Welcome Guest, Not a member yet? Register   Sign In
Load view from another view?
#1

[eluser]Buso[/eluser]
How can I do that? Should I use include "aview.php"?
#2

[eluser]rogierb[/eluser]
In MVC you do not load a view from a view. You load the view in you controller.
If you want to show multiple views, just load them in your controller and parse them as usual.
#3

[eluser]Developer13[/eluser]
Buso - just use $this->load->view('view_name') from inside of your view.

And RTFUG.
#4

[eluser]oliur[/eluser]
1) You can create a template view. I normally call it 'main' i.e. in my view folder I have a template called main.php that has the page skeleton.
2) In the template file you can have something like this
Code:
$this->load->view('content_view');
3) From your controller you set content_view to whatever view (newsDetails in this example)you want to load from your template view. You then load your template view and pass that view name as parameter.

For example,
Code:
$data['content_view'] = 'newsDetails';
$this->load->view('main',$data);
#5

[eluser]wowdezign[/eluser]
I use a system like the one oliur just described. For me it makes my template modular, in a sense, so I can change out parts or pass sections in from the controller.
#6

[eluser]Buso[/eluser]
[quote author="wowdezign" date="1257805485"]I use a system like the one oliur just described. For me it makes my template modular, in a sense, so I can change out parts or pass sections in from the controller.[/quote]

yea me too

i love having a dynamic skeleton



well, i have another question:

how to load a view from a helper??
Im writing a html_helper called login(), which should check if the user is logged in to show the welcome view, or else show the login form.
But i get this error:
Fatal error: Using $this when not in object context
#7

[eluser]oliur[/eluser]
I guess it's becuase helpers are just a bunch of functions and not part of 00 sturcture or any class. Therefore, refereing to $this (which means this object) will trigger an error.
#8

[eluser]CI_avatar[/eluser]
you can make main view and a lot of function for your modules within that main view. just call certain function if you need it.
#9

[eluser]Buso[/eluser]
[quote author="oliur" date="1258098336"]I guess it's becuase helpers are just a bunch of functions and not part of 00 sturcture or any class. Therefore, refereing to $this (which means this object) will trigger an error.[/quote]
yea, the solution was creating an CI instance.. i wish someone told me that, coulda saved a lot of time -.-




Theme © iAndrew 2016 - Forum software by © MyBB