Welcome Guest, Not a member yet? Register   Sign In
How do u manage your views?
#1

[eluser]Christoph Rumpel[/eluser]
I am struggling these days with clearing my code and i am not sure how to manage my views.
In my case i am working with a template view containing a headerview a contenview and a footerview. So everytime i load i view i just write:

Code:
$data['title'] = 'ShowTopics';
    $data['view'] = 'forum/showTopics_v';
    $this->load->view('template',$data);
This is working without problems. My problem is that i have these lines in every second functioin, in every controller, when i want load or reload a page after a function. Maybe u got some ideas or experiences you´d like to share with the community that might help me.
thx and greets

Christoph
#2

[eluser]stuckinphp[/eluser]
For matters of readability I'd start with using http://php.net/compact

Code:
$title = 'ShowTopics';
$view = 'forum/showTopics_v';
$this->load->view('template',compact('view','title'));

You are pretty stuck in the way that, if you want a view to load, you'll need to load it.

If you can train yourself to use a naming convention like you have started to anyway ("_v") you could use a post controller hook (http://ellislab.com/codeigniter/user-gui...hooks.html) to find and load views automagically if they are available based on controller name. Although you'd need to do some ugly thing with public variables which likely defeats the point..
#3

[eluser]John_Betong_002[/eluser]
Try searching this forum for "MY_Controller".

This would allow you to include the common MY_Controller in all of your controllers.
 
 

Also take a look at the third parameter for $this->load->view('template',$data, TRUE);

 
#4

[eluser]mihaibaboi[/eluser]
You might want to take a look at "Template Library for CodeIgniter", by Colin Williams. You can find it here.

I've been using it for some time now, and I find it very clean.




Theme © iAndrew 2016 - Forum software by © MyBB