Php Laravel不加载我的视图
我正在开发一个以Laravel4.2(PHP5.4.25)为后端框架的web应用程序 当我从IDE运行索引页时,它会返回我期望的第一个视图,但当我从浏览器调用它时,它会显示以下错误:Php Laravel不加载我的视图,php,session,laravel,laravel-4,routing,Php,Session,Laravel,Laravel 4,Routing,我正在开发一个以Laravel4.2(PHP5.4.25)为后端框架的web应用程序 当我从IDE运行索引页时,它会返回我期望的第一个视图,但当我从浏览器调用它时,它会显示以下错误: substr() expects parameter 1 to be string, object given 这是一个错误屏幕 这是我的路由文件: <?php // Route to home page Route::get('/', array('as' => 'home', function
substr() expects parameter 1 to be string, object given
这是一个错误屏幕
这是我的路由文件:
<?php
// Route to home page
Route::get('/', array('as' => 'home', function () {
Log::debug('**** Load home page view');
if ( Auth::check() ) {
return View::make('dashboard');
} else {
return View::make('login');
}
}));
感谢您转储的错误,这在您的视图中不是问题,但在您的数据库连接中却是问题。数据库管理器无法分析您的数据库连接名称。这可能是由
Auth::check()
引起的。检查数据库是否正确配置。问题出在app/config/session.php
中
我已经用
'connection'=>DB::connection('mysql'),
替换为'connection'=>null,
,一切正常。在你看来,你是在使用Str::endsWith($something)
还是函数以($something)
结尾?@DavidBarker不,我的视图是空的。很难说有什么错。当您从IDE运行时,它是否显示此空登录页?您在浏览器中启动的url是什么?您是否只有login.php
文件,或者可能还有login.blade.php
?@MarcinNabiałek当我从IDE运行index.php时,它会在控制台中返回HTML。我从浏览器调用的url为:。我只有login.php
。恐怕另一段代码中有错误。如果你把它放在这个路径中,而不是放在任何模板中,返回'test'代码>?我假设你也会有这个错误,所以你可能会在你的代码中修改其他东西。我已经开发并运行了很多使用DB的单元测试。现在,我尝试以这种方式更改我的路由:route::get('/',array('as'=>'home',function(){return View::make('login');}))代码>但是当我调用索引页时,它返回相同的错误。我没有看到你所有的代码,但我能告诉你的是有什么东西试图攻击你的数据库,可能是另一个包?我已经检查过了,这不是DB问题。即使您将无效的连接数据放入数据库中,非常奇怪的Auth::check()
也不会引发任何异常。请检查完整的堆栈列表,通常在列表的下方可以看出哪个类正在执行此操作。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
</head>
<body>
</body>
</html>
<?php
return array(
/*
|--------------------------------------------------------------------------
| Default Session Driver
|--------------------------------------------------------------------------
|
| This option controls the default session "driver" that will be used on
| requests. By default, we will use the lightweight native driver but
| you may specify any of the other wonderful drivers provided here.
|
| Supported: "file", "cookie", "database", "apc",
| "memcached", "redis", "array"
|
*/
'driver' => 'database',
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 120,
'expire_on_close' => false,
/*
|--------------------------------------------------------------------------
| Session File Location
|--------------------------------------------------------------------------
|
| When using the native session driver, we need a location where session
| files may be stored. A default has been set for you but a different
| location may be specified. This is only needed for file sessions.
|
*/
'files' => storage_path().'/sessions',
/*
|--------------------------------------------------------------------------
| Session Database Connection
|--------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/
'connection' => DB::connection('mysql'),
/*
|--------------------------------------------------------------------------
| Session Database Table
|--------------------------------------------------------------------------
|
| When using the "database" session driver, you may specify the table we
| should use to manage the sessions. Of course, a sensible default is
| provided for you; however, you are free to change this as needed.
|
*/
'table' => 'sessions',
/*
|--------------------------------------------------------------------------
| Session Sweeping Lottery
|--------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/
'lottery' => array(2, 100),
/*
|--------------------------------------------------------------------------
| Session Cookie Name
|--------------------------------------------------------------------------
|
| Here you may change the name of the cookie used to identify a session
| instance by ID. The name specified here will get used every time a
| new session cookie is created by the framework for every driver.
|
*/
'cookie' => 'laravel_session',
/*
|--------------------------------------------------------------------------
| Session Cookie Path
|--------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application but you are free to change this when necessary.
|
*/
'path' => '/',
/*
|--------------------------------------------------------------------------
| Session Cookie Domain
|--------------------------------------------------------------------------
|
| Here you may change the domain of the cookie used to identify a session
| in your application. This will determine which domains the cookie is
| available to in your application. A sensible default has been set.
|
*/
'domain' => null,
/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/
'secure' => false,
);