Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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
Laravel PHP类没有';t显示阵列数据_Php_Laravel 4 - Fatal编程技术网

Laravel PHP类没有';t显示阵列数据

Laravel PHP类没有';t显示阵列数据,php,laravel-4,Php,Laravel 4,我目前正在学习创建LaravelPHP控制器、视图和路由的教程。这是我的密码: Authors2.php(控制器) index.php(视图) 电流输出 Authors2 Home Page Authors2 Home Page Andrew Perkins 28 California PHP 所需输出 Authors2 Home Page Authors2 Home Page Andrew Perkins 28 California PHP 请帮助我,以便我能够理解为什么php数据没

我目前正在学习创建LaravelPHP控制器、视图和路由的教程。这是我的密码:

Authors2.php(控制器)

index.php(视图)

电流输出

Authors2 Home Page
Authors2 Home Page
Andrew Perkins
28
California
PHP
所需输出

Authors2 Home Page
Authors2 Home Page
Andrew Perkins
28
California
PHP

请帮助我,以便我能够理解为什么php数据没有正确显示在标题下。谢谢大家!

您必须像这样向视图传递数据:

$view = View::make('authors2.index', array('name'=>'Andrew Perkins'))
        ->with('age', '28')
        ->with('location', 'California')
        ->with('specialty', 'PHP);
return View::make('authors2.index', array(
    'name' => 'Andrew Perkins',
    'age' => 28,
    'location' => 'California',
    'specialty' => 'PHP'
));
$name = 'Andrew Perkins';
$age = 28;
$location = 'California';
$specialty = 'PHP';

return View::make('authors2.index', compact('name', 'age', 'location', 'specialty'));
或者像这样:

$view = View::make('authors2.index', array('name'=>'Andrew Perkins'))
        ->with('age', '28')
        ->with('location', 'California')
        ->with('specialty', 'PHP);
return View::make('authors2.index', array(
    'name' => 'Andrew Perkins',
    'age' => 28,
    'location' => 'California',
    'specialty' => 'PHP'
));
$name = 'Andrew Perkins';
$age = 28;
$location = 'California';
$specialty = 'PHP';

return View::make('authors2.index', compact('name', 'age', 'location', 'specialty'));
或者像这样:

$view = View::make('authors2.index', array('name'=>'Andrew Perkins'))
        ->with('age', '28')
        ->with('location', 'California')
        ->with('specialty', 'PHP);
return View::make('authors2.index', array(
    'name' => 'Andrew Perkins',
    'age' => 28,
    'location' => 'California',
    'specialty' => 'PHP'
));
$name = 'Andrew Perkins';
$age = 28;
$location = 'California';
$specialty = 'PHP';

return View::make('authors2.index', compact('name', 'age', 'location', 'specialty'));
或者,使用与上述相同的变量:

return View::make('authors2.index')->with(compact('name', 'age', 'location', 'specialty'));
或者,您也可以这样做:

$view = View::make('authors2.index');
$name = 'Andrew Perkins';
$view->with(compact('name'));
$view->with('age', 28);
return $view;

我只是试着使用你的代码,但它仍然没有出现。可能是因为变量定义不正确,或者可能是空的吗?@JeffP。为什么不定义或不为空?您的代码正在向视图传递静态字符串,而不是变量。我实际上已经找出了问题所在。代码是正确的,但我的index.php位于错误的文件位置。谢谢你的帮助!您正在使用四种不同的方式向视图添加数据,包括两种不起作用的方式(其中一种将视图对象视为数组)。到底为什么?!我一直在关注一个在线教程,所以Laravel对我来说还是个新手。