quocvuongdn icon

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

quocvuongdn | PRO | 07/22/16 11:59:21 PM UTC | 0 ⭐ | 425 👁️ | Never ⏰ | []
PHP |

910 B

|

None

|

0 👍

/

0 👎

<?php 
 
class MY_Router extends CI_Router {
  
  public $suffix = 'Action';
 
  public function __construct($routing = NULL) {
    parent::__construct();
 
    log_message('info', 'MY _ Router Class Initialized');
  }
 
  /**
   * Set method name
   * Change 'method-name' to 'methodNameAction'
   *
   * @param string  $method Method name
   * @return  void
   */
  public function set_method($method)
  {
    $method_parts = explode('-', $method);
 
    if(count($method_parts) >= 2) {
      $build_name = '';
      for($i = 0; $i < count($method_parts); $i++) {
 
        if($i > 0){
          $build_name .= ucfirst($method_parts[$i]);
        } else {
          $build_name .= $method_parts[$i];
        }
      }
 
      
    } else {
      $build_name = $method;
    }
    
    $build_name = $build_name.$this->suffix;
 
    $this->method = isset($build_name) ? $build_name : $method;
  }
 
}

Comments