helper - controller - function dilemma |
[eluser]webscriptz.be[/eluser]
Hi, I'm making myself a webhosting system and I'm think I'm ding overkill in lines of codes actually. I have some functions that every single function needs having but having 10 functions in your controller for 10 different think gets the document kind of crowded so can i best do this in a helper or something, note that i need the the corresponding models to because otherwise it won't work: the concerning bits of code, there all placed in the model settings at the moment. Code: $data['links'] = $this->Settings->getLinks(); So please can anybody help me. -Tim
[eluser]TheFuzzy0ne[/eluser]
Your function is out of context of the CI Super Object. You need to reference it with get_instance(): Code: $CI =& get_instance();
[eluser]webscriptz.be[/eluser]
[quote author="TheFuzzy0ne" date="1238510689"]Your function is out of context of the CI Super Object. You need to reference it with get_instance(): Code: $CI =& get_instance(); if it's a helper or library, the code i posted is situated in the controllers. sorry if i wasn't clear on that.
[eluser]zutis[/eluser]
Third reply down here : http://ellislab.com/forums/viewthread/108293/ ... this is a good way to give all your models, controllers and libs access to site wide vars etc.
[eluser]xwero[/eluser]
If i understand it correctly links, config and lang come out of the settings model and you needs those variables in all your controller functions? If this is right you can use class variables and use the constructor to set them Code: class Some_controller extends Controller Code: class Some_controller extends Controller
[eluser]webscriptz.be[/eluser]
[quote author="xwero" date="1238511892"]If i understand it correctly links, config and lang come out of the settings model and you needs those variables in all your controller functions? If this is right you can use class variables and use the constructor to set them Code: class Some_controller extends Controller Code: class Some_controller extends Controller it's the second patch of code that i have in every function of my controllers, so i would like to make in into a main method or something alike so that i don't need to declare them nor that i need to put it in each individual function.
[eluser]pixelazion[/eluser]
I don't know if this will help. ^_^ but you can try this for a start Code: $this->load->model('settings'); <-- small s on settings
[eluser]webscriptz.be[/eluser]
I going to explain myself a little more, it think it's my fault you guys don't understand it as i have got it in mind, for which i'm sorry. I have to code (see first post), this code is located in the controllers and has to be declared in every function of each controller with exception of the constructor. My problem now is that is not really a nice view nor is it a good practice. now i have done some trail and error and i came up with the following construction which is already sowhat better but still there's room for improvement. Code: <?php the only thing which still buggers me slightly is: Code: $this->load->vars($data);
[eluser]zutis[/eluser]
I think I understand what you mean. And my first response still stands. Try it. Your code would look something like this: first create application/libraries/MY_Controller.php And put this in: Code: <? then your code will look like this: Code: <?php Everything else will work the same.
[eluser]webscriptz.be[/eluser]
Thanks! it works the only thing that apparently i had to add to the individual controllers was $this->load_common_variables(); in the constructor |
Welcome Guest, Not a member yet? Register Sign In |