[eluser]basterz[/eluser]
Hello everyone I am a newbie in programing (started a few month ago) I choose codeigniter because it is very cool and readable. I want to ask how can I make my dynamic_menu visible into the global template.
This is my controller:
Code:
<?php
class dynamic_menu extends Controller
{
function index()
{
$this->load->model('dynamic_menu_model');
$data['menu'] = $this->dynamic_menu_model->getAll();
$this->load->view('menu', $data, true);
}
}
?>
This is my model:
Code:
<?php
class dynamic_menu_model extends Model
{
function getAll()
{
$query = $this->db->get('dynamic_menu');
return $query;
if($q->num_rows() > 0)
{
foreach($q->result() as $row)
{
$data[]=$row;
}
return $data;
}
}
}
?>
This is my view for the menu:
Code:
<?php
$q = $this->db->get('dynamic_menu');
if($q->num_rows() > 0)
{
foreach($q->result() as $row)
{
$menu[]=$row;
}
}
?>
<div id="logo">
<h1>Architecture Bureau</h1>
<p>It's all possible</p>
</div>
<div id="nav">
<ul>
<?php foreach($menu as $m): ?>
<li><a >url; ?>"><?php echo $m->name; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
This is my global layout:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Architecture</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>stylesheet/style.css" type="text/css" charset="utf-8" />
</head>
<body>
<div id="wrapper">
<div id="header"> </div>
<div id="left">
<?php
$this->load->view('menu');
?>
</div>
<div id="right">
</div>
<div class="clear"> </div>
<div id="spacer"> </div>
<div id="footer">
<div id="copyright">
Copyright © 2007 Company Name All right reserved.
</div>
<div id="footerline"></div>
</div>
</div>
</body>
</html>
this is my part of the database that I think you may need:
Code:
CREATE TABLE IF NOT EXISTS `dynamic_menu` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`description` text NOT NULL,
`meta_tags` text NOT NULL,
`page_title` text NOT NULL,
`url` text NOT NULL,
`created_on` datetime NOT NULL,
`uploaded_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `dynamic_menu`
--
INSERT INTO `dynamic_menu` (`id`, `name`, `description`, `meta_tags`, `page_title`, `url`, `created_on`, `uploaded_on`) VALUES
(2, 'Home', 'This is a homepage', 'some metas', 'Home', 'DynamicMenu', '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(3, 'Recent Projects', 'Those are our recent projects', 'some metas', 'Our recent projects', 'Products', '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(4, 'Services', 'This is service description', 'some metas', 'This is service title', 'Services', '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(5, 'Clients', 'This is a client description', 'some metas', 'this is Client title', 'Clients', '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(6, 'Solutions', 'Description for solutions', 'some metas', 'Title for solutions', 'redirect to solutions'
So for the moment I've hardcoded the query into the "menu" view but I know it is wrong. I am looking for some other solution.
Regards