Hi, this is the wiki page1 and page2 that i followed.
If i don’t declare those variables as public in my reusable action, yii send me a message of undefined variables.
If they are declared, the variables into the action are uninitialized. Why?
Widget Code
public static function actions(){
return array(
// naming the action and pointing to the location
// where the external action class is
//'NewRecord'=>'application.components.actions.NewRecord',
'NewRecord'=>'application.components.actions.NewRecord',
);
}
Controller Code
public function actions(){
return array(
// naming the action and pointing to the location
// where the external action class is
//'send.'=>'application.components.actions'
//'test.'=>'application.widgets.site.immobileMoreInfo',
'test.'=>array(
'class'=>'application.widgets.site.immobileMoreInfo',
'NewRecord'=>array(
'model'=>'ContattiInfoImmobile',
'property1'=>'value1',
'model_name'=>'ModelClass',
),
),
);
}
Action Code
class NewRecord extends CAction {
public $model;
public $property1;
public $model_name;
public static function run() {
//$controller = $this->getController();
// get the Model Name
//$model_class = ucfirst($controller->getId());
// create the Model
$model_class = new $this->model;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST[$model_class])) {
$model->attributes = $_POST[$model_class];
if ($model->save())
//$controller->redirect(array('view', 'id' => $model->id));
echo 'OK';
}
/*
$controller->render('create', array(
'model' => $model,
));
*/
echo 'KO';
}