CodeIgniter Forums
Some routing problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Some routing problems (/showthread.php?tid=56840)

Pages: 1 2


Some routing problems - El Forum - 01-24-2013

[eluser]Metamorphosis[/eluser]
Good day everyone.

i've got some issues with the routing...

This doesn't work:
Code:
$route['member/(:any)'] = "member/view/$1";

but this works...
Code:
$route['member/blaze'] = "member/view/blaze";

So my question is: What's wrong with my routes.php?
Did i configure something wrong?

Please excuse my bad english and my meager word choice.




Some routing problems - El Forum - 01-24-2013

[eluser]PhilTem[/eluser]
To me it looks good, but: which version of CI are you using?


Some routing problems - El Forum - 01-24-2013

[eluser]Metamorphosis[/eluser]
I use CI 2.1.2


Some routing problems - El Forum - 01-24-2013

[eluser]PhilTem[/eluser]
Do you get a 404-page or something else (e.g. blank page)?


Some routing problems - El Forum - 01-24-2013

[eluser]Metamorphosis[/eluser]
I receive a 404 Error Page


Some routing problems - El Forum - 01-24-2013

[eluser]Otemu[/eluser]
Can we view your controller code?


Some routing problems - El Forum - 01-24-2013

[eluser]Metamorphosis[/eluser]
The controller code. It's the nearly the same code like the News Controller at the User's Guide.

member.php
Code:
<?php
class Member extends CI_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->model('member_model');
    }
    
    public function index(){
        
        $data['member'] = $this->member_model->get_member();
        $data['title'] = 'Member';
        
        $this->load->view('templates/header', $data);
        $this->load->view('member/index', $data);
        $this->load->view('templates/footer');
    }
    
    public function view($slug){
        $data['member'] = $this->member_model->get_member($slug);
        if(empty($data['member'])){
            show_404();
        }
        
        $data['title'] = $data['member']['name'];
        
        $this->load->view('templates/header', $data);
        $this->load->view('member/view', $data);
        $this->load->view('templates/footer');
    }
}
?>



Some routing problems - El Forum - 01-24-2013

[eluser]PhilTem[/eluser]
It seems that you're getting the 404 because there's no row/member returned from your model. What's the code of the latter method?


Some routing problems - El Forum - 01-24-2013

[eluser]Otemu[/eluser]
PhilTem is correct, it is reaching your controller and calling the show_404(); function.
To test just echo a value for example
Code:
public function view($slug){
        echo 'hi my route does work';
    }

Then your know for sure that your route is working, maybe the name your putting into the url doesn't exist in the database.


Some routing problems - El Forum - 01-24-2013

[eluser]Metamorphosis[/eluser]
It's still the same problem.

i changed the controller's view method to:
Code:
public function view($slug){
  echo 'If you can see this, the route is working';
}
and still get the 404 page :/

and the name is in the database.
i created it at the same time and the links are generated with
Code:
<a href="member/&lt;?php echo $member['slug'] ?&gt;">