• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
doubt with controllers

Hi guys!

I am creating an application to understand how
CodeIgniter works, and I doubt has arisen.

Suppose that the application has a menu and a dynamic main <div>, in the menu the links are read
from a database, and this menu is constant except when it adds a new link from a form.

every time you reload the page (whatever the controller), I suppose that the menu should be read what is new in the database. but, how can I do this if CodenIgniter just let me load one controller?

can I execute a external function from the template (the main view) to show the "links" ?

something like.

&lt;?php showLinks(); ?&gt;

// dynamic content

thanks for help.
excuse my bad englishSmile

Yes... this gets controlled in the controller Wink

Example for how it would be done (without the database)

class Mycontroller Extends Controller {

  function Mycontroller()

  function index()
    $data['title'] = "My Title";
    $data['menu'] = array('link1' => 'Link', 'link2' => 'Link', 'link3' => 'Link');
    $this->load->view('template', $data);


&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
<div id='menu'>&lt;?php foreach ($menu as $links):
echo anchor('$links', 'Link');
<div id='content'>Blahalhalhlah

Hi stuffradio, thanks for the fast response.

but.. what if the menu must be in all the views?? do i have to create
always something like

$data['links'] = $this->model->get_links();
$this->load->view("myview", $data);


right now i'm working with something like this.

i have a template( template.php )


      <div id="menu">



      <div id="foot">

my controllers always make this if they wanna load a view with the template tempalte.php
function foo(){
$data['title'] = "testing...";
          $data_content['something'] = "bla bla bla bla";
          $data_content['something2'] = "bla bla bla bla";
$data['content']=$this->load->view("inner_content",$data_content, true);

$this->load->view("template", $data);

and I dont need to load always the header, footer, menu.

but.. what i want to do.. is.. load some dynamic content in the

<div id="menu"></div>

calling a showFunction(); or something like that.

thanks again Wink


but there is some way you can do it automatically. You could autoload the model, and then call it always.

I'm not too sure how to explain it right now, it's pretty much bed time for me Tongue

ok men. thanks for your time Wink
i will try Wink

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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