TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Routes function (http://www.talkphp.com/advanced-php-programming/4089-routes-function.html)

Tanax 04-02-2009 02:25 PM

Routes function
 
Hi!

Like I said before, I'm quite into Framework at the moment.
Anyhow, something's wrong with my routes function, because.. it works GREAT when I'm on this url:

localhost/index.php/controller/index/
but not
localhost/index.php/controller/index

It has to end with a trailing slash, or else I get this:
Code:

Notice: Undefined index: 3 in C:\wamp\www\testproject\system\libraries\Router.php on line 33
Router.php:
PHP Code:

public function route()
    {
        
        if(
$this->uri['1'] == ''// If the first URI segment is blank
        
{
            
            
$default_controller TANAXIA_CORE::config_item('default_controller');
            
Tanaxia_Loader::controller($default_controller);
            
        }
        
        elseif(
$this->uri['2'] == '')
        {
            
            
Tanaxia_Loader::controller($this->uri['1']);
            
        }
        
        elseif(
$this->uri['3'] == '')
        {
            
            
Tanaxia_Loader::controller($this->uri['1'], $this->uri['2']);
            
        }
        
        else
        {
            
            
Tanaxia_Loader::controller($this->uri['1'], $this->uri['2'], $this->uri['3']);
            
        }
        
    } 

And the controller in Loader:
PHP Code:

    public function controller($controller$function NULL$params NULL)
    {
        
        if(!
file_exists(APPPATH 'controllers/' $controller EXT))
        {
            
            
TANAXIA_CORE::error('Could not locate the controller "' $controller '"');
            
        }
        
        include(
APPPATH 'controllers/' $controller EXT);
        
        
$name ucfirst($controller) . "Controller";
        
$class =& new $name();
        
        if(
$function === NULL)
        {
            
            return 
$class->index();
            
        }
        
        elseif(
$params !== NULL)
        {
            
            return 
$class->$function($params);
            
        }
        
        else
        {
            
            return 
$class->$function();
            
        }
        
    } 

Any suggestions on how to fix so I can get rid of that error?
Thanks

TheOnly92 04-03-2009 01:49 PM

Well, get rid of that error by setting the error_reporting level lower or use
PHP Code:

isset($this->uri['3']) && $this->uri['3'] == '' 

in the condition.

Tanax 04-03-2009 09:06 PM

Ahh, thanks! I solved it already by myself though, not sure if I'm using the best solution, but it got rid of the error, without lowering the error level, so I assume that's a good thing :-P


All times are GMT. The time now is 01:10 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0