Using variables as the controller name for routes |
(07-16-2021, 04:22 AM)John_Betong Wrote: @eril46,Hi! 1) BaseController is an abstract controller class. Being such, it cannot be used for routing purposes, so basically it's exempted from the restrictions. 2) If you're using the auto-routing feature, this quote MUST be followed strictly. 3) If you are instead defining each route explicitly, no need to follow this but we use and recommend the PascalCase naming convention (actually used for all classes in the framework). (06-11-2021, 11:51 AM)eri146 Wrote: Hello, I have a POST request. For example In theory, this is workable BUT NOT recommended. This practice can pose a lot of complications in the future. Foremost, you have to make sure all possible combinations are available classes and methods, otherwise you have to devise your own failover. Simply do not do this.
To use (:any) as a class variable in your route, you can modify your code as follows:
$routes->post('/admin/something/(:any)', 'Admin::$1'); This will allow you to use the captured value of (:any) as a variable in your class name. Additionally, to use the method as a variable after the double colons (: ![]() $routes->post('/admin/(:any)/(:any)', 'Admin::$1::$2'); This will allow you to use the first captured value as the class name and the second captured value as the method name. I hope this helps! |
Welcome Guest, Not a member yet? Register Sign In |