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.

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器