0

我自己做了一个 MVC 框架。我被困在网址更新点。这就是我尝试登录时发生的情况,例如:

  1. 当我按下登录按钮时,URL 如下所示:localhost/Login_controller/
  2. 登录控制器被调用并加载验证凭据所需的模型。
  3. 模型将状态返回给控制器,控制器加载相应的视图。在我的例子中,它的 profile.php。
  4. url 现在应该是这样的:localhost/profile/

$this->load->view(profile);

执行上面这行代码后,url 还是一样的localhost/Login_Controller/

谁能告诉我如何解决它?

我从本教程中获得了设计 MVC 的帮助。我学习的 MVC 教程

应用程序/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; 
       }
    }
 }  

应用程序/模板.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
       } 
    }
 }   

希望这足以详细说明。

4

0 回答 0