Welcome Guest, Not a member yet? Register   Sign In
Help in include files
#11

[eluser]Rey Philip Regis[/eluser]
Now you realize how easy to make webpages using CI. Its just creativity and understanding the thoery on how to do a certain thing.

Its been a pleasure helping you....

Good day and happy code igniting haha..
#12

[eluser]khuram[/eluser]
There is only one thing that i havent been able to understand.
Lets say on my template page, I have to load a list of categories in a table.

Ideally there should be a controller for template which can be called from anyother control to initialize the stuff.
I havent been able to find this out anywhere.
Right now, I am having to do this in every new page that I make.

Code:
$this->load->model('template/template','TemplateFunctions', TRUE);
$data['cats'] = $this->TemplateFunctions->get_categories();
$this->load->view('template/template', $data);
Ideally this is not the best situation. Please advice me into how to make a master control which I include in every control and it knows how to react.
#13

[eluser]Rey Philip Regis[/eluser]
Code:
$this->load->model('template/template','TemplateFunctions', TRUE);
$data['cats'] = $this->TemplateFunctions->get_categories();
$this->load->view('template/template', $data);

Is the code above dynamic? I mean does $this->TemplateFunctions->get_categories(); change in every page? If its the same in every page, I have a suggestion but havent tried it yet. Try to use hooks put your code i mean the above code to a method then register it in a hook its configurations is inside the config folder, then after executing the above code in your newly created method put it in a session so it will be available in all of your page.

Personally, just like what I said a while ago, I haven't tried that technique yet. Just try that, if you like....

Good day.
#14

[eluser]khuram[/eluser]
Hi Rey

Yes this list is populated from database but it is a list which wont change on pages except the category detail pages themselves where it includes the subcategories for that selected category. This templating system is not becoming any easier. I must be dumb. Sad
#15

[eluser]khuram[/eluser]
I am having a hard enough time learning the basics of CI, if I go after hooks with my half cooked knowledge, I will probably get lost pretty soon.
#16

[eluser]Rey Philip Regis[/eluser]
Code:
$this->load->model('template/template','TemplateFunctions', TRUE);
$data['cats'] = $this->TemplateFunctions->get_categories();
$this->load->view('template/template', $data);

Well, how about making a library or a helper function then put above code inside that function. Then configure that helper or library that you've made to be autoloaded in th autoload.php in the config folder. Then just call that library or helper in every constructor of your controller. Just make sure the reciever of the result will be a global variable, so it can be accessed to every method by your controller.


Good day.
#17

[eluser]Colin Williams[/eluser]
The best way to do this and stick to the MVC principle is to use a base controller. Most of the time in application development, you don't need more than one controller. What you are typically doing is loading and nesting views into one main view. The Controller (singular) contains all the functions required by the app.

This breaks down a bit when you start organizing your app into multiple controllers, because you then must concoct a way to continue nesting these globally-important views without repeating code for every controller. Or, of course, you could have a single controller and just use routes to make your URIs appear to map to different controllers.

In CI, Controllers are sub-classes of a Controller class, which is just a CI library. This means you can extend it with your own classes. Typically it's best to put the extra classes in a MY_Controller.php library file, then have your controllers extend MY_Controller (or other classes that extend Controller). This location isn't necessary because CI instantiates YOUR controller class (as determined by the Router class), so the additional controller class or classes just need to be included somehow. Going with the previously explained way is favored just because it follows CI conventions already. If CI sees that there is a MY_Controller.php library, it's going to automatically load it. Might as well piggy-back that process.




Theme © iAndrew 2016 - Forum software by © MyBB