quocvuongdn

#CI change 'method-name' -> 'methodNameAction' style

Jul 22nd, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. class MY_Router extends CI_Router {
  4.  
  5.   public $suffix = 'Action';
  6.  
  7.   public function __construct($routing = NULL) {
  8.     parent::__construct();
  9.  
  10.     log_message('info', 'MY _ Router Class Initialized');
  11.   }
  12.  
  13.   /**
  14.    * Set method name
  15.    * Change 'method-name' to 'methodNameAction'
  16.    *
  17.    * @param string  $method Method name
  18.    * @return  void
  19.    */
  20.   public function set_method($method)
  21.   {
  22.     $method_parts = explode('-', $method);
  23.  
  24.     if(count($method_parts) >= 2) {
  25.       $build_name = '';
  26.       for($i = 0; $i < count($method_parts); $i++) {
  27.  
  28.         if($i > 0){
  29.           $build_name .= ucfirst($method_parts[$i]);
  30.         } else {
  31.           $build_name .= $method_parts[$i];
  32.         }
  33.       }
  34.  
  35.      
  36.     } else {
  37.       $build_name = $method;
  38.     }
  39.    
  40.     $build_name = $build_name.$this->suffix;
  41.  
  42.     $this->method = isset($build_name) ? $build_name : $method;
  43.   }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment