-
anuragk
Junior Member
-
Posts: 28
Threads: 6
Joined: Apr 2023
Reputation:
0
05-02-2023, 07:00 AM
(This post was last modified: 05-02-2023, 07:00 AM by anuragk.)
if I use
Code: $routes->post('login', 'Admin::do_login');
everything works as expected
but when I use
Code: $routes->match(['get', 'post'], 'login', [Admin::class, 'do_login']);
I get an error
404 Controller or its method is not found: \Config\Admin::do_login
am I doing anything wrong?
The class name is Admin and the method name is do_login
The controller file name is Admin.php
-
anuragk
Junior Member
-
Posts: 28
Threads: 6
Joined: Apr 2023
Reputation:
0
(05-02-2023, 07:09 AM)iRedds Wrote: Specify a class name with a namespace.
can you explain how and why? i am new to this
because on the other hand, this works fine
Code: $routes->match(['get', 'post'], 'appointment', [Appointment::class, 'appointmentForm']);
-
iRedds
Senior Member
-
Posts: 662
Threads: 36
Joined: Apr 2019
Reputation:
45
What are you new to? In php?
In the first example, the handler is specified as a string. In this case, the class will be checked for the existence of a namespace, and if it is not found, the default namespace will be added.
In the second example, you specify the handler as a string, where you declare the class name directly. If you don't specify a namespace or don't import, the current namespace will be used.
Current namespace is Config.
PHP Code: namespace Config;
use Namespace\Example2;
$routes->get('example1', [Example1::class, 'index']); // \Config\Example1 $routes->get('example2', [Example2::class, 'index']); // \Namespace\Example2 $routes->get('example3', ['\Namespace\Example3', 'index']); // \Namespace\Example3
$routes->get('example4', '\Namespace\Example4::index'); // \Namespace\Example4 $routes->get('example5', 'Namespace\Example5::index'); // \App\Controllers\Namespace\Example5
-
kenjis
Administrator
-
Posts: 3,669
Threads: 96
Joined: Oct 2014
Reputation:
229
-
anuragk
Junior Member
-
Posts: 28
Threads: 6
Joined: Apr 2023
Reputation:
0
(05-02-2023, 03:42 PM)iRedds Wrote: What are you new to? In php?
In the first example, the handler is specified as a string. In this case, the class will be checked for the existence of a namespace, and if it is not found, the default namespace will be added.
In the second example, you specify the handler as a string, where you declare the class name directly. If you don't specify a namespace or don't import, the current namespace will be used.
Current namespace is Config.
PHP Code: namespace Config;
use Namespace\Example2;
$routes->get('example1', [Example1::class, 'index']); // \Config\Example1 $routes->get('example2', [Example2::class, 'index']); // \Namespace\Example2 $routes->get('example3', ['\Namespace\Example3', 'index']); // \Namespace\Example3
$routes->get('example4', '\Namespace\Example4::index'); // \Namespace\Example4 $routes->get('example5', 'Namespace\Example5::index'); // \App\Controllers\Namespace\Example5
Thank you for explaining in such a manner.
the problem is solved
|