Laravel 4嵌套的资源控制器Route :: resource('admin/photo','PhotoController');不工作 [英] Laravel 4 nested resource controllers Route::resource('admin/photo', 'PhotoController'); not working

查看:145
本文介绍了Laravel 4嵌套的资源控制器Route :: resource('admin/photo','PhotoController');不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Larvel 4中,我正在尝试设置嵌套的资源控制器.

In Larvel 4 I'm trying to setup nested resource controllers.

routes.php 中:

Route::resource('admin/photo', 'Controllers\\Admin\\PhotoController');

app \ controllers \ Admin \ PhotoController.php 中:

<?php namespace Controllers\Admin;

use Illuminate\Routing\Controllers\Controller;

class PhotoController extends Controller {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        return '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.
     *
     * @return Response
     */
    public function show($id)
    {
        return $id;
    }

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

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

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

}

索引(/admin/照片GET),创建(/admin/照片/创建)和存储(/admin/照片POST )操作正常...但是编辑显示无效,我只是看到一个页面未找到404状态.

index (/admin/photo GET), create (/admin/photo/create) and store (/admin/photo POST) actions work fine... but not edit and show, I just get a page not found 404 status.

但是,如果我删除管理员根目录路径,它将起作用.

it will work though if I drop the admin root path.

任何人都可以告诉我如何设置Route :: resource控制器以使用诸如admin/photo之类的嵌套路径

Can anyone tell me how I setup the Route::resource controller to work with a nested path like admin/photo

推荐答案

请参见 https://github .com/laravel/framework/issues/170 在这里找到了我的答案(请参阅泰勒写的内容)

See https://github.com/laravel/framework/issues/170 Found my answer there (see what Taylor wrote)

对于那些希望在route.php中看到我现在可以使用的代码的人:

For those who want to see my code that works now in routes.php:

Route::group(array('prefix' => 'admin'), function() {

    // Responds to Request::root() . '/admin/photo'
    Route::resource('photo', 'Controllers\\Admin\\PhotoController');
});

这篇关于Laravel 4嵌套的资源控制器Route :: resource('admin/photo','PhotoController');不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆