0

MVC フレームワークを自作しました。URL 更新の時点で立ち往生しています。これは、たとえばログインしようとすると次のようになります。

  1. ログインボタンを押すと、URL は次のようになります: localhost/Login_controller/
  2. ログイン コントローラーが呼び出され、資格情報を認証するために必要なモデルが読み込まれます。
  3. モデルはステータスをコントローラーに返し、コントローラーはそれぞれのビューをロードします。私の場合、その profile.php.
  4. URL は次のようになります: localhost/profile/

$this->load->view(プロファイル);

上記のコード行を実行した後、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; 
       }
    }
 }  

アプリケーション/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
       } 
    }
 }   

これで詳しく説明できることを願っています。

4

0 に答える 0