Welcome Guest, Not a member yet? Register   Sign In
Please help me. I'm a newbie
#1

[eluser]Unknown[/eluser]
I create Main Controller with index action. Code here:
Code:
index()
{
   $data['content'] = 'My Content Here';
   $this->load->view('template',$data);
}
//and menu action here
menu()
{
  $this->load->helper('url');
  $data['menu'] = array(
    array(
     'title'=>'Home Page','link'=> base_url().'homepage',
    ),
    array(
     'title'=>'Contact','link'=> base_url().'contact',
    )
  );
$this->load->view('menu',$data);
  //Right i will code the homepage controller and contact controller
}
//-----------
menu.php //view
---------------
<ul>
&lt;?php foreach($menu as $item):?&gt;
<li><a href='&lt;?=$item['> &lt;?= $item['title']?&gt; </a></li>
&lt;?php endforeach;?&gt;
</ul>
//------------
template.php //view
---------------
html.....
&lt;body&gt;
<div id='header'>
    // So I want the menu action process and its view will show here. Please help me. So sorry i poor English
</div>
<div id='content'>
  &lt;?= $content;?&gt;
</div>
<div id='footer'>
</div>  
&lt;/body&gt;
#2

[eluser]LifeSteala[/eluser]
Welcome to Code Igniter. In future, please try to wrap your code in the code tags.

In your template.php view, add this:

Code:
<div id=‘header’>
  // So I want the menu action process and its view will show here. Please help me. So sorry i poor English
  &lt;?php $this->load->view('menu'); ?&gt; // load menu view
</div>

That should theoretically work.

Good Luck!
#3

[eluser]cereal[/eluser]
I can confirm it works, but this won't load the menu() function, it will load only the view.
I would create a model for the menu:

Code:
function list()
{
    $this->load->helper('url');
    $a = array(
        array('title' => 'homepage','link'=>base_url().'homepage'),
        array('title' => 'second page','link'=>base_url().'second')
    );
    return $a;
}

and then write the controller index() like this:

Code:
function index()
{
    $this->load->model('menu'); // it's better to autoload this
    $data['menu'] = $this->menu->list();
    $data['content'] = 'My content here';
    $this->load->view('template',$data);
}

Or, in alternative, load more views:

Code:
function index()
{
    $data['menu'] = array(/*your array menu here*/);
    $data['content'] = 'My content here';
    $this->load->view('menu',$data);
    $this->load->view('template',$data);
}

bye Smile
#4

[eluser]Unknown[/eluser]
So sorry I'm poor english, The above problem is a small factor in my project. I want to present more clearly. I want to create layout for my website like this:
[code]
|-----------------------------------------------------------------------------|
| HEADER AREA |
| --------------------- |
| Menu-> Home * Products * About Us * Contact <-Menu |
|-----------------------------------------------------------------------------|
| LEFT CONTENT | |
| | |
| This content | |
| is the categories| |
| of products | THIS IS MY LAYOUT. It's very simple |
| | |
| | I call this area is "MAINCONTENT" |
|------------------| |
| Some Image Here | |
| | |
|-------------------------------
#5

[eluser]cereal[/eluser]
Please explain better, if I'm understanding, your problem relates to the layout not to CodeIgniter.
p.s. If you use a code tag in your replies, your posts will look much better Wink
#6

[eluser]Mischievous[/eluser]
Really you could load all your views? To make it less repetitious you could place your main parts in a extended controller Smile


Code:
$template = array(
   'header' => $this->load->view('header_file', $header_data, TRUE),
   'menu' => $this->load->view('menu_file', $menu_data, TRUE),
   'content' => $this->load->view('content_file', $content_data, TRUE),
   'footer' => $this->load->view('footer_file', $footer_data, TRUE)
);

$this->load->view('template',$template);

OR.... you could use a template library.
Template Library
Phil Sturgeon's Dwoo Template Library

OR... you could make your own?




Theme © iAndrew 2016 - Forum software by © MyBB