Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Routing works on MAMP NOT LAMP
#16

[eluser]Tim Brownlaw[/eluser]
Well Andy...
I've just setup your case in my CI LAMP dev site and this is what I've come up with...
HINT: Always write out what you have done and what the result was! That way you know what you tried and what happened!
The Setup
In application/config/route.php we have
Code:
$route['default_controller'] = "home";
$route['404_override'] = '';
In application/controllers/home.php we have
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
  public function index()
  {
    $this->load->view('welcome_message');
  }
}
/* End of file home.php */
/* Location: ./application/controllers/home.php */
RESULT: When we run cidev22.com – we get the default Home Controller loading and we are greeted byt the CI Welcome Message... So that all works.
Now WHAT IF I set the Controller Class name from Home to home.
So
Code:
class Home extends CI_Controller {
becomes
Code:
class home extends CI_Controller {
RESULT: It still works. But class names should be capitalized!

Now What IF I change the Controllers Filename from home.php to Home.php
RESULT: It goes BANG – 404 Page Not Found

Now What IF I change the route from
Code:
$route['default_controller'] = 'home';
to
Code:
$route['default_controller'] = 'Home';
RESULT: It works – In this particular instance
NEXT:
NOW Let's set the router to include
Code:
$route['$product/(:any)'] = 'Home/productdetail/$1';

Now our controller becomes...
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
  public function index() {
  $this->load->view('welcome_message');
  }

  public function productdetail() {
    $product_name = $this->uri->segment(2);
    if (empty($product_name)) {
      echo 'No Product Selected';
    }
    else {
      echo 'You chose ' . $product_name;
    }
  }
}
/* End of file home.php */
/* Location: ./application/controllers/home.php */
And the application/config/routes.php becomes
Code:
$route['default_controller'] = 'home';
$route['product'] = 'home/productdetail';  // Required when only website.com/product is entered else you get a "Page Not Found"
$route['product/(:any)'] = 'home/productdetail/$1'; // Required for website.com/product/smurfs
$route['404_override'] = '';
IMPORTANT NOTE: It appears that the URL in a case like $route['product/(:any)'] = 'home/productdetail/$1'; IS Case Sensitive... so 'home/productdetail/$1'; Works whereas 'Home/productdetail/$1'; results in a 404 Page not found
It appears that $route['product'] is required to catch the default case. Well that's what happened in this test setup anyways...

Entering website.com/product results in
Code:
No Product Selected
Entering website.com/product/smurfs results in
Code:
You chose smurfs

So think through what you are doing... DO IT – Write down what you did and what happened and you'll end up finding the Answer!
Just like I did here and I even learned a few new things!!!


Messages In This Thread
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 09:13 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 10:14 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 10:26 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 10:43 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 10:47 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 11:02 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-15-2014, 11:10 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-16-2014, 06:09 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-16-2014, 09:15 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-16-2014, 09:27 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-17-2014, 05:40 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-18-2014, 02:05 PM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-18-2014, 04:49 PM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-18-2014, 05:38 PM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-18-2014, 05:40 PM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-18-2014, 07:02 PM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-19-2014, 02:53 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-19-2014, 05:06 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-20-2014, 05:01 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-20-2014, 05:10 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-20-2014, 05:11 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-20-2014, 05:30 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-20-2014, 05:39 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-20-2014, 04:43 PM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-21-2014, 03:20 AM
CodeIgniter Routing works on MAMP NOT LAMP - by El Forum - 10-21-2014, 06:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB