Welcome Guest, Not a member yet? Register   Sign In
Routing with parametars problem
#1

Hi,
I asked this on stackoverflow but decided that this is better place to ask for help, so my problem is this:
When I need to take parameter from URI I just can't make my route works.
So this is what I have in route.php
Code:
$routes->add('admin', 'Admin/Login::index');
$routes->add('admin/login', 'Admin/Login::login');
$routes->add('admin/gUP', 'Admin/AdminGlavni::g_obrada');
$routes->add('admin/cam', 'Admin/AdminGlavni::cam_prikaz');
$routes->add('admin/cam/edit/(:any)', 'Admin/AdminGlavni::cam_edit_show/$1');
but this is not working (all other routes works as they should)
Code:
$routes->add('admin/cam/edit/(:any)', 'Admin/AdminGlavni::cam_edit_show/$1');
When I try to reach mydmain.com/admin/cam/edit/1 I get:
Quote:404 - File Not Found
Controller or its method is not found: \App\Controllers\Admin::index
and cam_edit_show in AdminGlavni Class is defined like this:
Code:
public function cam_edit_show($id) {
                ......

            }
What is wrong whit my route? Please help.


In meant time I got suggestion to disable autoRoute but that didn't help at all.
Reply
#2

Slash in handler namespace is an error.

@kenji It seems to me that an exception should be thrown for invalid slashes in the namespace of the route handler.
Reply
#3

(This post was last modified: 04-08-2022, 08:28 AM by Didytz.)

(04-08-2022, 07:35 AM)iRedds Wrote: Slash in handler namespace is an error.

@kenji It seems to me that an exception should be thrown for invalid slashes in the namespace of the route handler.
Hi and tnx for reply, but could you tell me exactly what is problem with slash? It should not be there at all or it should be other kind of slash (backslash?)
Sorry if this is stupid question, but I compare my route with CI 4 official tutorial / example and everything looks the same just changed names of URI and controler... Huh

I mean this looks the same as my route, and this is from https://codeigniter.com/user_guide/incom...uting.html
Code:
$routes->add('product/(:any)', 'Catalog::productLookup/$1');
Reply
#4

The namespace uses a backslash.
$routes->add('product/(:any)', 'Namespace\Catalog::productLookup/$1');

https://codeigniter.com/user_guide/incom...aceholders
Reply
#5

(04-08-2022, 08:39 AM)iRedds Wrote: The namespace uses a backslash.
$routes->add('product/(:any)', 'Namespace\Catalog::productLookup/$1');

https://codeigniter.com/user_guide/incom...aceholders

O M G, I am official retarded for missing this Confused

Tnx a lot for pointing out this stupid mistake. Now it is working yeee

But what is not now clear to me is why my other routes works with wrong slash?
If you look my example form first post you will see that I have all wrong slashes but only one with parameter really throw error, and that is why I didn't notice it before. But still why other routes works?
Reply
#6

@iRedds I agree with you.
I've sent a PR: https://github.com/codeigniter4/CodeIgniter4/pull/5885
Reply
#7

(04-08-2022, 08:44 AM)Didytz Wrote: But what is not now clear to me is why my other routes works with wrong slash?
If you look my example form first post you will see that I have all wrong slashes but only one with parameter really throw error, and that is why I didn't notice it before. But still why other routes works?

[Image: 5ydyeb.jpg]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB