Welcome Guest, Not a member yet? Register   Sign In
An easy way to execute a method from the view ..
#10

[eluser]wiredesignz[/eluser]
I'm not going to try to teach you MVC here, but there are far better ways to achieve templating.

Call the model from the view
Code:
//view
<ul>
&lt;?php
    if ($items = $this->menu_model->get_data(array('site','nav'))):
        foreach ($items as $k => $item):
            $active = ($item->uri == $page) ? array('class' => 'current') : NULL;
            echo '<li>', anchor($item->uri, $item->title, $active), '</li>';
        endforeach;
    endif;
?&gt;
</ul>

Pass the data into the view
Code:
//controller
$data['items'] = $this->menu_model->get_data(array('site','nav'));

//view
<ul>
&lt;?php
    if ($items):
        foreach ($items as $k => $item):
            $active = ($item->uri == $page) ? array('class' => 'current') : NULL;
            echo '<li>', anchor($item->uri, $item->title, $active), '</li>';
        endforeach;
    endif;
?&gt;
</ul>

Pass a reference to the model into the view
Code:
//controller
$data['menu'] =& $this->menu_model;

//view
<ul>
&lt;?php
    if ($items = $menu->get_data(array('site','nav'))):
        foreach ($items as $k => $item):
            $active = ($item->uri == $page) ? array('class' => 'current') : NULL;
            echo '<li>', anchor($item->uri, $item->title, $active), '</li>';
        endforeach;
    endif;
?&gt;
</ul>


Messages In This Thread
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 05:33 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 05:45 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 05:55 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:00 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:05 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:16 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:26 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:40 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:50 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 06:58 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 07:19 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 07:24 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 07:35 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 07:39 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 07:44 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 07:54 AM
An easy way to execute a method from the view .. - by El Forum - 07-31-2008, 08:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB