H4T3D

Create Controllers dynamically

Nov 30th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. function clean($string) {
  3.    $string = str_replace('-', '_', $string); // Replaces all spaces with hyphens.
  4.    return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
  5. }
  6.  
  7. $files = scandir(getcwd());
  8. //print_r($files);
  9.  
  10. for($i=2 ; $i<count($files) ;$i++){
  11. $con = explode('.', $files[$i]);
  12.  
  13. if($con[0] != "index123"){
  14.  
  15.  $func_name =  clean($con[0]);
  16.  
  17.  
  18.     echo ' public function '.$func_name.'()
  19.     {
  20.         $this->load->view("'.$con[0].'");
  21.     }
  22.     </br>';
  23.  
  24.  
  25. }
  26.  
  27.  
  28. }
  29.  
  30. ?>
Add Comment
Please, Sign In to add comment