Vuthy Sok Vuthy Sok - 1 year ago 97
PHP Question

Codeigniter Route url parents page and child page

Edit: I am new Codeigniter I am not how to use Codeigniter Routing. I create Contact Us page and Map page. Map page is the subpage of Contact Us page.

Table Name : Pages

id label link parent
1 Contact Us contact-us 0
3 About Us about-us 0
2 Map map 1

Here my Controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends CI_Controller {

public function __construct()
public function index()

$data['getAllPage'] = $this->page_model->getAllPages();


public function view($id) {
$data['single_page'] = $this->page_model->displaySinglePage($id);

In routes.php I have put $route['(:any)'] = "page/view/$1";

When I enter url "" or "" it show correct content of Contact page but I enter "" it still show content of Contact page.

What I want when I enter "" it shuold show content of Map page

Thanks in advance.

Answer Source

Please try code maybe can help

// Parents and Child page.
$route['page/(:any)/(:num)'] = "page/view/$1/$2";

// For Main Home Page.
$route['(:any)'] = "page/view/$1";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download