Welcome Guest, Not a member yet? Register   Sign In
Calling library methods from a view
#4

[eluser]nhm tanveer hossain khan (hasan)[/eluser]
gotcha Big Grin
i don't think that is harming core philosophy so much since you are not writing the whole logic which was written under "get_categories" method. though you could load them under controller and send them over a variable. (which MVC suggests)
i am pretending this bunch of view code is used for creating modular component. which is not actually controller action dependent.

i have followed the following method in my code -
Code:
<?= render_categories() ?>

on helper you should have the following code -
Code:
function render_categories() {
  $this->load->view("common/categories", array(
    "categories" => $this->sidebar->get_categories()
  ));
}

On common/categories.php
Code:
<ul>
&lt;? foreach ($categories as $cat) : ?&gt;
<li><$=cat->title; ?&gt;</li>
&lt;? endforeach; ?&gt;
</ul>

it gives me chance to separate my logic and view with in the component scope. so later if i decide to change the logic in the category retrieval process or use separate library i don't need to touch the view.

best wishes Smile


Messages In This Thread
Calling library methods from a view - by El Forum - 12-18-2008, 10:08 AM
Calling library methods from a view - by El Forum - 12-18-2008, 10:36 AM
Calling library methods from a view - by El Forum - 12-18-2008, 10:46 AM
Calling library methods from a view - by El Forum - 12-18-2008, 11:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB