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

(04-06-2015, 04:55 AM)casa Wrote: No need "_model" in the name.

you need "_model" or something else to prevent class name collision
you have a controller named Users and you make a model named Users what do you think will happen?

(This post was last modified: 04-07-2015, 04:44 AM by casa.)

You can have your proposals : when you call a model, the loader call in directory models (see system/core/Loader.php), when you call a library, directory libraries in directory system or application directory is concerned, etc. There won't have a conflict.
If you try to call in controller named Users the model Users by this->load->model(..), you will be an error.
You can add a letter like c between your controller name or other if you want (that like you say).
About the questions of complete an array of different object or pass parameter, there had an error with your method because it is unsuitable.

(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();


    return $retour;

and I can use it like this:
PHP Code:

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 ?


Theme © iAndrew 2016 - Forum software by © MyBB