Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to pass parameters in the constructor instance of Phalcon\Mvc\Model

The class extends Phalcon\Mvc\Model, I want to pass two params in the construct method, But Phalcon\Mvc\Model construct is final. How can i do that?

Since it's final I can think only of writing a setter method an passing the parameters there.



6.9k
Accepted
answer
edited Mar '14

@Gregor Panek is right. But already we have existing assign (setter) method like below::

$modelInstance->assign(array(
    'key1' => 'value1',
    'key2' => 'value2',
    'year' => 2014,
    [...]
));


15.4k

Thanks a6oozar Again..It look like just this only way

Dear @gl-liao in fact we have two other ways too like below:

$robot = \Phalcon\Mvc\Model::cloneResultMap(new Robots(), array(
         'type' => 'mechanical',
         'name' => 'Astro Boy',
         'year' => 1952
));

// OR

$robot = \Phalcon\Mvc\Model::cloneResult(new Robots(), array(
         'type' => 'mechanical',
         'name' => 'Astro Boy',
         'year' => 1952
));

`

There is any effort to support parameters on Model instantiation in futher versions?

OOP defines that constructor method should require necessary data to properly instantiate a new object allowing it to get a valid object state.

yes, would be nice if phalcon would support constructor params in future, models are kinda limited by design now

++

I would sort of think the initialize() method would take paramaters which would be bound to the model instance?