Welcome Guest, Not a member yet? Register   Sign In
( edited ) - Creating menus
#1

[eluser]AntSteinn[/eluser]
/*****************ADDED**********************/
I started reading user_guide after I sent this topic.
So I was reading about Views, Models and Controllers and I'm thinking for the future when I will use Template system so I can change Template in Backend. Should I have my templates folder in views folder or make new folder for templates.

Is some way so the controller knows what template he should displaying?
Code:
$this->load->view('templates/blue/tmplfile');

Code:
$template = $thatone //From database
$validtemp = 'template/'.$template.'/tmplfile';

$this->load->view($validtemp);
Is it good way if it works?


Another question
Code:
function user($username)
    {
        echo $username;
    }
I know when I write explane.com/users/LaLaLa

Will print out: LaLaLa

Is that way also for getting story from database, like if building memberslists and linking username http://explane.com/user/username ?




Sorry my english.
/********************************************/



Hi.

I have template and I'm creating Menus by database.

When I set query on template file, will come up my result.
But I want have it in model/controller so it's more easy later If I will build new template and can just put get_menus(); than hole query code.

Sorry my english, If someone could understand what I'm meaning will it be great get feedback.

--
1. I have template saved as ../views/templates/orginal/index.php
2. I have file saved as ../controller/beta.php It's file calling to my template and show it up on web.com/beta

Code:
<?php
class Beta extends Controller {

    
    function index()
    {
    $data['page_title'] = 'Chat.is - Beta';
     $data['main_content'] = 'templates/orginal/index';
$this->load->model();
    $this->load->view('templates/orginal/index', $data);
     }

    
}
?>
Fatal error: Class 'Menus' not found in /home/chatis/public_html/system/libraries/Loader.php on line 184

If I have only $this->load->model('');
will come up:
Fatal error: Class 'MenusModel' not found in /home/chatis/public_html/system/application/views/templates/orginal/index.php on line 33



3. I have model for query from database ../model/menus/menus.php

Code:
<?php
class MenusModel extends Model {

function MenusModel()
    {
        parent::Model();
    }
    
    function get_menus()
    {
       $query = $this->db->query("SELECT title FROM menus");

if ($query->num_rows() > 0)
{
   foreach ($query->result() as $row)
   {
      echo $row->title;
   }
  }
}    
}
?>

4. I'm using autoload for database config.

In my template file are get_menus(); trying to call and get error

8-/
#2

[eluser]ELRafael[/eluser]
Ops, you're doing wrong ;P

Controller
Code:
function index()
{
  //Bla bla bla
  //Now the code
  $this->load->model('MenusModel', 'Menu');
  //If you'll use views, i recommend this way
  $data['menus'] = $this->Menu->get_menus();
  $this->load->view('templates/original/index', $data);
  //But if you won't, just do that
  $this->Menu->get_menus();
}

Model
Code:
function get_menus()
{
  $this->db->select('title');
  //Now, if you'll use views, try this way
  return $this->db->get('menus');
  //Otherwise, you can do like that
  $query = $this->db->get('menus');
  foreach ( $query->result() as $m )
  {
    echo $m->title;
  }
}

View
Code:
<!-- //In case that you use views -->
<?php if ( $menus->num_rows() > 0 ) : ?>
  <?php foreach ( $menus->result() as $m ) : ?>
    The title of menu is: &lt;?php echo $m->title; ?&gt;<br />
  &lt;?php enforeach; ?&gt;
&lt;?php else : ?&gt;
  No donuts for you, muah muah muah
&lt;?php endif; ?&gt;
#3

[eluser]AntSteinn[/eluser]
On the top, edited topic




Theme © iAndrew 2016 - Forum software by © MyBB