![]() |
Adding get routes name feature - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Adding get routes name feature (/showthread.php?tid=67971) |
Adding get routes name feature - DuoS - 05-02-2017 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 ![]() RE: Adding get routes name feature - mt19 - 05-13-2017 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 RE: Adding get routes name feature - DuoS - 07-14-2017 (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 ![]() RE: Adding get routes name feature - ciadmin - 07-14-2017 Hmmm - what you ask for sounds like the URL helper ... https://www.codeigniter.com/user_guide/helpers/url_helper.html What are you looking for on top of that? RE: Adding get routes name feature - Wouter60 - 07-14-2017 Routes never refer to view files, but only to controller/method[/parameters]. RE: Adding get routes name feature - DuoS - 07-22-2017 (07-14-2017, 11:11 AM)ciadmin Wrote: Hmmm - what you ask for sounds like the URL helper ... https://www.codeigniter.com/user_guide/helpers/url_helper.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. ![]() RE: Adding get routes name feature - PaulD - 07-23-2017 If you are referring to only the current path, then you can get that using the URL segments https://www.codeigniter.com/user_guide/libraries/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/libraries/uri.html#CI_URI RE: Adding get routes name feature - jonathanq - 08-04-2017 I use routes in a controller better than laravel example: PHP Code: /** Please check my adds https://github.com/yonineitor/Dynamic-Routes |