Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在模型-视图-控制器框架内动态更新url_Php_Url_Model View Controller - Fatal编程技术网

Php 在模型-视图-控制器框架内动态更新url

Php 在模型-视图-控制器框架内动态更新url,php,url,model-view-controller,Php,Url,Model View Controller,我自己做了一个MVC框架。我陷入了url更新的困境。这就是我尝试登录时发生的情况,例如: 当我按下login按钮时,URL如下所示:localhost/login\u controller/ 登录控制器将被调用并加载验证凭据的所需模型 模型将状态返回给控制器,控制器加载相应的视图。在我的例子中是profile.php url现在应该是这样的:localhost/profile/ $this->load->view(配置文件) 执行上述代码后,url保持不变localhost/Login\u Co

我自己做了一个MVC框架。我陷入了url更新的困境。这就是我尝试登录时发生的情况,例如:

  • 当我按下login按钮时,URL如下所示:localhost/login\u controller/
  • 登录控制器将被调用并加载验证凭据的所需模型
  • 模型将状态返回给控制器,控制器加载相应的视图。在我的例子中是profile.php
  • url现在应该是这样的:localhost/profile/
  • $this->load->view(配置文件)

    执行上述代码后,url保持不变localhost/Login\u Controller/

    有人能告诉我怎么修吗

    我从本教程中获得了设计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();
            }
        }
     }   
    
    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');
               }  
            }
        }
     }
    
    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
           } 
        }
     }   
    
    控制器/Login\u controller.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();
            }
        }
     }   
    
    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');
               }  
            }
        }
     }
    
    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
           } 
        }
     }   
    
    模型/自动登录模型

     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; 
           }
        }
     }  
    
    application/template.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();
            }
        }
     }   
    
    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');
               }  
            }
        }
     }
    
    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
           } 
        }
     }   
    

    希望这足够详细说明。

    执行该代码后,URL应该是什么样子?另外,我们可能需要查看
    view
    方法的定义才能理解您的意思。@halfer我已经添加了链接。在阅读了本教程之后,我以同样的方式设计了框架。我编辑了这篇文章,并给出了完整的细节,以使您理解。