Php 使用Laravel构建电子商务网站:如何根据产品ID查看/发送产品?

Php 使用Laravel构建电子商务网站:如何根据产品ID查看/发送产品?,php,laravel,Php,Laravel,我学习了Tutsplus关于使用Laravel创建电子商务网站的教程。我现在遇到的问题是当尝试路由到子文件夹时。在本教程中,讲师提供了一项功能,您可以通过ID查看产品。他就是这样做的: // StoreController.php public function getView($id) { return View::make('store.view')->with('store', Store::find($id)); } 这段代码似乎正在从stores表传递id。我认为当点击

我学习了Tutsplus关于使用Laravel创建电子商务网站的教程。我现在遇到的问题是当尝试路由到子文件夹时。在本教程中,讲师提供了一项功能,您可以通过ID查看产品。他就是这样做的:

// StoreController.php
public function getView($id) {
    return View::make('store.view')->with('store', Store::find($id));
}
这段代码似乎正在从
stores
表传递
id
。我认为当点击一个产品时,就是传递
id
的时候

// Routes.php
Route::controller('store', 'StoreController');
还有一些模板:

// store\index.blade.php
<h2>Stores</h2>
<hr>
<div id="stores row">
    @foreach($stores as $store)
    <div class="stores col-md-3">
        <a href="/store/products/view/{{ $store->id }}">
            {{ HTML::image($store->image, $store->title, array('class' => 'feature', 'width'=>'240', 'height' => '127')) }}
        </a>

        <h3><a href="/store/products/view/{{ $store->id }}">{{ $store->title }}</a></h3>

        <p>{{ $store->description }}</p>
    </div>
    @endforeach
</div><!-- end product -->
对此

public function getView($id) {
    return View::make('store.product.view')->with('store', Store::find($id));
}

但它似乎不起作用,只给了我一个控制器方法未发现的错误

首先,视图名称
view::make('store.product.view')
与URL无关

您必须更改路线:

Route::controller('store/view', 'StoreController');
然后在控制器中调整方法的名称,因为它应该与
store/view

public function getProducts($id) {
    return View::make('store.product.view')->with('store', Store::find($id));
}

我强烈建议您阅读主题

中的内容。看,讲师正在使用控制器路由,因此您实际上无法控制命名链接、命名路由和更改相关控制器功能。url将保持不变,如果您在该位置有视图文件,您将注意到它与您的代码一起正确加载。请查看此处:
public function getProducts($id) {
    return View::make('store.product.view')->with('store', Store::find($id));
}