Welcome Guest, Not a member yet? Register   Sign In
Very basic MVC question on including other files
#1

[eluser]DB2k[/eluser]
Hi

In PHP if I wanted to include say a menu system I would use the PHP Include command so that all pages can reference the same content in one place.

Now with CI, I can do this slightly differently but I am not quite sure which way is best to adhere to the MVC architecture?

The menu will just be HTML so is it a view? If so do I just have a file menu.php in my views folder, and then load it using:

class Site extends CI_Controller {

function index()
{
$this->load->view('menu');
}
}

Firstly - is that the right thing to do and secondly, will that actually produce the content on screen, or do I have to then call it somehow?

Sorry - I'm really new to this method of coding and apologise for asking such a noddy question that is almost certianly answered somewhere else. I just can't find it.

best regards,
Dave
#2

[eluser]jgetner[/eluser]
for your first question yes thats perfect.
for your second question in your config folder there is a script called routes go into that file and set your defualt controller to the controller you want called first.
#3

[eluser]DB2k[/eluser]
Thanks jgetner - I'll give it a try!
#4

[eluser]DB2k[/eluser]
Ok I think I get it. My controller calls all the views, instead of my controller calling 1 view which calls a sub-view.

Its working and seems good - thanks again for the help




Theme © iAndrew 2016 - Forum software by © MyBB