Welcome Guest, Not a member yet? Register   Sign In
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?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB