Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed issue #1076 #1081

Closed
wants to merge 5 commits into from

3 participants

@marcosgdf

Fixed issue #1076

@marcosgdf

So...? The issue has already been closed... This should be approved...

@narfbg
Owner

There's a conflict between your version and the one in EllisLab's repository. You'll have to sync any changes from it first.

@marcosgdf

What about now?

@narfbg
Owner

Yes, it can be merged now.
But why is _set_routing() execution moved after _set_overrides()?

@marcosgdf

Because _set_overrides() sets the params and should be set in order to _set_routing() detect them

CodeIgniter/system/core/Router.php - line: 510

if (isset($routing['function']))
        {
            $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function'];
            $this->set_method($routing['function']);
        }
@narfbg
Owner

_set_routing() doesn't seem to detect anything but settings from application/config/routes.php. I haven't tested it, but to me it looks like this would effectively eliminate any overrides.

@marcosgdf

Routing is set in index.php, line 99-105. The routing array is passed to set_overrides() and then is used in set_routing()

If you want to reproduce it, check issue #1076 and you'll see the problem...

@narfbg
Owner

OK, so I set $routing['directory'] to 'test', then I enable query strings and go to http://url/?d=blah. Line 112 in system/core/Router.php will set the routing directory to 'blah', no matter that I have set $routing['directory']. Same goes for classes and methods as well.
I don't see any checks in _set_routing() for if the directory, class or method are already set.

@marcosgdf

But that's only if you enable query strings... If you don't enable them, then you'll face the problem.

You set $routing['directory'] in the index.php file, then /system/core/CodeIgniter.php line 177 passes the array to _set_overrides, which does $this->set_directory($routing['directory']) /system/core/Router.php line 502.

Then it goes to _validate_request() (system/core/Router.php line 272) which is supposed to check if the controller exists.

@narfbg
Owner

... and it's exactly _validate_request() that will overwrite anything that was set using the $routes array.

@marcosgdf

So...?

I'm Spanish and my English is not that good.. so I'd appreciate if you can clarify what do you try to tell me...

@narfbg
Owner

I'm trying to tell you that _set_overrides() is supposed to be run after _set_routing().

What _set_routing() does is to trigger the logic that decides which directory/class/method should be run. It works on its own and doesn't take any overrides in mind.
_set_overrides() on the other hand is designed for one simple purpose in mind - to set hard-coded values, no matter what the router has decided to do before that.

@marcosgdf

OK. But if _set_overrides() is called AFTER _set_routing(), _validate_request() won't know the directory to search for the controller, and that's what is causing the problem.

@narfbg
Owner

If you've set $routing['directory'] - it will be set as the directory to include from, no matter what. It doesn't need validation.

@marcosgdf

Yes it does, in Router line 272, 278, 287.... That's the problem that I specified in bug #1076...

@narfbg
Owner

Now we're just repeating the same thing over and over again here.
I didn't write that and I don't want to argue, but I'm pretty sure that it is supposed to be this way ...

@philsturgeon @ericbarnes ?

@toopay

Agree with narf. @marcosgdf i think issue #1076 could be resolved by some mod_rewrite / htaccess tweak rather than routes, since subdomain however, was considered as different domain and ideally should be treated as two different application which shared Codeigniter system. But despite i encourage the way someone maintain their application across different domain like that, you could still use your own approach on issue #1076, with some rewrite rule like :

RewriteEngine On 
RewriteBase / 

RewriteCond %{HTTP_HOST} ^foo.domain.com [NC] 
RewriteCond %{REQUEST_FILENAME} !(foo)/ 
RewriteRule ^(.*)$ index.php/foo/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 

This way, some request to http://foo.domain.com/something/weird would be get response from method weird at controllers/foo/something.

@marcosgdf

That's a posibility, but I'm not creating any feature, I mean, I'm just fixing CodeIgniter's implementation of that feature, which doesn't work well.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2012
  1. @marcosgdf

    Fixed issue #1076

    marcosgdf authored
Commits on Mar 19, 2012
  1. @marcosgdf
Commits on May 23, 2012
  1. @marcosgdf
  2. @marcosgdf
  3. @marcosgdf

    Revert "Fixed issue #1353. Copied from develop branch"

    marcosgdf authored
    This reverts commit 6b8348637e0ccb9a44a1b5b822ce58f75135b0f0.
This page is out of date. Refresh to see the latest.
View
5 system/core/CodeIgniter.php
@@ -170,13 +170,14 @@
* ------------------------------------------------------
*/
$RTR =& load_class('Router', 'core');
- $RTR->_set_routing();
-
+
// Set any routing overrides that may exist in the main index file
if (isset($routing))
{
$RTR->_set_overrides($routing);
}
+
+ $RTR->_set_routing();
/*
* ------------------------------------------------------
View
6 system/core/Router.php
@@ -269,16 +269,16 @@ function _validate_request($segments)
}
// Does the requested controller exist in the root folder?
- if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
+ if (file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
return $segments;
}
// Is the controller in a sub-folder?
- if (is_dir(APPPATH.'controllers/'.$segments[0]))
+ if (is_dir(APPPATH.'controllers/'.$this->fetch_directory().$segments[0]))
{
// Set the directory and remove it from the segment array
- $this->set_directory($segments[0]);
+ $this->set_directory($this->fetch_directory().$segments[0]);
$segments = array_slice($segments, 1);
if (count($segments) > 0)
View
1  user_guide/changelog.html
@@ -89,6 +89,7 @@
<li>Fixed a bug (#726) - PDO put a 'dbname' argument in it's connection string regardless of the database platform in use, which made it impossible to use SQLite.</li>
<li>Fixed a bug - CI_DB_pdo_driver::affect_row was not being initialized properly with SELECT queries, cause it was relying on PDOStatement::rowCount().</li>
<li>Fixed a bug - CI_DB_pdo_result::num_rows() was not returning properly value with SELECT queries, cause it was relying on PDOStatement::rowCount().</li>
+ <li>Fixed a bug (#1076) - $routing['directory'] wasn't being recognized by CodeIgniter in some cases.</li>
</ul>
Something went wrong with that request. Please try again.