• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some routing problems

#1
[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.


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

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

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

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

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

#7
[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');
    }
}
?>

#8
[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?

#9
[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.

#10
[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;">


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.