尝试将控制器中生成的数据传递给视图。
在web.php中路由
Route::get('person', ['uses'=>'PersonController@index']);
控制器app / Http / Controllers / Person.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PersonController extends Controller
{
public function index()
{
$age = 35;
$height = 68;
$weight = 102;
// Calculate rest of BPX values
$BPXVals = [];
// Actual Weight
$BPXVals['actualWeight'] = $weight;
$BPXVals['actualWeight2'] = pow($weight, 2);
$BPXVals['actualWeight3'] = pow($weight, 3);
$BPXVals['weightLN'] = log($weight);
return View::make('person.index', ['BPXVals'=>$BPXVals]);
}
}
在Resources / Views / index.php中查看
<!doctype html>
<html>
<head>
</head>
<body>
{{ $BPXVals }}
</body>
</html>
收到以下错误:
ReflectionException in Container.php line 721:
Class App\Http\Controllers\PersonController does not exist
在定义路线或将路线链接到控制器和/或视图时,我做错了什么?
答案 0 :(得分:1)
尝试将app / Http / Controllers / Person.php更改为app / Http / Controllers / PersonController.php