You must not hardcode url's. You must use createUrl() or createAbsoluteUrl() as @Grimv01k recommends you. When in view or in controller you can do this by
$this->createUrl( 'foo/bar',array('id'=>321) )
Other ways:
Yii::app()->controller->createUrl('/baz/foo/bar'); // will use current controller
or
Yii::app()->createUrl('/baz/foo/bar')
Edited
So if you want
to unset a session when a user clicks on a icon
you can do this in following way.
echo CHtml::ajaxLink(
'click me to destroy session, mua-ha-ha',
Yii::app()->createUrl( '/session/destroy' ),
array(
'type' => 'post',
'dataType' => 'json',
'data' => array(
'foo' => 'bar',
),
'beforeSend' => 'js:function(){
console.log( $(this) );
return false;
}',
'success' => 'js:function(data){
console.log(data);
}',
)
);
in SessionController:
public function actionDestroy () {
if ( isset( $_POST['foo'] ) ) {
Yii::app()->session->destroy();
if ( Yii::app()->request->isAjaxRequest ) {
$response = array(
'status' => !Yii::app()->session->sessionID
) ;
echo CJSON::encode( (object) $response );
Yii::app()->end();
}
}
}

被折叠的 条评论
为什么被折叠?



