Welcome Guest, Not a member yet? Register   Sign In
Adding get routes name feature
#1
Smile 

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 Smile
Reply
#2

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;
$this->router->method


For example, if you have a default_controller and you connect to page "/", then
Code:
$this->router->class == default_controller
$this->router->method == index
Reply
#3

(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:

PHP Code:
$this->router->class;
$this->router->method


For example, if you have a default_controller and you connect to page "/", then
Code:
$this->router->class == default_controller
$this->router->method == index

this is not what i'm asking Smile
Reply
#4

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?
Reply
#5

Routes never refer to view files, but only to controller/method[/parameters].
Reply
#6

(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.html

What are you looking for on top of that?
No url helper nothing to do with this issue. Smile
(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. Sad
Reply
#7

(This post was last modified: 07-23-2017, 01:48 AM by PaulD.)

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();
This gets the actual path? You could use:
Code:
ruri_string()

For
Code:
Request::route()->getName()
This gets the route name used in the URI? You could use:
Code:
uri_string();

https://www.codeigniter.com/user_guide/l...tml#CI_URI
Reply
#8

(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:
/**
 * @route:product
 */
Class ProductController extends CI_Controller{
 
/**
 * @route:{post}insert
 */
 
function insert()
 {
   
//output is method post slug: product/insert
 
}



Please check my adds https://github.com/yonineitor/Dynamic-Routes
Reply




Theme © iAndrew 2016 - Forum software by © MyBB