Part of the EllisLab Network
   
 
Controller in subdir having URI problems…
Posted: 08 January 2007 08:47 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  147
Joined  09-24-2006

Hi guys,

I have a controller in a sub dir (controllers/admin/club_directory), even though my trace shows that the correct routed URI is coming through it doesnt seem to pass the argument to the method as expected (FYI I’m using CI 1.5.0.1)

Here’s the relevant snippet:


require_once(APPPATH.'controllers/front.php');

class
Club_Directory extends Front {

    
function Club_Directory(){
        parent
::Front();
        
    
}
    
    
function view_club($id = ''){
        
echo $this->uri->ruri_string();//outuputs /club_directory/view_club/1/
        
die('id: '.$id);// outputs <empty string>

What am I doing wrong??? Would appreciate some help thanks! smile

Profile
 
 
Posted: 09 January 2007 07:22 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  147
Joined  09-24-2006

Hi guys, still stuck at the same problem… Anyone!?

Profile
 
 
Posted: 10 January 2007 03:54 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  166
Joined  08-31-2002

Maybe the variable isn’t passed if you are using a re-routed URL? You’d have to do some testing to confirm that (disable the custom routing and access the controller with the full URL), but you should be able to get around it by putting $id = $this->uri->rsegment(3) at the top of the controller if that is indeed the problem.

Profile
 
 
Posted: 10 January 2007 05:23 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  915
Joined  07-10-2006

Try renaming your class and constructor to Club_directory.

Profile
 
 
Posted: 14 January 2007 09:37 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  147
Joined  09-24-2006

Hi Bulk and Estra.

@Bulk Im using the routed URL for my link:


In the view…

anchor('admin/club_directory/edit_club/my-club-name-23', 'My Club Name');

In the routes…

$route['admin/club_directory/edit_club/[a-zA-Z0-9-]+-([0-9]+)'] = "admin/club_directory/edit_club/$1";

@ elstra renaming classs and constructor doesnt solve the issue either :/

Profile
 
 
Posted: 15 January 2007 03:35 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  166
Joined  08-31-2002

Just wondering - in the code you pasted, the function in your controller is view_club, but in the route you defined, you are calling edit_club.. did you miss some code in your example?

Profile
 
 
Posted: 15 January 2007 04:33 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  147
Joined  09-24-2006

Ooops sorry a typo in my post… Yes both functions suffer the same problem. Essentially the same routes for both functions:

$route['admin/club_directory/view_club/[a-zA-Z0-9-]+-([0-9]+)'] = "admin/club_directory/view_club/$1";
$route['admin/club_directory/edit_club/[a-zA-Z0-9-]+-([0-9]+)'] = "admin/club_directory/edit_club/$1";

Profile
 
 
Posted: 15 January 2007 05:10 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  166
Joined  08-31-2002

Ok, after some indepth examination of the code, I’ve found a bug in the base CodeIgniter.php file…

Now, if you want to fix this completlety, you’ll need to edit that file - which of course is a bit extreme.. its about as core as core gets. The fix is…

in /application/codeigniter/CodeIgniter.php

at line ~217, change:

call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));

to

if ($RTR->rsegments == $RTR->segments)
{
    call_user_func_array
(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
}
else
{
    call_user_func_array
(array(&$CI, $method), array_slice($RTR->rsegments, 2));
}

Basically the Router class strips any directory from the rsegments array anyway, so the code that moves the offset of array_slice is reduntant and (SHOULD) be safe to remove.

Update: My previous fix broke normal URLs to controllers in sub-dirs. This is a bit of a kludge the alternative meant re-writing portions of the base Router.php class which I didn’t want to do.

If you’re not comfortable editing a base file, then you can just use $id = $this->uri->rsegment(3); at the top of your script, until this bug is fixed.

I’ll post this in the bugs forum too.

Profile
 
 
Posted: 15 January 2007 06:44 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  147
Joined  09-24-2006

Ok, thanks for looking into it Bulk…I’m nervous about the Core change so i’ll wait to see where the bug report goes raspberry

Profile
 
 
Posted: 19 April 2007 11:58 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Rank
Total Posts:  51
Joined  09-12-2006

Hi

Look here and tell me if this solve your problem too??
thanks

Profile
 
 
Posted: 19 April 2007 12:45 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  51
Joined  09-12-2006

Hi
Look here and tell me if this solve your problem too??

thanks

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66415 Total Logged-in Users: 36
Total Topics: 84756 Total Anonymous Users: 2
Total Replies: 454846 Total Guests: 240
Total Posts: 539602    
Members ( View Memberlist )