这可能是一个愚蠢的问题,但我被困住了..
我基本上想在 laravel 中运行一个简单的选择查询,并在数据库结果中显示单行的结果。
我是 php 和 laravel 的新手,所以尝试在其中使用模型来挂起 MVC。
以下是我所做的。路线
Route::get('groupprofile/(:any)',array('uses'=>'groups@profile'));
控制器 - groups.php
class Groups_Controller extends Base_Controller {
public $restful=true;
public function get_profile($groupName){
$groups=new Groups();
$groupInfo=$groups->getGroupInfo($groupName);
return View::make('groups.profile.groupprofile')->with('groupInfo',$groupInfo);
}
}
模型 - groups.php
class Groups{
public function getGroupInfo($name){
return DB::query('select * from Groups where name=?',array($name));
}
}
查看 - groupprofile.blade.php
@layout('layouts.default')
@section('content')
<h1>This is a profile page for a group.</h1>
@foreach ($groupInfo -> results as $info)
<br />Here I want to display all columns e.g. name, philosophy, founder name etc.
<br />$info->Description
@endforeach
<br />Testing end
@endsection
有人可以指导我该怎么做吗?我无法理解如何使用刀片在视图中显示传递的结果集中的数据。
还是我这样做的方法是错误的?我更喜欢编写查询,所以不使用 Eloquent 或 fluent 查询构建器。