【发布时间】:2014-06-22 04:19:46
【问题描述】:
我的 app/routes.php 文件中有以下代码:
<?php
// Route/model binding for data
Route::model('data', 'Data');
Route::get('/', function() {
return Redirect::to("data");
});
// Display all data (of all types)
Route::get('data', function(){
$data = Data::all();
return View::make('data.index')
->with('data', $data);
});
// Display all data of a certain type
Route::get('data/type/{name}', function($name){
$type = Data::whereName($name)->with('data')->first();
return View::make('data.index')
->with('type', $type)
->with('data', $type->data);
});
Route::get('data/{data}', function($data){
return View::make('data.single')
->with('data', $data);
});
// Create/Add new data
Route::get('data/create', function(){
$data = new Data;
return View::make('data.edit')
->with('data', $data)
->with('method', 'post');
});
Route::post('data', function(){
$data = Data::create(Input::all());
return Redirect::to('data/'.$data->id)
->with('message', 'Seccessfully added data!');
});
// Edit data
Route::get('data/{data}/edit', function(Data $data){
return View::make('data.edit')
->with('data', $data)
->with('method', 'put');
});
Route::put('data/{data}', function(){
$data->update(Input::all());
return Redirect::to('data/'.$data->id)
->with('message', 'Seccessfully updated page!');
});
// Delete data
Route::get('data/{data}/delete', function(Data $data){
return View::make('data.edit')
->with('data', $data)
->with('method', 'delete');
});
Route::delete('data/{data}', function(Data $data){
$data->delete();
return Redirect::to('data')
->with('message', 'Seccessfully deleted data!');
});
// The about page (static)
Route::get('about', function(){
return View::make('about');
});
// View composer
View::composer('data.edit', function($view){
$types = Type::all();
if(count($types) > 0)
{
$type_options = array_combine($types->lists('id'),
$types->lists('name'));
}
else
{
$type_options = array(null, 'Unspecified');
}
$view->with('type_options', $type_options);
});
我所有的路线都可以正常工作,除了数据/创建。当我访问数据/创建时,我收到 404 Not Found 错误。即使我将路线定义如下:
Route::get('data/create', function(){
return "Test";
});
我仍然收到 404 错误。但是,以下工作正常:
Route::get('somethingElse/create', function(){
return "Test";
});
我不知道问题可能是什么。我正在遵循 Raphal Saunier 的“Laravel 4 入门”一书中的示例,作者编写的代码与我上面的代码相同(尽管使用“cats”而不是“data”)。
【问题讨论】:
标签: laravel laravel-4 http-status-code-404