Welcome Guest, Not a member yet? Register   Sign In
How to pass variable from model to controller and define in the view?
#1

[eluser]Juan Velandia[/eluser]
Hello Every one

I've dealing with this for a while, I hope you can put me on the right track, I need to show some data from DB on different menus according with the "placeholder" field in the "cms_section" table, here is the code so far:

model:
Code:
function show_item_placeholder($placeholder)
    {
        $this->db->select('name');
        $this->db->select('url_section');
        $this->db->where('placeholder',$placeholder);
        $query = $this->db->get('cms_section');
        return $query->result();
     }


Controller:
Code:
function index($placeholder)
    {
        $data['section_content'] = $this->section_content_model->get_section_content();
        $data['item_placeholder'] = $this->item_placeholder_model->show_item_placeholder($placeholder);
        $partials = array('top_logo'=>'view_top_logo','top_menu'=>'view_top_menu', 'left_menu'=>'view_left_menu');
        $this->template->load('master_home', $partials, $data);
       }

and the view: "top_menu.php"

Code:
$placeholder = '1';
foreach ($item_placeholder as $row1):
echo anchor('home/section/'.$row1->url_section, $row1->name, array('class'=>'menuh1'))
endforeach;

Any ideas would be highly appreciated, thanks!
#2

[eluser]Juan Velandia[/eluser]
well I`ve decided to go like this:

controller:
Code:
function placeholder($placeholder){
    $placeholder = array();
    $placeholder['1'] = $this->item_placeholder_model->get_item_placeholder('1');
        $placeholder['2'] = $this->item_placeholder_model->get_item_placeholder('2');
        $placeholder['3'] = $this->item_placeholder_model->get_item_placeholder('3');
        return $placeholder;
    }

view:
Code:
<?echo anchor('home/', 'Inicio', array('class'=>'menuh1')) ?>
<?php foreach ($placeholder['1'] as $row1): ?>
<?echo anchor('home/section/'.$row1->url_section, $row1->name, array('class'=>'menuh1')) ?>
<?php endforeach; ?>

  <?echo anchor('contact/', 'Contáctenos', array('class'=>'menuh1')) ?>




Theme © iAndrew 2016 - Forum software by © MyBB