Welcome Guest, Not a member yet? Register   Sign In
basic Helper get your defines routes list
#1

(This post was last modified: 10-24-2020, 11:15 PM by nc03061981.)

PHP Code:
function app_route_list()
    {
        
$routes = \Config\Services::routes();
        
$routes $routes->getRoutes();
        
        
$arrR = [];
        foreach (
$routes as $key => $val)
        {
            if (
is_string($val)) {
                
$arr explode('/'$key);
                
$cR  '';
                
$cM  '';
                foreach (
$arr as $ind => $item)
                {
                    if (
$ind == && $item != '/') {
                        
$cR $item;
                    } else if (
$item != '' && $item != '(.*)') {
                        
$cM $item;
                    }
                }
                if (
$cR != '') {
                    
$arrR[$cR][] = $cM;
                }
            } else {
                break;
            }
        }
        
        foreach (
$arrR as $key => $val)
        {
            
$arr = [];
            foreach (
$val as $item)
            {
                if (
$item != '') {
                    
$arr[] = $item;
                }
            }
            if (
count($arr)) {
                
$arrR[$key] = $arr;
            } else {
                
$arrR[$key] = '';
            }
        }
        
        return 
$arrR;
    }
    
    
/*
        Example Return :: 
        
        Array
        (
            [mining] => Array
                (
                    [0] => initblock
                    [1] => inittoken
                    [2] => firstblock
                    [3] => miningstart
                    [4] => miningelapsed
                    [5] => miningend
                    [6] => miningresult
                    [7] => validblock
                    [8] => ...
                )

            [register] => 
            [login] => 
            [logout] => 
            [encrypt] => 
            [decrypt] => 
            [records] => 
            [factory] => 
            [coin] => 
            [miner] => 
            [index] => 
            [buycoin] => 
            [sellcoin] => 
            [deposit] => 
            [withdraw] => 
            [validtoken] => 
            [...] => ...
        )
    */ 

Use for setting role by route and method

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#2

System routes return more than 4000 items ;-)

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#3

You should wrap your helper methods within a:

PHP Code:
/**
 * methodName ()
 * -----------------------------------------------------------------------
 */
if ( ! function_exists('methodName'))
{
    
/**
     * methodName ()
     * -------------------------------------------------------------------
     *
     * @return false
     */
    
function methodName()
    {

        return 
false;
    }


Like above.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

Thanks @InsiteFX

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#5

I use phpStorm so I have everything setup in temples for libraries, controllers all of them.

I just do a CTRL+J and select the template I want to use.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

I use notePad++
...
Get list routes and method for module set roles by route (not Editor)

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply




Theme © iAndrew 2016 - Forum software by © MyBB