[eluser]jen_84[/eluser]
Hi!
Im a newbie on Codeigniter, so just don't tell me to read the user guide because it would'nt help me much.
Im working on a simple cms in Codeigniter (2.1.0) and i have run into a small problem. I have created a dynamic menu with a menu model and it shows as it should. My menu model locks like this:
menu_model.php
Code:
<?php
class Menu_model extends CI_Model {
function __construct() {
//Call parent constructor
parent::__construct();
}
function get_menu () {
$q = $this->db->get('ci_menu');
if($q->num_rows() > 0) {
foreach($q->result() as $row) {
$menu[] = $row;
}
return $menu;
}
}
}
And here is my view page to display the menu:
header.php
Code:
<html>
<head>
<title>Index Page</title>
<link rel="stylesheet" href="<?php echo base_url();?>css/main.css" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<div id="top_nav"><?php echo anchor('admin', 'Admin panel'); ?></div>
<div id="container">
<div id="header">
<h1>MyCms</h1>
<div id="menu">
<ul id="navbar">
<?php foreach ($menu as $m) : ?>
<li id="navbar"><a href="<?php echo site_url($m->url); ?>"><?php echo ($m->name); ?></a></li>
<?php endforeach ;?>
</ul>
</div>
</div>
</div>
Ok, so far so good. Now I want these menu links to point to different pages and change the content on main.php dynamically to display a specific page depending on wich menu link the user had clicked on. The problem is that I don't know how to make this work. I know how to grab all the content from the pages table from database, but not how to grab a single row with a particular id and then show it's content on the main.php view.
My database lock like this:
Code:
CREATE TABLE IF NOT EXISTS `ci_menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`page_id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`url` varchar(150) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `ci_pages` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id for pages',
`pg_title` varchar(50) NOT NULL,
`content` text NOT NULL,
`link` varchar(150) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Could someone please explain to me how to make this work.
Sorry for my bad grammar, but english is not my native language.