Welcome Guest, Not a member yet? Register   Sign In
how get route name from current url?
#1

how get route name from current url?
Reply
#2

Try \CodeIgniter\Config\Services::router()->getMatchedRouteOptions()['as'] ?
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3
Thumbs Up 
(This post was last modified: 10-30-2023, 03:17 AM by asnanmtakim.)

(10-30-2023, 02:31 AM)ozornick Wrote: Try \CodeIgniter\Config\Services::router()->getMatchedRouteOptions()['as'] ?
Thank you very much for you help
Reply
#4

The method is not documented.
https://codeigniter4.github.io/CodeIgnit...uting.html

It may be changed in the future. So I recommend you create a function or method to call above code.
Then, even if the method is changed, you will need to update only the function/method code.
Reply
#5

Apparently in version CI 4.6.0 this was really changed. Please help me, how can I do this in the current version? 
Thank you
Reply
#6

All works. 

PHP Code:
// Route $routes->get('/', 'Home::index', ['as' => 'homepage']);
// in Home.php
    public function index(): string
    
{
        dd(Services::router()->getMatchedRouteOptions());
    }

// output
array:[
  
"as" => "homepage"

Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#7

Thank you for help!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB