Welcome Guest, Not a member yet? Register   Sign In
URI Routing Issue
#1

[eluser]the_unforgiven[/eluser]
Hi,

I'm having an issue with the routes of the site I'm building.

Here's my controller, model and view along with what i have tried in the routes based on the CI manual.

Controller:
Code:
// Pages
function pages($path){
  $data['navi'] = $this->MPages->getAllPages();
     $page = $this->MPages->getPagePath($path);
  
  $data['title'] = $page['name'];

  $data['metadesc'] = $page['description'];
  $data['metakeywords'] = $page['keywords'];

  $data['page'] = $page;

  $data['content'] = 'page';
  $data['title'] = ucfirst($page['name']);

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

Model
Code:
function getAllPages(){
     $data = array();
  $this->db->limit(7);
     $Q = $this->db->get('pages');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data;
}

View
Code:
<?php
    foreach ($navi as $p) : ?>
    <li><a href="&lt;?php echo base_url(); ?&gt;&lt;?php echo $p['path']; ?&gt;" title="Home">&lt;?php echo $p['name']; ?&gt;</a><span class="line">|</span></li>
  
   &lt;?php endforeach; ?&gt;

Routes
Code:
$route['pages/(:any)'] = 'home/pages/$2';

So my question is based what I have wrote how should my routes look should the client add in more pages?

Help and code samples based on mine code would be highly appreciated, thanks in advance.
#2

[eluser]zoopstud[/eluser]
[quote author="the_unforgiven" date="1336395729"]
Routes
Code:
$route['pages/(:any)'] = 'home/pages/$2';
[/quote]

Does $1 work?

Code:
$route['pages/(:any)'] = 'home/pages/$1';
#3

[eluser]the_unforgiven[/eluser]
neither works I tried $1 and put $2 on here just in case sorry should have said thats $1 and $2 doesnt work, any other idea's
#4

[eluser]the_unforgiven[/eluser]
When using $1 i get

Code:
Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.
#5

[eluser]the_unforgiven[/eluser]
If i set my route like this:
Code:
$route['(:any)'] = 'home/pages/$1';
it works but then cocks up my other links for categories...
#6

[eluser]CroNiX[/eluser]
Post all of your routes. Your 404_override and default_controller routes need to come first before any others that use regular expressions (see very bottom of routes in userguide).

As far as your other controllers, you will need to create routes for all of those as well. Once you start using routes you have to route everything since you are straying from the default CI behavior of /controller/method/params. Either that or use a negative rule in your catch-all route telling it to route only if the first segment is x,y,z, such as "about", "contact", etc.
#7

[eluser]the_unforgiven[/eluser]
this now works

Code:
I did have these before just didnt think it would be relevant!
$route['default_controller'] = 'home';
$route['404_override'] = 'errors';

/*
| -------------------------------------------------------------------------
| CUSTOM ROUTES
| -------------------------------------------------------------------------
*/

$route['pages/(:any)'] = 'home/pages/$1'; // Pages Routes page!
$route['categories/(:any)'] = 'home/categories/$1'; // Categories

After playing around with it and changing my links withing my code view file this now works!




Theme © iAndrew 2016 - Forum software by © MyBB