TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-02-2009, 02:25 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default 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
__________________
Tanax is offline  
Reply With Quote
Old 04-03-2009, 01:49 PM   #2 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

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.
TheOnly92 is offline  
Reply With Quote
The Following User Says Thank You to TheOnly92 For This Useful Post:
Tanax (04-03-2009)
Old 04-03-2009, 09:06 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
The hello world contest Village Idiot The Lounge 9 01-07-2008 02:15 PM


All times are GMT. The time now is 02:53 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design