View 将变量传递给视图
我想我可能发现了一只虫子。这就是我到目前为止所拥有的 Routes.phpView 将变量传递给视图,view,laravel,blade,View,Laravel,Blade,我想我可能发现了一只虫子。这就是我到目前为止所拥有的 Routes.php Route::get('/{user}/{char_dynasty}/{char_name}/selectedok', array( 'as' => 'char-profile-get', 'uses' => 'CharacterController@getDropDownList')); Route::post('/user/{user}/{char_dynasty}/{char
Route::get('/{user}/{char_dynasty}/{char_name}/selectedok', array(
'as' => 'char-profile-get',
'uses' => 'CharacterController@getDropDownList'));
Route::post('/user/{user}/{char_dynasty}/{char_name}/selectedok', array(
'as' => 'char-profile-post',
'uses' => 'CharacterController@postDropDownList'));
class CharacterController extends BaseController{
public function getDropDownList($user, $char_dynasty, $char_name)
{
if(Auth::check())
{
$user = Auth::user();
return View::make('layout.notification', array(
'user' => $user,
'char_dynasty' => $char_dynasty,
'char_name' => $char_name));
}
else
{
return App::abort(404);
}
}
public function postDropDownList()
{
if (Auth::check())
{
$user = Auth::user();
$char_name = User::find($user->id)->characters()->where('char_name', '=', Input::get('choose'))->first();
return Redirect::route('char-profile-get', array(Session::get('theuser'),
$char_name->char_dynasty,
$char_name->char_name));
}
}
}
CharacterController.php
Route::get('/{user}/{char_dynasty}/{char_name}/selectedok', array(
'as' => 'char-profile-get',
'uses' => 'CharacterController@getDropDownList'));
Route::post('/user/{user}/{char_dynasty}/{char_name}/selectedok', array(
'as' => 'char-profile-post',
'uses' => 'CharacterController@postDropDownList'));
class CharacterController extends BaseController{
public function getDropDownList($user, $char_dynasty, $char_name)
{
if(Auth::check())
{
$user = Auth::user();
return View::make('layout.notification', array(
'user' => $user,
'char_dynasty' => $char_dynasty,
'char_name' => $char_name));
}
else
{
return App::abort(404);
}
}
public function postDropDownList()
{
if (Auth::check())
{
$user = Auth::user();
$char_name = User::find($user->id)->characters()->where('char_name', '=', Input::get('choose'))->first();
return Redirect::route('char-profile-get', array(Session::get('theuser'),
$char_name->char_dynasty,
$char_name->char_name));
}
}
}
profile.blade.php(代码片段)
我更改为使用另一个变量填充下拉列表,以便能够从postDropDownList
执行数据库查询$char\u name
如果我在函数getDropDownList中这样做,var_dump($char_);var\u dump($char\u name)
string 'Spirescu' (length=8)
string 'Ion' (length=3)
关键是getDropDownList
中的参数具有正确的数据,但没有传输到视图中。我做错了什么?我不知道如何访问视图中的变量
我还尝试了returnview::make('layout.notification',compact('user','char\u devention','char\u name')代码>
或
我收到了同样的错误。或者,$data
未定义。这不是重复您昨天的问题吗:另外,您在哪里调用profile.blade.php
?它不在你的控制器的任何地方。可能的副本我已经解决了我昨天的问题,制作了一个新的控制器,并把功能放在那里。我这样做是因为我的getDropDownList的参数是空的。现在他们不是。但是发生了一些有趣的事情。一旦我将View::make('layout.notification'更改为View::make('layout.profile'layout.profile中使用的其他变量现在还没有定义。我该怎么办?$char_devention和$char_name现在可以工作了,但是其他变量还没有定义,这在以前是有效的。我不明白你的问题。你的问题和你最后的注释互相矛盾。如果它们现在可以工作,你做了什么?代码现在看起来怎么样?还有哪些变量?$c_name
?如何传递它们?
$data = array(
'user' => $user,
'char_dynasty' => $char_dynasty,
'char_name' => $char_name);
return View::make('layout.notification', $data);