Calling controller function within controller? |
[eluser]delay[/eluser]
I am new to codeignitor and MVC but so far I really like it. I currently am not sure the best way to structure or handle part of my code. In my "amazon" controller I have a function, like this which loads several functions from the model. Code: function get_keyword_search($searchterm) Now I want to call this and several other controller functions within another controller function. Code: function check_amazon () I am very new to MVC and I understand I shouldn't really use DB queries outside of the model class. I could make the whole check_amazon function part of the model but my understanding is you also shouldn't call controllers from the model. So my question is where is the best place to call a bunch of controller functions? Can you call a controller function within a controller? How do you call the controller within the controller? Thanks very much for any help.
[eluser]Muhammad Faisal Shabbir[/eluser]
In very simple if u want to use same controller function in any other function of the same controller you just $this operator with the function name . Or if u want to use same model function in same model differnt function just use $this with function name . If u want to use different controller functions or also different models in particular controller then for model you have to load all the models in that particular model or if u want to use different controller then inheritance will help u.
[eluser]gunter[/eluser]
you could write a "base controller" and extend your controller from that... search for base controller or write a library for that...
[eluser]Grahack[/eluser]
Note that you can prefix some functions with an '_' underscore. This prevents the function to be triggered by http://site.com/index.php/controller/function (see the private functions section in the docs).
[eluser]delay[/eluser]
Thanks for all the tips and fast response... just what I needed. |
Welcome Guest, Not a member yet? Register Sign In |