【问题标题】:Having trouble understanding links in laravel 4无法理解 laravel 4 中的链接
【发布时间】:2013-06-01 19:09:04
【问题描述】:

我在 laravel 4 中的 link_to_action 有问题

在 laravel 3 中,我会显示类似的链接

{{ HTML::link_to_action('user/create', 'Create User') }}

但是由于我已经切换到 laravel 4,所以我正在创建像这个 UserController 这样的控制器,但是当我尝试使用 HTML 时

{{ HTML::linkAction('user/create', 'Create User') }}

它给了我一个错误,即使有一个名为 create 的方法,操作也不存在。 任何帮助将不胜感激。

这是我的控制器

<?php

class UserController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}

【问题讨论】:

    标签: laravel laravel-4


    【解决方案1】:
    // L3
    {{ HTML::link_to_action('user@create', 'Create User') }}
    
    // L4
    {{ HTML::linkAction('UserController@create', 'Create User') }}
    

    编辑:

    // I think you missed that entry in your routes.php
    Route::resource('user', 'UserController');
    

    【讨论】:

    • 嗯,我试过了,它似乎工作,但仍然报错
    • 你的 routes.php 中有那个条目吗? Route::resource('user', 'UserController');
    • 是的,但是当我尝试测试更新或销毁时会出错
    • 我正在尝试将 except 数组用于带有参数的 http 动词,以便我可以在 id 上运行 reg expr
    • 请用新问题、新问题和新代码更新您的问题,因为您现在正在询问另一个问题
    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多