2013-03-18 26 views
0

我開始瀏覽cakephp教程,我完全按照教程中所示覆制源代碼。Cakephp簡單身份驗證教程頁面不會重定向到當前頁面

我已經完成了博客教程,並且一切看起來都不錯,現在我進入了「簡單身份驗證和授權應用程序」(http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html)教程,但遇到了這個問題。

  1. 添加頁面加載罰款:

    「... /應用/ Webroot公司/ index.php文件/用戶/添加」

  2. 點擊提交後,它重定向我到這個網址(與額外的「用戶」字符串)和錯誤消息。

    「... /應用/ Webroot公司/ index.php文件/用戶/用戶/添加」

    Missing Method in UsersController 
    
    Error: The action Users is not defined in controller UsersController 
    
    Error: Create UsersController::Users() in file: app/Controller/UsersController.php. 
    
    class UsersController extends AppController { 
    
    
    public function Users() { 
    
    } 
    
    } 
    

讓我知道我應該開始檢查,謝謝。


AppController的

class AppController extends Controller { 
     public $components = array(
      'Session', 
      'Auth' => array(
       'loginRedirect' => array('controller' => 'posts', 'action' => 'index'), 
       'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'), 
       'authorize' => array('Controller') // Added this line 
      ) 
     ); 

     public function beforeFilter() { 
      $this->Auth->allow('index', 'view'); 
     } 

     public function isAuthorized($user) { 
     // Admin can access every action 
     if (isset($user['role']) && $user['role'] === 'admin') { 
      return true; 
     } 

     // Default deny 
     return false; 
     } 
    } 
+0

'/ app/webroot/index.php/Users/add'? 它可能是一個URL重寫問題:你是否遵循了URL重寫教程:http://book.cakephp.org/2.0/en/installation/url-rewriting.html – ptica 2013-03-18 19:04:39

+0

只是做了同樣的事情。 – MCHam 2013-03-19 15:02:11

回答

1

因爲我還不能發表評論,我在這裏告訴你,如果我知道編輯這個答案。

讓我看看你的AuthComponent配置AppController.php

編輯:

答案在下面的評論。 :)

+0

添加AppController – MCHam 2013-03-18 17:52:23

+0

請提供login.ctp文件或用於登錄的視圖文件的位置。 – 2013-03-18 18:44:17

+0

副本完全顯示在教程中:「http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html」。找一個「<?php echo $ this-> Session-> flash('auth');?>」和那段代碼就是我的login.ctp – MCHam 2013-03-19 16:58:07

相關問題