Laravel不把我的班级当作班级

时间:2014-01-16 08:29:56

标签: php class laravel laravel-4 syntax-error

我收到的错误消息:

enter image description here

我的设置:

我在classes文件夹中创建了一个app文件夹,并在Alert.php内创建了app\classes
app\start\global.php中,代码是这样的:

ClassLoader::addDirectories(array(
    app_path().'/commands',
    app_path().'/controllers',
    app_path().'/models',
    app_path().'/database/seeds',
    app_path().'/classes', // This line is the one I've added.
));

composer.joson

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/classes"
    ]

在此之后我跑了composer dump-autoload 我在'Alert'=>'Alert'中的aliases数组中添加了app\config\app.php 我的班级app\classes\Alert.php

<?php
class Alert {
    static function new($type, $message){
        if(Session::has("alert_type") && Session::has("alert_message")) {
            $alert_type = Session::get("alert_type");
            $alert_message = Session::get("alert_message");
        } else {
            $alert_type = array();
            $alert_message = array();
        }
        $alert_type[] = $type;
        $alert_message[] = $message;
        Session::flash("alert_type", $alert_type);
        Session::flash("alert_message", $alert_message);
    }
}

filters.php

Route::filter('auth', function()
{
    if (Auth::guest()) {
        $alert_type = "danger";
        $alert_message = "<strong>Error: </strong>You need to sign in before continue.";
        Alert::new($alert_type, $alert_message);
        return Redirect::intended('/');
    }
});

1 个答案:

答案 0 :(得分:3)

new是PHP中的reserved keyword。使用静态方法的其他名称,你会没事的。