【发布时间】:2013-09-26 02:30:10
【问题描述】:
我们有一个用旧 PHP 编写的业务后端,我们现在想尝试在 Laravel 中重做它,但在跳转时遇到了问题。
我已阅读大量教程,但似乎很难找到相关的教程。我们有一个充满记录的数据库,对于第一页,我们只想将它们全部打印到一个表中。
在常规 php 中,我们只是运行一个查询,将它放入一个数组并解析出数据。我尝试在视图控制器中这样做,但收效甚微......
现在只是尝试打印数据,表格格式可能略有偏差,路线和一切正常。
我不是 100% 相信一切都设置在理想的地方,或者这是否是理想的方式,但这就是我们所拥有的:
提前感谢您的帮助!
// Model:'PaymentInfo' - Database Table: 'payment_info'
Class PaymentInfo extends Eloquent
{
public $connection = 'main';
protected $table = 'payment_info';
protected $primaryKey = 'order_id';
public function getLastname()
{
return $this->lastname;
}
public function getFirstname()
{
return $this->firstname;
}
public function getBuyerEmail()
{
return $this->buyer_email;
}
public function getCountry()
{
return $this->country;
}
public function getMcGross()
{
return $this->mc_gross;
}
然后是控制器:
class AdminController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function getIndex()
{
return View::make('admin.index');
}
}
终于看到了:
@extends('master')
@section('content')
<div class="span 8 well">
<h4>Hello {{ (Auth::user()->username) }}</h4>
</div>
<div>
<div style="font-size:medium">
<h1>
<center>Recent Orders</center>
</h1>
</div>
<div id="highstyle1">
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<th>Order #</th>
<th>Buyer Name</th>
<th>Email Address</th>
<th>Country</th>
<th>Payment</th>
<th>Buyer Memo</th>
<th>Order Date</th>
<th>Status</th>
<th>Transaction ID</th>
</tr>
<tr>
{{ $order_id = PaymentInfo::all() }}
@foreach ($order_id as $order)
<td>{{ PaymentInfo::$order->lastname }}</td>
@endforeach
</tr>
</table>
</div>
</div>
@stop
【问题讨论】:
标签: laravel laravel-4 eloquent