Welcome Guest, Not a member yet? Register   Sign In
I am sick of bad CodeIgniter's URL errors handling. I am going to Laravel
#1

[eluser]term25[/eluser]
Don't get me wrong but handling URL errors in CodeIgniter is pretty bad.

E.g. if I have an URL:

Code:
http://localhost/article/154
Where 154 is $id of the article in db and a controller article looks like e.g.:

Code:
function index ($id = '')
{

// some code here

}

Now, when I type something like:

Code:
http://localhost/article/154dsdead34
I get an error because that id is not in my db. But, the php errors are shown on the page and the whole page is messedd up.

Instead I need a redirect to my controller called custom404 that can handle this (or if it is for some reason not possible at least a direct redirect('/'); to the homepage)

The same fix for variants like (to big $id number or not found in db):

Code:
http://localhost/article/3004534534534234600234
or (other parameters)

Code:
http://localhost/article/154/something/derer/asdasd


So, to fix that I need to use something like this in top of my controller function before other code:

Code:
if ( ! preg_match("~^article/\d+$~", $this->uri->uri_string())) {
    redirect('/');
}

and the routes settings like:

Code:
$route['article/(:any)'] = 'article/$1';

btw. this is not working:

Code:
$route['article/(:num)'] = 'article/$1';

Why the develers didn't do something like :

Code:
$route['article/(:any)(:stop,'/')'] = 'article/$1';

to stop acepting other parameters and redirect to homepage or something?

I am really upset from how difficult is to check and secure urls in Codeigniter ;(

If somebody knows about some better way of dealing with urls and routes in CI, let me know.

If I didn't find some way how to ease this url handling I will leave CI and go to Laravel or some other php framework that can do it better.

Thanks in advance.


Messages In This Thread
I am sick of bad CodeIgniter's URL errors handling. I am going to Laravel - by El Forum - 11-07-2012, 04:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB