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

#11
[eluser]bjk2007[/eluser]
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:
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:
Code:
'//foo/bar/bass'.  From url: /foo/bar/bass

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

#12
[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

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

#14
[eluser]bjk2007[/eluser]
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?

#15
[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

#16
[eluser]bjk2007[/eluser]
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.

PHP:
Code:
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

WITH VARIABLES:

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

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

#18
[eluser]bjk2007[/eluser]
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.

#19
[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.
Code:
<?php

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)
    {
        if(!isset($this->router->segments[1]))
        {
            return;
        }
        $start_segments = explode('/', $this->router->segments[1]);
        array_shift($this->router->segments);
        $this->router->segments = array_merge($start_segments, $this->router->segments);
        
        $i = 1;
        foreach ($this->router->segments as $val)
        {
            $this->router->segments[$i++] = $val;
        }
        unset($this->router->segments[0]);
        
        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.

#20
[eluser]Unknown[/eluser]
Hi everybody.

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

thanx!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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