Welcome Guest, Not a member yet? Register   Sign In
question on MVC
#1

[eluser]Unknown[/eluser]
Hello


i'm quite new to CI, but i've a question regarding my first site i'm writing.


Basically, I've got a USER and a TEMPLATE class

so i wrote a Model 'User' and a model 'Template'.
In my User model, i have a field 'template' which in the db is stored as the template_id.
Now, what i want, is for the 'template' field to not contain the template_id but contain an instance of the template class with all my fields.

Now, what i did, is in my 'User' model, in the 'load_entry' method,
Code:
$template_id = $row->template;
            $this->load->model('Model_template', 'template' . $template_id);
            $this->('template' . $template_id)->load_entry($template_id);
            $this->template = $this->('template' . $template_id)->getInstance();

My little issue, concerns the CodeIgniter way of loading a model ...
personnaly i would have done so that the load->model method returns an instance of the model, ...
So what i did was add a getInstance() method in all my models (i should modify the model class ^^ so they inherit it ^^)

it basically does a return $this;




I haven't found much info about my type of issue, maybe i've done what everyone else is doing ? or is there a better CI way to do this ?

Thank you.


Messages In This Thread
question on MVC - by El Forum - 12-17-2007, 04:22 AM
question on MVC - by El Forum - 12-17-2007, 02:00 PM
question on MVC - by El Forum - 12-18-2007, 01:45 AM
question on MVC - by El Forum - 12-18-2007, 09:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB