E
E
EVOSandru62015-01-21 09:54:44
Yii
EVOSandru6, 2015-01-21 09:54:44

How to create an object of a class whose name is known in yii in the Create external action?

Good afternoon,
I figured out the external Update action , there is a static call for example:

class ShowTreeAction extends CAction{
    public $pk = 'id';
    public $modelClass;
    function run(){
        if(empty($_GET[$this->pk]))
            throw new CHttpException(404);
        $this->controller->render('item',array('model'=>CActiveRecord::model($this->modelClass)->findByPk((int)$_GET[$this->pk])));
    }
}

That is, there is a :: construction, but what if the action is Create and I want to create a new object through new , for example In the controller I write:
function actions(){
        return array(
            'create'=>array(
                'class'=>'application.components.actions.CreateAction',
                'modelClass' => 'Product'
            )
        );
    }

Then how do I create an object in an outer activity?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmeroff, 2015-01-21
@EVOSandru6

Just create it like this:
$object = new $this->modelClass;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question