将每个产品链接到Laravel中的product_details页面

时间:2016-06-18 19:14:34

标签: php laravel laravel-4

在原生PHP中,将页面上的每个产品链接到其product_details页面大约需要2分钟

- 比如从数据库中为每个产品提供一个id,并在详细信息页面中通过$ _GET从URL获取id并获取相同id的数据库信息

现在我在Laravel做同样的事情,请有人帮我把手放在这里

这是我的代码

路线路线编辑

Route::get('Current_projects', 'ProjectController@currentProjects');
Route::get('projects/projectDetails/{id}', 'ProjectController@viewProject');

这是我的控制器

class ProjectController extends \BaseController
{

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function currentProjects()
    {
        $projects = Projects::all();
        return View::make('projects.currentProjects', ['projects' => $projects]);
    }

    public function viewProject($id)
    {
        $projects = Projects::with('projectDetails')->findOrFail($id);
        return View::make('projects.currentProjects.projectDetails', compact($projects));
    }
}

以下是我尝试关联修改

的方法
<a href="{{ URL::to("projects/projectDetails/{$pro->id}") }}" class="portfolio-link" data-toggle="modal">

现在点击currentProjects中的任何产品

收到错误

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Open: C:\wamp\www\myPro\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php

php artisan route

+--------+------------------------------------------+------+-----------------------------------+----------------+---------------+
| Domain | URI                                      | Name | Action                            | Before Filters | After Filters |

+--------+------------------------------------------+------+-----------------------------------+----------------+---------------+
|        | GET|HEAD /                               |      | PagesController@home              |                |               |
|        | GET|HEAD home                            |      | PagesController@home              |                |               |
|        | GET|HEAD about                           |      | PagesController@about             |                |               |
|        | GET|HEAD vision                          |      | PagesController@vision            |                |               |
|        | GET|HEAD Chairman Word                   |      | PagesController@chairmanWord      |                |               |
|        | GET|HEAD contacts                        |      | PagesController@contacts          |                |               |
|        | GET|HEAD Current_projects                |      | ProjectController@currentProjects |                |               |
|        | GET|HEAD project/projectDetails/{id} |      | ProjectController@viewProject     |                |               |
+--------+------------------------------------------+------+-----------------------------------+----------------+---------------+

3 个答案:

答案 0 :(得分:1)

试试这个

<a href="{{ url('projects/projectDetails', [$pro->id]) }}"> ... </a>

了解更多信息,请查看此链接 https://laravel.com/docs/4.2/helpers#urls

答案 1 :(得分:0)

NotFoundHttpException类似于HTTP 404 - 找不到网站。您的路由或链接似乎有问题。

答案 2 :(得分:0)

You are generating a URL to a route you haven't defined.

Routes match URIs. There is no route defined for Current_projects/projectDetails/{id}.

Also this is incorrect:

Route::get('projects/projectDetails/{$id}', ...);

Params don't have $ signs in them in the URI.

Route::get('projects/projectDetails/{id}', ...);

Would be the correct way to define that.

Then you can create a URL to that:

URL::to("projects/projectDetails/{$pro->id}");