• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debug Bar feature: Change Matched Route Params with variables name & values

#1
This example below using ReflectionMethod class (my self version):

PHP Code:
   <?php

        $router 
Config\Services::router();
 
       
        $className 
$router->controllerName();
 
       $methodName $router->methodName();
 
       $params $router->params();

 
       $method = new ReflectionMethod($className$methodName);

 
       foreach$method->getParameters() as $key => $param )
 
       {
 
           $value = isset($params[$key]) ? $params[$key] : 'null'// 'null' or $param->getDefaultValue()
 
           
            echo 
'$' $param->getName() . ' => ' $value '<br>'// or using table
 
       
   
PHP: 7.0.5

Controller:

PHP Code:
   <?php namespace App\Controllers;

 
   class Products extends CodeIgniter\Controller {

 
       public function shoes($brand$id)
 
       {
 
           echo $brand;
 
           echo $id;
 
       }
 
       
    
}
 
    

URL:

   
Code:
example.com/products/shoes/penguin/13

    
Before (Debug Bar):

Code:
   Routes
       Matched Route
           Directory  :    
           Controller : Products
           Method     : shoes
           Params     : array(
                           [0] => penguin
                           [1] => 13
                        )

Expected output (Debug Bar):

Code:
   Routes
       Matched Route
           Directory  :    
           Controller : Products
           Method     : shoes
           Params     : $brand => penguin
                        $id => 13
Reply

#2
Looks pretty good to me. Care to work it up into a pull request?
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.