• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controllers in Unlimited Nested Folders

Another issue to report. It appears that this new routing library is affecting the uri helper. The segment numbering seems to be offset by 1. For example a request for example.com/foo/bar/bass with this code:
echo "/".$this->uri->segment(1)."/".$this->uri->segment(2)."/".$this->uri->segment(3)."/".$this->uri->segment(4)."'.  From url: ".$this->uri->uri_string();

Returns this output:
'//foo/bar/bass'.  From url: /foo/bar/bass

Would someone please confirm this? If there is a problem then we can fix it.

[eluser]Peter Goodman[/eluser]
Hrm, I could see how that would happen, unfortunately I'll be leaving soon for the weekend, but I can take a look at it sunday night Smile

[eluser]Peter Goodman[/eluser]
Is the problem persisting?

Yeah. I'm still getting segments reported as one position greater than their true location. Are you witnessing this yourself or does yours work fine?

[eluser]Peter Goodman[/eluser]
Can do do a check for me:

a) do the segments report properly for controllers in no dir
b) how do the segments report for controllers in a nested dir
c) how do the segments report for a re-mapped route (configged through the routes.php file $route array)
d) how do the segments report for a route with variables passed in to the action

If these all report in the same way, that they are each off by one, then the fix should be simple. Smile

OK, here's the output I got. Note: I didn't do tests for re-mapped routes, I've never used them before and don't have too much time to figure out how they work right now. If you really need me to I can though.
SUMMARY: It appears this only applies to controllers in the root folder level. Passing variables makes no real difference.

echo "'/".$this->uri->segment(1)."/".$this->uri->segment(2)."/".$this->uri->segment(3)."/".$this->uri->segment(4)."/".$this->uri->segment(5)."/".$this->uri->segment(6)."'.  From url: ".$this->uri->uri_string();

Controller: /segcount.php
Request: http://example.com/segcount.php
Output: '//segcount////'. From url: /segcount

Controller: /level1/segcount.php
Request: http://example.com/level1/segcount.php
Output: '/level1/segcount////'. From url: /level1/segcount

Controller: /level1/level2/segcount.php
Request: http://example.com/level1/level2/segcount.php
Output: '/level1/level2/segcount////'. From url: /level1/level2/segcount


Controller: /segcount.php
Request: http://example.com/segcount/index/foo/bar.php
'//segcount/index/foo/bar/'. From url: /segcount/index/foo/bar

Controller: /level1/segcount.php
Request: http://example.com/level1/segcount/index/foo/bar.php
Output: '/level1/segcount/index/foo/bar/'. From url: /level1/segcount/index/foo/bar

Controller: /level1/level2/segcount.php
Request: http://example.com/level1/level2/segcoun...oo/bar.php
'/level1/level2/segcount/index/foo/bar/'. From url: /level1/level2/segcount/index/foo/bar

[eluser]Peter Goodman[/eluser]
Okay code updated. Tell me if it works as expected Smile

That works. Unless we find some other bugs then it would be nice to try to get this packaged into the next Code Igniter release.

[eluser]Jonathan Gordon[/eluser]
*EDIT* > Fixed a glitch when first segment wasn't set.

Hey all, I was messing with Peter's library and found that my URI segments still weren't working. I wrote my own URI library to go along with his to help fix the problem, so if you're still having problems, here's the code to fix it.

Set as MY_URI.php in your Libraries folder.

class MY_URI extends CI_URI {
    * URI Extension to fix segment gathering with Peter Goodman's Unlimited Subdirectory Router Library
    * Discussion thread at: http://ellislab.com/forums/viewthread/56100/
    * @author Jonathan Gordon
    * @copyright Copyright 2007 Jonathan Gordon, all rights reserved.
    function segment($n, $no_result = FALSE)
        $start_segments = explode('/', $this->router->segments[1]);
        $this->router->segments = array_merge($start_segments, $this->router->segments);
        $i = 1;
        foreach ($this->router->segments as $val)
            $this->router->segments[$i++] = $val;
        return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n];

    // --------------------------------------------------------------------


This is basically a reconstruction of the function already available, after exploding segment 1 and merging it back to the array. Nothing special, but in case anyone didn't want to poke through the source, here you have it.

Thanks Peter, I spent a couple days pissed at CI for its lack of subdirectory support, and your custom Library was really nice to have found.

If anyone has any problems with this, let me know.

Hi everybody.

What is the file that i have to change the code?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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