2

我们有一个用旧 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
4

1 回答 1

3

从您的视图中删除它,因为它不能这样工作:

{{ $order_id = PaymentInfo::all() }}

这可能是您的新控制器:

class AdminController extends BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function getIndex()
    {
        $order_id = PaymentInfo::all();

        return View::make('admin.index')->with('order_id', $order_id);
    }

}

你也认为:

@foreach ($order_id as $order)
    <td>{{ $order->lastname }}</td>
@endforeach

而且您不需要模型中的所有这些 get() 方法,只需摆脱它们,仍然$order->lastname可以正常工作。

只是为了澄清:

不会返回一堆 id,它会返回 Payment 对象的集合,完整的东西,所以你最好调用它:

$orders = PaymentInfo::all();

我只是保留了你用来让它为你工作的名字。

于 2013-09-26T02:50:53.273 回答