Welcome Guest, Not a member yet? Register   Sign In
doubt with controllers
#1

[eluser]kmil0[/eluser]
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.

<template>
<menu>
&lt;?php showLinks(); ?&gt;
</menu>

<dynamicdiv>
// dynamic content
</div>
</templte>

thanks for help.
excuse my bad englishSmile
#2

[eluser]stuffradio[/eluser]
Yes... this gets controlled in the controller Wink

Example for how it would be done (without the database)
Code:
&lt;?php

class Mycontroller Extends Controller {

  function Mycontroller()
  {
    parent::Controller();
    $this->load->helper('url');
  
  }

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

}

Template
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<div id='menu'>&lt;?php foreach ($menu as $links):
echo anchor('$links', 'Link');
endforeach;
?&gt;
</div>
<div id='content'>Blahalhalhlah
</div>
&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]kmil0[/eluser]
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

Code:
$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 )

Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

      <div id="menu">

      </div>

      &lt;?=$content?&gt;

      <div id="foot">
      </div>
&lt;/body&gt;
&lt;/html&gt;

my controllers always make this if they wanna load a view with the template tempalte.php
Code:
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
#4

[eluser]stuffradio[/eluser]
Yes,

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
#5

[eluser]kmil0[/eluser]
ok men. thanks for your time Wink
i will try Wink




Theme © iAndrew 2016 - Forum software by © MyBB