Welcome Guest, Not a member yet? Register   Sign In
how do I prevent error display if missing argument in URL?
#1

[eluser]netrox[/eluser]
I noticed that if I have this URL like this

www.example.com/profile/id/4

it will display the profile of 4.

But if someone enters with this URL

www.example.com/profile/id

Where id function is missing an argument, it generates an error. I don't want that error displayed at all. I tried "(!isset($id))" condition but it generated the error before it could reach that condition.

How do I stop that? And redirect the page back to the index function of the given class?
#2

[eluser]Joseph Wensley[/eluser]
You can try giving it a default, use something like

Code:
function id($id = NULL)
{
    if($id === NULL){
        //redirect
    }
}
#3

[eluser]netrox[/eluser]
Thank you! That worked. Smile
#4

[eluser]BandonRandon[/eluser]
I know this is a little bit of an older post but I am using CI 2.0 and found this method to be simpler. This was the first post I found when searching how to do this so I thought I whould share how I'm doing it.
Code:
public function my_function($id='') //set the field here so it won't return false
    {    
        if($id =='') // if it's empty
        {
            //redirect or show content if empty here
        }
    }

Hope this helps




Theme © iAndrew 2016 - Forum software by © MyBB