Welcome Guest, Not a member yet? Register   Sign In
How I use masterpage and dont duplicate code
#1

[eluser]Unknown[/eluser]
Hi i'm using this library:

Code:
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Layout
{

    var $obj;
    var $layout;

    function Layout($layout = "master_page")
    {
        $this->obj =& get_instance();
        $this->layout = $layout;
    }

    function setLayout($layout)
    {
      $this->layout = $layout;
    }

    function view($view, $data=null, $return=false)
    {
        $loadedData = array();
        $loadedData['content'] = $this->obj->load->view($view,$data,true);

        if($return)
        {
            $output = $this->obj->load->view($this->layout, $loadedData, true);
            return $output;
        }
        else
        {
            $this->obj->load->view($this->layout, $loadedData, false);
        }
    }
}

And my HTML is this:

Code:
<!doctype html>
&lt;html lang="pt-br"&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;Don't listen to Le Corbusier | acazsouza.com.br&lt;/title&gt;

        &lt;link rel="stylesheet" type="text/css" href="/resources/css/reset.css" media="screen, projection"&gt;
        &lt;link rel="stylesheet" type="text/css" href="/resources/css/style.css" media="screen, projection"&gt;
        &lt;!--[if lt IE 9]>
            [removed]
            // Via Remy Sharp (@rem): http://remysharp.com/2009/01/07/html5-enabling-script/
            /*@cc_on'abbr article aside audio canvas code details figcaption figure footer header hgroup mark menu meter nav output progress section summary time video'.replace(/\w+/g,function(n){document.createElement(n)})@*/
            [removed]
        <![endif]--&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;header&gt;
            <h1><a href="/">acazsouza.com.br</a></h1>
        &lt;/header&gt;
        <div class="c">
            <article>
                &lt;?php echo $content?&gt;
            </article>
            <aside>
                <section class="autor">
                    <h1>Autor</h1>
                    <ul>
                        <li><a href="#" title="E-mail de contato" class="gmail">[email protected]</a></li>
                        <li><a href="http://www.twitter.com/acazsouza" title="Twitter" class="twitter" target="_blank">@acazsouza</a></li>
                        <li><a href="#" title="Live Messenger" class="messenger">[email protected]</a></li>
                    </ul>
                </section>
                <section class="categorias">
                    <h1>Categorias</h1>
                    <ul>
                        <li><a href="/artigos/">adequatelygood</a></li>
                        <li><a href="/artigos/">css</a></li>
                        <li><a href="/artigos/">debugging</a></li>
                        <li><a href="/artigos/">html5</a></li>
                        <li><a href="/artigos/">javascript</a></li>
                        <li><a href="/artigos/">jquery</a></li>
                        <li><a href="/artigos/">module pattern</a></li>
                        <li><a href="/artigos/">performance</a></li>
                        <li><a href="/artigos/">python</a></li>
                        <li><a href="/artigos/">slide</a></li>
                    </ul>
                </section>
            </aside>
        </div>
    &lt;/body&gt;
&lt;/html&gt;

So, in the aside tag i need to this is dinamycall, but i don't want to put the code to do this in all controller, i want to put the code to load this part in one place only, how i do this?
#2

[eluser]umefarooq[/eluser]
Hi you can extend CI controller with MY_Controller in application library and put your common code MY_Controller and extend you controller with MY_controller and you can access that code in each and every controller you want. for more information read this article

http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
#3

[eluser]Unknown[/eluser]
And how your solution works fast? Just me on this occasion doubt ...
_________________________________________
site:
<a href="http://pharmacyaffiliate.biz/" title="pharmacy affiliate">pharmacy affiliate</a>
#4

[eluser]Unknown[/eluser]
thank you people, i use a base controller.




Theme © iAndrew 2016 - Forum software by © MyBB