Using variables as the controller name for routes |
Hello, I have a POST request. For example
/admin/something/(:any) And I would like to use (:any) as a class variable. For example $routes->post('/admin/something/(:any)', 'admin/$1::methodname'); Using $1 does not work under any circumstance and it seems that this slash is being trimmed in the Router.php system file. How can I use it as a variable? Additionally, how could I also use the method as a variable after the double colons? :: For example: $routes->post('/admin/(:any)/(:any)', 'admin/$1::$2'); Thank you!
I’m pretty sure it’s not possible to do something like that. Do you have that much classes in your app that you really don’t want to type them in?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Hello and thanks! It seems the quote button doesn't work here but I'll do this instead...
"I’m pretty sure it’s not possible to do something like that. Do you have that much classes in your app that you really don’t want to type them in? " What it amounts to is dynamic flexibility without relying on a singular controller to do all the heavy lifting. If a single controller has to have 40 switches and load each and every library file (because for some reason I can't get $something = new library_file to work in CI4) it becomes very taxing in memory. Now if it's possible to load library files as they are needed, that would be different and much less of a burden however being able to do what I was explaining in the OP would give so much more power to codeigniter projects.
I don’t understand why you’re talking about a single controller that loads every library at once like it’s the only way to do it!
Create all the controllers you need, load only the library you need, then define your routes accordingly or just enable auto-route. Maybe you just need to read a little more of the user guide or some tutorials. Because CI4 doesn’t have the limitations you think it has.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
@eril46,
https://codeigniter.com/user_guide/incom...llers.html Quote:Important Note to Development Team: BaseController.php does not conform to the above restrictions?
(07-16-2021, 04:22 AM)John_Betong Wrote: @eril46, I think the user guide is wrong. I always have multiple uppercase letters in my controller, like in your example, and it's working fine.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |