久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CakePHP Auth 組件重定向問題

CakePHP Auth component redirect issue(CakePHP Auth 組件重定向問題)
本文介紹了CakePHP Auth 組件重定向問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我無法讓 Auth 組件在 CakePHP 1.2.6 應用程序中執行我想要的重定向.

I am having trouble getting the Auth component do the redirects I want in a CakePHP 1.2.6 app.

我有一個顯示在所有頁面上的登錄表單,我想將用戶保留在他登錄的頁面上.例如,如果他正在查看另一個用戶的個人資料,我想在登錄后將他留在那里,而不是將他重定向到 $this->Auth->loginRedirect 操作.此外,關于我的應用程序的另一件事是我沒有僅限經過身份驗證的訪問"頁面,每個人都可以訪問每個頁面,但如果您登錄,您可以獲得其他功能.

I have a login form that appears on all pages and I want to keep the user on the page he logs in on. For example, if he is viewing another user's profile, I want to keep him there after logging in, not redirect him to the $this->Auth->loginRedirect action. Also, another thing about my app is that I have no "authenticated access only" pages, every page is accessible to everyone, but if you're logged in you get additional features.

我從閱讀文檔中了解到我需要設置autoRedirect 為 false 以獲取要執行的 login() 函數中的代碼:

What I understood from reading the documentation is that I need to set autoRedirect to false to get the code in the login() function to be executed:

class UsersController extends AppController {    
    var $name = 'Users';
    var $helpers = array('Html', 'Form','Text');

    function beforeFilter() {
        $this->Auth->autoRedirect = false;
    }

    function login() {
        $this->redirect($this->referer());
    }

    function logout() {
        $this->redirect($this->Auth->logout());
    }

    /* [...] */
}

這目前破壞了我的身份驗證.我注意到(從日志中)如果我在登錄功能中保留重定向并將 autoRedirect 設置為 false,則 $this->data 中的密碼字段login() 函數顯示為空.

This currently breaks my authentication. I've noticed (from the logs) that if I leave the redirect in the login function and set autoRedirect to false, the password field in $this->data in the login() function appears as empty.

下面,我已經發布了與 Auth 組件相關的 AppController 的內容:

Below, I've posted the contents of AppController that relate to the Auth component:

public function beforeFilter() {

    $this->Auth->fields = array(
        'username' => 'email',             
        'password' => 'password'            
    );

    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');     
    $this->Auth->loginRedirect = array('controller' => 'usercars', 'action' => 'homepage');

    $this->allowAccess();

    // build wishlist if the user is logged in
    if ($currentUser = $this->Auth->user()) {
        $wishlists = $this->buildWishlist($currentUser);
        $this->set('wishlists', $wishlists);
    }

}

private function allowAccess() {
      if(in_array($this->name, /* all my controller names */)) {
          $this->Auth->allow('*');
      }
}

我似乎無法理解我做錯了什么.

I can't seem to understand what I'm doing wrong.

推薦答案

Add parent::beforeFilter();到用戶控制器中的 beforeFilter:

Add parent::beforeFilter(); to beforeFilter in the user controller:

function beforeFilter() {
    $this->Auth->autoRedirect = false;
    parent::beforeFilter();
}

您還可以將重定向替換為您的用戶控制器的登錄方法:

You can also replace the redirect with this to the login method of your user controller:

$this->redirect($this->Auth->redirect());

Auth->redirect() 返回用戶在被帶到登錄頁面或 Auth->loginRedirect 之前登陸的 url.

Auth->redirect() returns the url where the user landed before being taken to the login page or Auth->loginRedirect.

這篇關于CakePHP Auth 組件重定向問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 中文字幕人成人 | 天天看天天摸天天操 | 欧美一级免费看 | 国产一区二区精品在线观看 | 国产毛片av| 精品国产精品 | 欧美日韩高清免费 | 欧美 视频 | 国产一区二区三区在线看 | 在线播放国产一区二区三区 | 欧美日韩第一页 | 国产精品久久视频 | 日本不卡免费新一二三区 | 欧美日韩成人在线 | 男女爱爱福利视频 | 黄色一级电影在线观看 | 91av视频 | 国产精品久久99 | 一区二区三区四区国产 | 一区二区三区中文字幕 | 2021狠狠干 | 亚洲国产精品精华素 | 亚洲国产欧美日韩 | 精品亚洲91 | 欧洲一级黄| 亚洲视频二区 | 三级成人在线观看 | 看片地址 | 麻豆av在线免费观看 | 欧美一区二区三区精品 | 亚洲免费在线 | 国产精品无码永久免费888 | 欧美亚洲高清 | 欧洲亚洲精品久久久久 | 国产精品99精品久久免费 | 日韩在线国产 | 九九热在线观看视频 | 99re视频在线| 欧美一级免费看 | 91在线一区二区三区 | 日韩精品一区二区三区在线观看 |