Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: admin
  5.  * Date: 19.07.2019
  6.  * Time: 10:28
  7.  */
  8.  
  9. namespace app\controller;
  10.  
  11. use app\models\Mops;
  12. use app\models\Siba;
  13. use app\models\Dachshund;
  14. use app\models\Labrador;
  15. use app\models\Rubber;
  16.  
  17. class controller
  18. {
  19.     public $view;
  20.  
  21.     public function __construct()
  22.     {
  23.         $this->view = new \app\views\View();
  24.     }
  25.     public function action_index(){
  26.         $this->view->generate( 'main_page.php');
  27.     }
  28.     public function action_command()
  29.     {
  30.         $routes = [
  31.             'mops' => Mops::class,
  32.             'sibainu' => Siba::class,
  33.             'dachshund' => Dachshund::class,
  34.             'labragor' => Labrador::class,
  35.             'rubber_dog' => Rubber::class
  36.         ];
  37.         $path = explode('/', $_POST['message']);
  38.  
  39.  
  40.         if(!empty($path[0])) $nameDog=$path[0];
  41.         if(isset($path[1])) $command=$path[1];
  42.  
  43.         if(isset($routes[$nameDog])){
  44.             $className = $routes[$nameDog];
  45.             $controller = new $className();
  46.  
  47.             method_exists($controller, $command)? $controller->$command(): Route::Error();
  48.  
  49.  
  50.         }
  51.     }
  52.     public static function Error()
  53.     {
  54.         echo json_encode('Oh, Error');
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement