duana1986
2014-01-06 21:12
浏览 31
已采纳

CakePhp问题:未找到类“登录”

I'm moving my app from codeigniter to cakephp. I have my first issue and I am not able to fix it...

In my controller FeedController, I'm calling this: Login::isLoggedInUser()

I have in model folder, the file login.php with this code:

<?php

App::uses('Login', 'AppModel');

class Login extends AppModel {

    public function __construct() {
        session_start();

        parent::__construct();
    }

    public static function authenticateUser() {
        $_SESSION['username'] = 'feeds.123';

        return $_SESSION['username'];
    }

    public static function isLoggedInUser() {
        if (isset($_SESSION['username']) && $_SESSION['username'] == 'feeds.123') {
            return true;
        }

        return false;
    }
}

I don't see what's wrong, my error is:

Error: Class 'Login' not found  
File: D:\wamp\www\app\Controller\FeedController.php 
Line: 12

Thanks for your help.

图片转代码服务由CSDN问答提供 功能建议

我正在将我的应用程序从codeigniter移动到cakephp。 我有我的第一个问题,我无法修复它...

在我的控制器FeedController中,我称之为: Login :: isLoggedInUser()

我在模型文件夹中,文件login.php带有以下代码:

 &lt;?php 
 
App:  :uses('Login','AppModel'); 
 
class Login extends AppModel {
 
 public function __construct(){
 session_start(); 
 
 parent :: __ construct(); 
}  
 
公共静态函数authenticateUser(){
 $ _SESSION ['username'] ='feeds.123'; 
 
返回$ _SESSION ['username']; 
} 
 
公共静态函数 isLoggedInUser(){
 if(isset($ _ SESSION ['username'])&amp;&amp; $ _SESSION ['username'] =='feeds.123'){
 return true; 
} 
 
 返回false; 
} 
} 
   
 
 

我看不出有什么问题,我的错误是:

 < 代码>错误:未找到类'登录'
文件:D:\ wamp \ www \ app \ Controller \ FeedController.php 
Line:12 
   
 
 

谢谢 你的帮助。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • dongxie2756 2014-01-06 21:25
    最佳回答

    There's a number of things that a wrong with the code you posted:

    1. App::uses should be of the format App::uses('ClassName', 'Package'); AppModel is not a package; it is a class. Packages pretty much just correspond to what folder to look in.

    2. You should be using the built-in Auth component for logging in, not writing your own logic. See the Auth tutorial: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html

    3. You should never be calling session_start or accessing $_SESSION directly. There are features in the framework for that sort of thing, so you should use them.

    4. You should avoid accessing session in your models. That logic should be in the controller.

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题