Welcome Guest, Not a member yet? Register   Sign In
model's constructor with parameters
#13

(This post was last modified: 06-10-2015, 07:33 AM by vincent78.)

Hi everybody,

I'm facing the same pb: I wanted to add some parameters to the __construct() method of a model and I got the same error message.
After reading this topic, I now understand why, so I'm looking for a solution to suit my need and the only solution I found without hacking CI is to add a "create" method in every model which looks like:
PHP Code:
public static function create($id$title$body) {
    $retour = new Topic();

    $retour->set_id($id);
    $retour->set_title($title);
    $retour->set_body($body);

    return $retour;


and I can use it like this:
PHP Code:
Topic::create($id$title$body); 

it's suitable but maybe there is a better solution

Do you think it's a good way to do it ?
Is there a better solution ?

Thanks
Vincent
Reply


Messages In This Thread
model's constructor with parameters - by casa - 04-05-2015, 10:33 AM
RE: model's constructor with parameters - by casa - 04-05-2015, 09:01 PM
RE: model's constructor with parameters - by s4if - 04-06-2015, 12:18 AM
RE: model's constructor with parameters - by casa - 04-06-2015, 01:57 AM
RE: model's constructor with parameters - by casa - 04-06-2015, 02:23 AM
RE: model's constructor with parameters - by casa - 04-06-2015, 04:55 AM
RE: model's constructor with parameters - by casa - 04-07-2015, 04:26 AM
RE: model's constructor with parameters - by vincent78 - 06-10-2015, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB