load model from own class |
[eluser]wiZe[/eluser]
hi there, i got a problem with loading a model from one of my classes. i created a class: €dit: ok it is definetly a matter of the class not being able to run the loader class! but it must be really simple, its basicly that: - create own class in app/libraries - load an instance of this class in one of my controllers - load a view/model/whatever from within my own class Any recommendations? Code: <?php and instantiated it in my controller: Code: <?php now i recieve this error message: Code: A PHP Error was encountered how do i load a model from my own class? hope somebody has an answer for me, thanks in advance!
[eluser]GSV Sleeper Service[/eluser]
looks like the model is being loaded ok, but there's a problem in your model. please post the model code.
[eluser]wiZe[/eluser]
ok this is my loaded model: Code: <?php but i think its somethin wrong with the references between the classes. the error "...Call to a member function select() on a non-object..." says that my Sandwhich instance is not an object. or am i wrong?
[eluser]GSV Sleeper Service[/eluser]
the database class is not being loaded in your model. from the manual Quote:When a model is loaded it does NOT connect automatically to your database. for more details see this page - http://ellislab.com/codeigniter/user-gui....html#conn
[eluser]wiZe[/eluser]
sry sleeper i forgot to mention that the db class is being auto loaded. how do i have to extend my own class if i load it in a controller, to get the functionality from controller and model class. i think there is the mistake. thanks for your answer though!!
[eluser]wiZe[/eluser]
ok it is definetly a matter of the class not being able to run the loader class! but it must be really simple, its basicly that: - create own class in app/libraries - load an instance of this class in one of my controllers - load a view/model/whatever from within my own class Any recommendations?
[eluser]Pascal Kriete[/eluser]
Your library shouldn't extend the controller. Instead, it should be a stand-alone class, that operates on a reference of the current controller. The user guide is a good reference on how this works. Essentially, you want something like this: Code: class Sandwhich {
[eluser]wiZe[/eluser]
yea inparo that was the thing i was missing! thanks a lot for your help!
[eluser]meigwilym[/eluser]
BTW, your model get_data method should be Code: function get_data($id)
[eluser]wiZe[/eluser]
i assign it in the controller like: Code: $data = $this->db->random_model->get_data($id); |
Welcome Guest, Not a member yet? Register Sign In |