Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉维4中的球_Php_Laravel_Laravel 4 - Fatal编程技术网

Php 拉维4中的球

Php 拉维4中的球,php,laravel,laravel-4,Php,Laravel,Laravel 4,--对不起,这里是laravel noob,来自普通php 我使用的旧php全局文件有问题。我希望能够在所有视图中从函数调用数据 基本上,我有一个名为loggedInUser的类,我用$loggedInUser实例化了它,我可以调用一个对象,例如, $loggedInUser->user\u id 现在,我不知道怎么把它移过去。我不知道在哪里/如何定义信息。我试着在/app/filters.php(函数之前)中执行它,但这不起作用,在bootstrap/start.php中也不起作用,因为无法在

--对不起,这里是laravel noob,来自普通php

我使用的旧php全局文件有问题。我希望能够在所有视图中从函数调用数据

基本上,我有一个名为loggedInUser的类,我用$loggedInUser实例化了它,我可以调用一个对象,例如, $loggedInUser->user\u id

现在,我不知道怎么把它移过去。我不知道在哪里/如何定义信息。我试着在/app/filters.php(函数之前)中执行它,但这不起作用,在bootstrap/start.php中也不起作用,因为无法在那里调用Session::classes

我在filters.php中有这段代码,但它似乎没有使用类本身,但是我拉的每个东西,例如->user\u id,都是一个不应该是这样的类。我怎样才能使它成为一个物体呢?你知道我最好把代码放在哪里吗

App::singleton('loggedInUser', function(){
    $app = new stdClass;
    if (Auth::check()) {
        // Put your User object in $app->user
        //$app->user = Auth::User();
        $loggedInUser = new loggedInUser();
        $user_id = Session::get('uid');
        $app->email = DB::table('app_Users')->where('User_ID', '=', $user_id)->pluck('Email');
        $app->user_id = $user_id;
        $app->display_username = DB::table('app_Users')->where('User_ID', '=', $user_id)->pluck('Username');
        $app->clean_username = DB::table('app_Users')->where('User_ID', '=', $user_id)->pluck('Username_Clean');
        $app->isLogedin = TRUE;
    }
    else {
        $app->isLogedin = FALSE;
    }
    return $app;
});
$app = App::make('loggedInUser');
View::share('loggedInUser', $app);  

谢谢你的意见

这将是非常诚实的-如果它冒犯了您,我很抱歉-但是这里的编码逻辑有太多问题-很明显您不理解Laravel。我建议做一些教程,我个人推荐

您基本上不需要您编写的任何代码。你所需要的只是

View::share('loggedInUser', Auth::user());  
那么在你看来,

{{{ $loggedInUser->email }}}
{{{ $loggedInUser->display_username }}}
等等

有些人会说,您甚至不需要View::share()函数,只需在视图中执行以下操作:

{{{ Auth::user()->email }}}
{{{ Auth::user()->display_username }}}