Wednesday, 15 September 2010

codeigniter - How can display different pages by one function and how should declare links in menu? -



codeigniter - How can display different pages by one function and how should declare links in menu? -

headerview.php

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title><?php echo $title; ?></title> </head> <body> <div id="topmenu"> <ul> <li><a href="what should write here ?">home</a></li> <li><a href="what should write here ?">about us</a></li> <li><a href="what should write here ?">contact us</a></li> </ul> </div>

footerview.php

</body> </html>

controllers/main.php

<?php if (!defined('basepath')) exit('no direct script access allowed'); class main extends ci_controller { function index(){ $this->load->view('headerview'); $this->load->view('homeview'); $this->load->view('footerview'); } } ?>

how can show view/about_us_view.php, view/contact.php etc pages 1 function ?

-thanks.

i assume ur view pages in root views folder

controller

<?php if (!defined('basepath')) exit('no direct script access allowed'); class main extends ci_controller { function index($page = 'homeview') { if ( ! file_exists('application/views/'.$page.'.php')){ show_404(); } else{ $this->load->view('headerview'); $this->load->view( $page); $this->load->view('footerview'); } } }

header

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title><?php echo $title; ?></title> </head> <body> <div id="topmenu"> <ul> <li><a href="<?php echo base_url('index.php/main');?>">home</a></li> <li><a href="<?php echo base_url('index.php/main/index/about_us_view');?>">about us</a></li> <li><?php echo base_url('index.php/main/index/contact');?>">contact us</a></li> </ul> </div>

the basic url pattern given below

http://example.com/[controller-class]/[controller-method]/[arguments]

in index function passing page name argument

to view contact page

<?php echo base_url('index.php/main/index/contact');?>

here

controller:main

method:index

argument:contact

also autoload url helper in config/autoload.php.

$autoload['helper'] = array('url');

codeigniter menu

1 comment: