• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create dynamic menu

#1
[eluser]Mainboard[/eluser]
well, i create a dynamic menu with a db, and this is my code:
My model
Code:
<?
class menu_enc_model extends CI_Model {
function call_menu_enc() {
     $q = $this->db->select('*')->from('tb_menu_enc')->where('activo', 1);
     $ret['rows_enc'] = $q->get()->result();
     return $ret;
     }
}
?>

My Control (call site.php)
Code:
function members_area() {
     $this->load->model('menu_enc_model');
     $results_enc = $this->menu_enc_model->call_menu_enc();
     $data['menu_enc'] = $results_enc['rows_enc'];
     $this->load->view('index', $data);
        }

And View
Code:
<?php foreach($menu_enc as $menue): ?>
&lt;? echo '<a class="current">link.' target='.$menue->destino.'>'.$menue->nombre_enc.'</a>';?&gt;
&lt;?php endforeach; ?&gt;
i dont' know why doesn't appear the href but the code is href='.$menue->link.' target=...

everything works perfect except when I press some button of the menu, automatically returns to my control (site.php) waiting some function, so i want to return to some view, not to my control, so how i can to create a function to return each view in each button?

#2
[eluser]ranjudsokomora[/eluser]
Hello lvasquez,
I was going to say that your anchor tag is constructed wrong, however when I tried to fix your example, and preview before I submitted, it screwed it all up... so try emailing me, ranjudso.komora@gmail.com, and I would be willing to help you through it.

#3
[eluser]Mainboard[/eluser]
thanks, i send you a email, thanks for your anwser and help

#4
[eluser]Jaketoolson[/eluser]
Codeigniters forum keeps messing me up to when I submit a fix... not sure whats up lol.

#5
[eluser]Mainboard[/eluser]
well, i found this link http://ellislab.com/forums/viewthread/154719/#748768
and this is my solution Big Grin, i will try to implement this class and this functions, i think that is the better way to use a dynamic menu with database without having to Redirect again each view in each button in my controll, thanks for the support.

#6
[eluser]John_Betong_002[/eluser]
Try this:

Code:
My Control (call site.php)

function members_area()
{
$this->load->model('menu_enc_model');

$results_enc = $this->menu_enc_model->call_menu_enc();

$data['menu_enc'] = $results_enc; // $results_enc['rows_enc'];

if(TRUE) // Debug stuff
{
   echo '<pre>';
     echo '<h2>$results_enc["rows_enc"]</h2>';
       print_r($results_enc['rows_enc']);

     echo '<h2>$results_enc</h2>';
       print_r($results_enc['rows_enc']);

     echo '<h2>$data["menu_enc"]</h2>';
       print_r($results_enc['rows_enc']);

   echo '</pre>';
   die;
}    

$this->load->view('index', $data);

}
&nbsp;
&nbsp;

#7
[eluser]Mainboard[/eluser]
i fix the problem, i create another function and works perfect Wink
Code:
function call_main($sort_colums = 'link') {
    $this->load->model('menu_enc_model');
    $results_enc = $this->menu_enc_model->call_menu_enc();
    $data['menu_enc'] = $results_enc['rows_enc'];
    $this->load->view($sort_colums, $data);
    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.