php - dynamic page is not working -


i have created controller named index , want develop dynamic controllers big hurdle creating page name again , again decided create have confusion though how developing pages have placed option in admin panel users can create pages though big issue unable retrive pages.

controller

public function index($page = 7) {         //$page = 7 7 default page set home          $page_data           = $this->get_data->alldata('pages', $page);         $data['title']   = $page_data->row()->pagetitle;         $class               = explode("/", $page_data->row()->template);         $data['body_class'] = $class[1];          $this->load->view('includes/header.php', $data);          if($class[1] == 'home') {             $this->load->view('templates/slider');         }          $this->load->view('templates/navigation.php');          $page_content   = $page_data->row()->template;         $this->load->view($page_content, $data);         $this->load->view('includes/footer.php');     }      public function page($pagename) {         $page_data          = $this->get_data->alldata('pages', $pagename);         $data['title']      = $page_data->row()->pagetitle;         $class              = explode("/", $page_data->row()->template);         $data['body_class'] = $class[1];          $this->load->view('includes/header.php', $data);          if($class[1] == 'home') {             $this->load->view('templates/slider');         }          $this->load->view('templates/navigation.php');          if($class[1] == 'home') {             $data['slider'] = 'templates/slider';         }          $data['content']    = $page_data->row()->template;         $this->load->view('index', $data);         $this->load->view('templates/footer-form.php');         $this->load->view('includes/footer.php');     } 

model

public function alldata($table, $pageid) {     $query_data = $this->db->get_where($table, array('pageid' => $pageid));     return $query_data; } 

my navigation page

 <?php       $sql_nav = $this->db->get("menu_navigation");        foreach($sql_nav->result() $nav) {                         echo "<li><a href='".base_url()."home/page/".$nav->menu_name."'>".$nav->$menu_name."</a></li>";                         //output http://localhost:90/kwikrepair/home/page/(menu name page name exist in database)                     }                 ?> 

now trying send call pages of requested data coming pages page data call upon when users click on navigation , the page id want pass in parameter index controller how passed ?

this isn't correct way develop dynamic pages using codeigniter. codeigniter mvc framework. if follow proper seperation of model-view-controller, easy develop dynamic web pages using codeigniter.

codeigniter user guide easy follow , has examples. please try of given tutorials.

in codeigniter, views loaded in order appear in controller. like:

$this->load->view('header'); $this->load->view('body'); $this->load->view('footer'); 

so if want optionally load page segment, in controller:

if($class[1] == 'home') {     $this->load->view('templates/slider'); } 

you don't pass view inside variable. passing data database model. pass data view, do:

$data['title'] = "some title" //any data or variable 

then can pass data associated view like:

$this->load->view('my_view',$data); 

and able view title $title variable in my_view.

similarly can save navigation template in views/templates folder , load as:

$this->load->view('templates/navigation'); 

you don't do:

<?php include('templates/navigation.php'); ?> 

like normal php pages. codeigniter mvc web framework. follow proper mvc guidelines described in codeigniter's excellent user guide documentation.

default format of codeigniter urls like:

<installation-folder>/index.php/<controller>/<function> 

if have controller named welcome.php like:

class welcome extends ci_controller {      /**      * index page controller.      *      * maps following url      *      http://example.com/index.php/welcome      *  - or -      *      http://example.com/index.php/welcome/index      *  - or -      * since controller set default controller in      * config/routes.php, it's displayed @ http://example.com/      *      * other public methods not prefixed underscore      * map /index.php/welcome/<method_name>      * @see https://codeigniter.com/user_guide/general/urls.html      */     public function index()     {         $this->load->view('welcome_message');     }      public function display($page = 7){         echo $page;     } } 

i can go page:

http://127.0.0.1/ci/index.php/welcome/display 

and shown 7, default value assigned $page variable if don't pass anything.

if go to:

http://127.0.0.1/ci/index.php/welcome/display/2 

$page variable assigned value 2 , display 2.

here comments taken default controller comes codeigniter installation:

/**  * index page controller.  *  * maps following url  *      http://example.com/index.php/welcome  *  - or -  *      http://example.com/index.php/welcome/index  *  - or -  * since controller set default controller in  * config/routes.php, it's displayed @ http://example.com/  *  * other public methods not prefixed underscore  * map /index.php/welcome/<method_name>  * @see https://codeigniter.com/user_guide/general/urls.html  */ 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -