在模型视图控制器框架内动态更新URL

时间:2013-10-27 21:22:26

标签: php url model-view-controller

我自己创建了一个MVC框架。我陷入了网址更新的困境。这是我尝试登录时发生的情况:

  1. 当我按下登录按钮时,URL如下所示:localhost / Login_controller /
  2. 调用登录控制器并加载验证凭据的所需模型。
  3. 模型将状态返回给控制器,控制器加载相应的视图。就我而言,它的profile.php。
  4. 网址现在应该如下所示:localhost / profile /
  5.   
        

    $这 - >负载>查看(配置文件);

      

    执行上面一行代码后,网址保持不变 localhost / Login_Controller /

    有人能告诉我如何解决它吗?

    我从本教程中获得了设计MVC的帮助。 MVC Tutorial that i studied

    应用/ router.php

    class router{
       private $registry;
       public function __construct($registry){
             $this->registry = $registry; 
       }   
       public function getController(){
           $url = $_GET['url'];
           if($contoller_path){
               include $controller_path;   // if controller exits the path will be included
               $url = new $url.Controller(); // instantiating the object for controller
               $url->auth_login();
            }
        }
     }   
    

    控制器/ Login_controller.php

    class Login_controller extends controller{
    
          public function __construct($registry){
             parent::_construct( $registry); 
          }   
          public function auth_login(){
           $url = $_GET['url'];
           $username = $_POST['username'];
           $password = $_POST['password'];
           if($model_path){
               include $_path;
               $this->registry->url = new $url.model();
               $status = $this->registry->{url->auth_login}($username, $password);
    
               if($status == 'success'){
    
                //HERE....
    // I want to change the url localhost/login_controller to localhost/profile/
    
                   $this->registry->template->show('profile');  
               }if($status == 'failure'){
                   $this->registry->template->show('index');
               }  
            }
        }
     }
    

    模型/ aut_login_hmodel

     class auth_login_model extends model{
    
      public function __construct($registry){
             parent::_construct( $registry); 
          } 
       public function auth_login($username, $password){
           //here is the code to query db and all..
    
           if($success){
               return $success;
           }else{
              return $failure; 
           }
        }
     }  
    

    应用/的template.php

    class template{
       private $registry;
       public function __construct($registry){
             $this->registry = $registry; 
       }   
       public function show($view){
    
           if(is_readable($view_path)){
               include $view_path;  // if view exists, it would load
    
           }else{
               include $index_path; // if view does not exists, index page loads
           } 
        }
     }   
    

    希望这足以详细阐述。

0 个答案:

没有答案