Error warning about incorrect code display if argument is not specified in URL

If I do not specify a value in the URL for Codeigniter, it will display a PHP error that has occurred saying that there is no argument to call the function. I do NOT want it to appear at all. If the URL has no arguments, it should just redirect to its index function. How can I prevent this?

For example, www.example.com/profile/id/45

would anyone guess and enter this "www.example.com/profile/id"

which will generate an error. How can I prevent this? I tried "if (! Isset ($ id))", but it generated an error before reaching this condition.

+3
source share
3

, :

function id($id=NULL)
{
 if ($id===NULL)
 {
  redirect....
 }

}
+5

:

$this->uri->segment(2); // gets 'id'
$this->uri->segment(3); // gets '45'

, :

http://codeigniter.com/user_guide/helpers/url_helper.html
+3

function id($id=0){
   if(there any record with $id being provided){
        //do something
}else{
       //id not provided,set to default values 0 and then
   show_404();
 }

}

There can be no id = 0 in any way, so it’s automatically turned on without redirection if the user enters the URL www.example.com/profile/id,

0
source

Source: https://habr.com/ru/post/1762214/


All Articles