kazemimorteza
جمعه 23 آبان 1393, 12:59 عصر
درود.
میخوام با ajaxLink یه مقداری را به کنترلر سایت siteController بفرستم ولی .....
اکشنی که صفحه showFriendForm را فراخوانی میکند.(تمامی اکشن ها در siteController قرار دارند.)
public function actionShowFriend() {
try {
if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']))
$this->render("showFriendForm", array('id' => Yii::app()->input->stripClean($_GET['id'])));
else {
throw new CHttpException(404, "error.-Bad request");
}
} catch (Exception $e) {
$this->render("error", array('message' => $e->getMessage()));
}
}
صفحه showFriendForm :
echo CHtml::ajaxLink(
"Link Text",
array('site/ajaxRequest'),
array( // ajaxOptions
'type' => 'post',
'dataType'=>'text',
'beforeSend' => "function( request )
{
alert(request);
// Set up any pre-sending stuff like initializing progress indicators
}", 'complete' => "function( data )
{
// handle return data
alert( data );
}",
'data' => array( 'val1' => '1', 'val2' => '2' )
),
array( //htmlOptions
'class' => 'btn'
)
);
اکشن ajaxRequest
public function actionAjaxRequest() {
if (isset($_POST['val1'])) {
$val1 = $_POST['val1'];
$val2 = $_POST['val2'];
}
//
// Perform processing
//
//
// echo the AJAX response
//
echo "some sort of response";
return;
//Yii::app()->end();
}
سطح دسترسی ها:
///---------------------------
public function filters() {
return array(
'accessControl', // perform access control for CRUD operations
// we only allow deletion via POST request
);
}
public function accessRules() {
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions' => array('index', 'ajaxRequest', 'contact', 'error', 'createPost', 'showFriend'),
'users' => array('@'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions' => array('login', 'logout', 'signUp'),
'users' => array('*'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
میخوام با ajaxLink یه مقداری را به کنترلر سایت siteController بفرستم ولی .....
اکشنی که صفحه showFriendForm را فراخوانی میکند.(تمامی اکشن ها در siteController قرار دارند.)
public function actionShowFriend() {
try {
if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id']))
$this->render("showFriendForm", array('id' => Yii::app()->input->stripClean($_GET['id'])));
else {
throw new CHttpException(404, "error.-Bad request");
}
} catch (Exception $e) {
$this->render("error", array('message' => $e->getMessage()));
}
}
صفحه showFriendForm :
echo CHtml::ajaxLink(
"Link Text",
array('site/ajaxRequest'),
array( // ajaxOptions
'type' => 'post',
'dataType'=>'text',
'beforeSend' => "function( request )
{
alert(request);
// Set up any pre-sending stuff like initializing progress indicators
}", 'complete' => "function( data )
{
// handle return data
alert( data );
}",
'data' => array( 'val1' => '1', 'val2' => '2' )
),
array( //htmlOptions
'class' => 'btn'
)
);
اکشن ajaxRequest
public function actionAjaxRequest() {
if (isset($_POST['val1'])) {
$val1 = $_POST['val1'];
$val2 = $_POST['val2'];
}
//
// Perform processing
//
//
// echo the AJAX response
//
echo "some sort of response";
return;
//Yii::app()->end();
}
سطح دسترسی ها:
///---------------------------
public function filters() {
return array(
'accessControl', // perform access control for CRUD operations
// we only allow deletion via POST request
);
}
public function accessRules() {
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions' => array('index', 'ajaxRequest', 'contact', 'error', 'createPost', 'showFriend'),
'users' => array('@'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions' => array('login', 'logout', 'signUp'),
'users' => array('*'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}