Welcome Guest, Not a member yet? Register   Sign In
Passing controller object into view (Is this bad?)
#1

[eluser]blasto333[/eluser]
I have a view that is used by two controllers both which implement a common interface.



In the controllers here is how I load the view.

Customers controller (implements iPersonController)
Code:
function index()
{
    $data['controller_name']=strtolower(get_class());
    $data['controller']=$this;
    $data['manage_table']=get_people_manage_table($this->Customer->get_all(),$this);
    $this->load->view('people/manage',$data);
}


manage view snippet
Code:
<?php echo anchor("$controller_name/view/-1/width:".$controller->_get_form_width().'/height:'.$controller->_get_form_height(),"New");
?>


Is it a bad practice to send in a reference to a controller, when I have a legit reason to be doing so.
($controller->_get_form_width())
#2

[eluser]Bramme[/eluser]
Why not generate your anchor in your controller and pas that html to your view?

I'm not sure it's really "bad practice", I've just found that there's most of the times some way of working around it.
#3

[eluser]blasto333[/eluser]
My view is kind of complicated, it just seems to make more sense to only pass in a couple of things.


Here is a simplified version of my view.

Code:
<?php $this->load->view("partial/header"); ?>
<div id="title_bar">
    <div id="title" class="float_left">&lt;?php echo $this->lang->line('common_list_of').' '.$this->lang->line('module_customers'); ?&gt;</div>
    <div id="new_button" class="float_right">
        &lt;?php echo anchor("$controller_name/view/-1/width:".$controller->_get_form_width().'/height:'.$controller->_get_form_height(),
        "<div class='big_button'><span>".$this->lang->line($controller_name.'_new')."</span></div>",
        array('class'=>'thickbox none','title'=>$this->lang->line($controller_name.'_new')));
        ?&gt;
    </div>
</div>
<div id="feedback_bar"></div>
<div id="table_action_header">
    <ul>
        <li class="float_left"><span>&lt;?php echo anchor("$controller_name/delete",$this->lang->line("common_delete"),array('id'=>'delete')); ?&gt;</a></span></li>
        <li class="float_left"><span><a href="#" id="email">&lt;?php echo $this->lang->line("common_email");?&gt;</a></span></li>
        <li class="float_right">
        <img src='&lt;?php echo base_url()?&gt;images/spinner_small.gif' alt='spinner' id='spinner' />
        &lt;?php echo form_open("$controller_name/search",array('id'=>'search_form')); ?&gt;
        &lt;input type="text" name ='search' id='search'/&gt;
        &lt;/form&gt;
        </li>
    </ul>
</div>
<div id="table_holder">
&lt;?php echo $manage_table; ?&gt;
</div>
&lt;?php $this->load->view("partial/footer"); ?&gt;
#4

[eluser]Colin Williams[/eluser]
You aren't working under any laws, here, so I don't think on the surface anybody can really say it's right or it's wrong. In classic MVC, the View is constantly in contact with the Controller and sometimes the Model.

I, personally, would just pass the value of the form width along with the $data array. You should have a standard way of doing it. Either the Controller always passes data to the View or the View always actively requests the data it needs from the Controller.
#5

[eluser]blasto333[/eluser]
I think you are right in this case, two more parameters is not painful and goes along with following a standard.




Theme © iAndrew 2016 - Forum software by © MyBB