templates - Is this a good way to use controllers and views in CodeIgniter? -


What's the best way to use controllers / ideas?

Know about creating my pages?

  function index () {$ this-> Load-> Library ('carbineer'); $ This- & gt; Load-> View ('include / head'); $ This- & gt; Load-> Scene ('include / house'); $ This- & gt; Load-> View ('top'); $ This- & gt; Load-> Scene ('special'); $ This- & gt; Load-> View ('eventslist'); $ This- & gt; Load-> Scene ('footer'); } Create the function () {$ this-> Load-> See ('include / head'); $ This- & gt; Load-> View ('top'); $ This- & gt; Load-> View ('Page'); $ This- & gt; Load-> View ('dynamicstuff'); $ This- & gt; Load-> Scene ('footer'); }  

I'm semi-templing like this, and it works fine to get the outline of the site, but is this the best way to make the app? I'm working in Codeigner for about a week, and I'm new to PHP.

is a download that makes it all very easy. Once you learn how to implement it, coding becomes very easy, it allows you to place different templates (layouts) to each page or controller.

Using the above-mentioned system, you can do the following:

  & lt;? PHP function index () {$ data ['some_variable'] = 'some data'; $ This- & gt; Template-> Write_view ('content', 'page / house', $ data); $ This- & gt; Templates & gt; to present (); }? & Gt;  

Change the template you want to use anywhere:

  & lt ;? Php $ this- & gt; Template-> Set_timet ('login'); ? & Gt;  

All of these templates have names that are kept in the configuration file. You can have as many templates as you want.

The template file will look something like this:

  & lt; Html & gt; .... e.t.c. All other HTML elements & lt; Body & gt; Header html goes here & lt ;? = $ Content? & Gt; Footer html goes here & lt; / Body & gt; & Lt; / Html & gt;  

You can also set up to be able to write your content. I usually do not do this because there are so many ideas included, but if you need complete control like this then you can still do this:

  & lt; Php function index () {$ data ['header'] = 'header info'; $ Data ['content'] = 'content information'; $ Data ['sidebar'] = 'sidebar information'; $ Data ['footer'] = 'footer information'; $ This- & gt; Template-> Write_view ('content', 'page / house', $ data); $ This- & gt; Template-> Write_view ('header', 'module / header'); $ This- & gt; Template-> Write_view ('sidebar', 'module / sidebar'); $ This- & gt; Template-> Write_view ('footer', 'module / footer'); $ This- & gt; Templates & gt; to present (); }? & Gt;  

HTML template code:

  & lt; Html & gt; .... e.t.c. All other HTML elements & lt; Body & gt; & Lt; Div id = "header" & gt; & Lt ;? = $ Header & gt; & Lt; / Div & gt; & Lt; Div id = "content" & gt; & Lt; Div id = "left" & gt; & Lt ;? = $ Content & gt; & Lt; / Div & gt; & Lt; Div id = "sidebar" & gt; & Lt ;? = $ Sidebar & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "footer" & gt; & Lt ;? = $ Footer text & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

In this way you only need to worry about including a file in all its controller functions. If you are not using PHP 5 (you should switch) then & lt ;? = $ Content? & Gt; Instead of using you can & lt ;? Php echo $ content; ? & Gt; .


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -