Welcome Guest, Not a member yet? Register   Sign In
Am I respecting MVC Pattern
#1

[eluser]Unknown[/eluser]
Hello!

I'm using CI Framework in order to build a web application as follows.

My default controller is something like this,

Code:
class Start extends CI_Controller {
public function index()
{  
  $view_data = array(
   'foo' => 'bar',
   'top_bar_view' => 'top_bar_view',
   'top_bar_params' => array(
    'param1' => 'val1',
    'param2' => 'val2',
    'param3' => 'val3',
    'param4' => 'val4',
    'param5' =>  'val5'
    )
  );
  
  $this->load->view('main_view', $view_data);
}

}

which loads the main_view, that is kind of master page, where I load the view file that I'm passing with $view_data.

Then, on this top_bar_view I would like to call a controller in order to build a menu depending on some data. For now, I accomplish this using an ajax call inside this partial view.

Code:
script type="text/javascript">
$(function() {
  $.post('index.php/menu/givemenu', {}, function(data) { $('#topMenuBar').append(data); });
});
[removed]
<img alt="alt_data" src="assets/img/&lt;?php echo $image_name; ?&gt;" />
<div>
<img alt="&lt;?php echo $descricao_editora; ?&gt;" src="assets/img/&lt;?php echo $image_name; ?&gt;" />
</div>
<div class="divSpacer20pxRight">

</div>
<div class="divTituloProduto">
&lt;?php echo $titulo_produto; ?&gt;
</div>
<div class="clear">

</div>

<div id="topMenuBar" class="divTopMenuBar">

</div>

<div class="clear">

</div>


Is this correct and respects the MVC Framework?

How would you do it ?

Thanks in advance,
#2

[eluser]CroNiX[/eluser]
In the controller, I would load/assemble the menu view and pass it to the view instead of using ajax.


Code:
$view_data['menu'] = $this->load->view('menu', $menu_data, TRUE);




Theme © iAndrew 2016 - Forum software by © MyBB