[eluser]Unknown[/eluser]
I have developed quite an extensive addon to the CodeIgniter codebase, and have come across quite a strange bug. There's quite a lot to get to explain the bug...
Firstly, I have a settings file in which I can specify 'virtual folders' within my application, which I include in the index.php file (in the root):
Code:
$settings = array(
'virtual-folders' => array(
'admin' => array(
'prefix' => 'admin_',
'theme' => 'default',
'default' => 'users/admin_dashboard',
'authenticate' => TRUE,
'login' => 'admin/login',
'logout' => 'admin/logout'
)
)
...
);
$GLOBALS['settings'] = $settings;
My intention is to use this to route '/admin/users/add' to 'users/admin_dashboard'. I then set up the routes.php file to look something like this:
Code:
$all = "([\w-]+)";
$any = "([\w/-]+)";
$ext = '';
$settings = $GLOBALS['settings'];
foreach ($settings['layouts'] as $key => $value) {
if ($ext && ($key != 'default')) {
$ext .= '|.' . $key;
}
else if ($key != 'default') {
$ext .= '.' . $key;
}
}
$ext = '(' . $ext . ')?';
$route['default_controller'] = $settings['general-settings']['default-route'];
$route['scaffolding_trigger'] = "";
$route['admin/login'] = 'users/admin_login';
$route['admin/logout'] = 'users/admin_logout';
$route['admin/dashboard'] = 'users/admin_dashboard';
foreach ($settings['virtual-folders'] as $key => $value) {
$route[$key . '/' . $all . '/' . $any . $ext] = "$1/" . $value['prefix'] . "$2/$3";
$route[$key . '/' . $any . $ext] = "$1/" . $value['prefix'] . "index";
$route[$key] = $value['default'];
}
$route[$any . $ext] = "$1";
The problem is that when I set up a controller method that uses the automatic url to argument conversion (based on segmental positioning):
Code:
function admin_view($bob = 1, $page = 2) {
$this->crumbs = array(
'Adverts' => base_url() . 'admin/advertcampaigns/view',
'Advert Types' => base_url() . 'admin/adverttypes/view'
);
print_r($bob);
print_r($page);
$this->adverttypes->select(array(
'url' => base_url() . 'admin/adverttypes/view/',
'limit' => 10,
'page' => $page
));
}
If I specify the first argument as an integer value (ex. '/testapp/admin/adverttypes/view/5') then $bob reflects a value of 5, $page reflects a value of 2.
If I omit the integer value (ex. '/testapp/admin/adverttypes/view/') then $bob reflects a value of 1, $page reflects a value of 5.
So, in plain terms, when I use this method of custom routing (which should render the routed segments in the same way as any other method) the arguments array differs when uri values are omitted.
Curious...