I am creating a website using codeigniter and I want to include the menu (options) file so that I could save all my time from independently pasting the code on every view I need.
Or even if there is a common file for custom functions where I could place the code and call the function.
ANy help. My menu option is as follows.
<h5>Admin Options</h5>
<ul>
<li><a href="">Portfolio</a>
<ul>
<li> <a href="category/addCategory">Add a Category</a></li>
<li> <a href="category/updateCategory">Edit/Delete Category</a></li>
<li> <a href="link/addLink">Add a Link</a></li>
<li> <a href="link/updateLink">Edit/Delete Link</a></li>
</ul>
</li>
<li>First</li>
<li>First</li>
<li>First</li>
<li>First</li>
</ul>
As you can see by the answers there are a number of ways of doing this but honestly I don’t see the point in a templating library as it’s relatively easy to do on your own. I use templates for my entire site since it means I don’t have to keep rewriting code. Below is how I do it.
Template.php This file loads the other parts of the template, it loads the header dependent on whether the user is logged in so I can add the user menus easily.
Each of those pages is a static html file or as in the case of the main content and sidebar_content they’re variables. So then from a controller I load my views like this (this is a basic page)
So what’s happening above is the first line is the actual view getting loaded to main content this is a php page with nothing but the middle content of the site in it. Title fills in the title tags in the header. sidebar content loads the appropriate sidebar.php page (in this case it’s an empty file). Additional head info is so I can load libraries or css pages specific to a single view. The final line brings it all together.
Edit – I added two lines for adding variable data. So you would do a call to your model like normal and return the data, but return it to an array inside the $data array. Then in your view you would access it like this (variables are obviously for example, you’d use whatever variables your model returns:
For the record normal PHP include statements work just fine in CI, it just makes a lot less sense than creating a template.