Adding get routes name feature |
Hi, Ci devs.
I tried to get routes name in view files to make urls. but no success due to CI not offering that kind of feature yet. every time clients change the routes names. they have to go through view files and change routes names in urls manually. its a bit of pain. I think it's a great feature to have in CI. Laravel have this feature builtin. Code: Route::getCurrentRoute()->getPath(); Code: Request::route()->getName() But I persoally dont like laravel. its very bloated and slow. I'm not a expert to do this kind of modification into the CI core. So I'm requesting this feature from CI devs. Kindly concider adding this feature. Thanks for hard work
I don't exactly understand what you are trying to achieve, however to get the current method and class you can do something like this:
PHP Code: $this->router->class; For example, if you have a default_controller and you connect to page "/", then Code: $this->router->class == default_controller (05-13-2017, 03:50 AM)mt19 Wrote: I don't exactly understand what you are trying to achieve, however to get the current method and class you can do something like this: this is not what i'm asking
Hmmm - what you ask for sounds like the URL helper ... https://www.codeigniter.com/user_guide/h...elper.html
What are you looking for on top of that?
Routes never refer to view files, but only to controller/method[/parameters].
(07-14-2017, 11:11 AM)ciadmin Wrote: Hmmm - what you ask for sounds like the URL helper ... https://www.codeigniter.com/user_guide/h...elper.htmlNo url helper nothing to do with this issue. (07-14-2017, 01:20 PM)Wouter60 Wrote: Routes never refer to view files, but only to controller/method[/parameters]. Yeah! thats the issue. its pain in the back when going through all the view files and change routes url segements in urls.
If you are referring to only the current path, then you can get that using the URL segments
https://www.codeigniter.com/user_guide/l...s/uri.html However, if users are changing the route names, then this will not help with things like your main navs, or links to other pages. How I would do this is to have your page details with an additional column, like page_url. You can auto generate this from the title (checking for uniqueness on creation of course) or have your users input their url manually. Either way, you can then have an option to have the user change the url with just a normal form post on some sort of admin screen. When showing the page, the page controller would decode the url to a page id. Or when creating navs, your controller would collect all the relevant urls for a foreach. I would never normally allow a user to define routes. That seems to be a recipe for breaking the site. Best wishes, Paul. PS I have not used laravel for a very long time but I think... For Code: Route::getCurrentRoute()->getPath(); Code: ruri_string() For Code: Request::route()->getName() Code: uri_string(); https://www.codeigniter.com/user_guide/l...tml#CI_URI
08-04-2017, 04:39 PM
(This post was last modified: 08-04-2017, 04:39 PM by jonathanq. Edit Reason: add class php code )
I use routes in a controller better than laravel
example: PHP Code: /** Please check my adds https://github.com/yonineitor/Dynamic-Routes |
Welcome Guest, Not a member yet? Register Sign In |