Om3*_*3ga 3 php routing routes laravel laravel-4
我是laravel的新手,现在就学习它.我在routes.php文件中提供以下路线
Route::resource('contacts', 'ContactsController');
Run Code Online (Sandbox Code Playgroud)
但是当我在浏览器中加载我的页面时,它会给我以下错误
Unhandled Exception
Message:
Call to undefined method Laravel\Routing\Route::resource()
Location:
/Users/zafarsaleem/Sites/learning-laravel/application/routes.php on line 35
Run Code Online (Sandbox Code Playgroud)
我的完整routes.php文件如下
Route::resource('contacts', 'ContactsController');
Route::get('/', function() //<------- This is line 35
{
return View::make('home.index');
});
Run Code Online (Sandbox Code Playgroud)
如何删除此错误?
编辑
ContactsController代码如下,我想要使用index()函数
class ContactsController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
Contact::all();
}
/**
* 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()
{
$input = Input::json();
Contact::create(array(
'first_name' => $input->first_name
'last_name' => $input->last_name
'email_address' => $input->email_address
'description' => $input->description
));
}
/**
* Display the specified resource.
*
* @return Response
*/
public function show($id)
{
return Contact::find($id);
}
/**
* Show the form for editing the specified resource.
*
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @return Response
*/
public function update($id)
{
$contact = Contact::find($id);
$input = Input::json();
$contact->first_name = $input->first_name;
$contact->last_name = $input->last_name;
$contact->email_address = $input->email_ddress;
$contact->description = $input->description;
$contact->save();
}
/**
* Remove the specified resource from storage.
*
* @return Response
*/
public function destroy($id)
{
return Contact::find($id)->delete();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2
我尝试了以下两条路线,但最终出现了同样的错误
Route::resource('contacts', 'ContactsController', ['only', => ['index']]);
Route::get('contacts','ContactsController@index');
Run Code Online (Sandbox Code Playgroud)
重新安装laravel 4后,我收到了以下错误
404 Not Found
The requested URL /contacts was not found on this server.
_____________________________________________________________________
Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Server at bb.dev Port 80
Run Code Online (Sandbox Code Playgroud)
编辑3
这是现在做的,我编辑"/private/etc/apache2/users/.conf"并从"AllowOverride None"更改为"AllowOverride All"然后重新启动我的apache服务器.现在我收到了以下错误
403 Forbidden
You don't have permission to access /contacts on this server.
__________________________________________________________________________________
Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Server at bb.dev Port 80
Run Code Online (Sandbox Code Playgroud)
为什么我没有这个联系人控制器的权限?现在让我发疯了.
这是我的.htaccess文件
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
你在另一台服务器上试过吗?很多事情都可能出现重写问题(我已经失去了修复.htaccess的时间),所以问题可能是Apache而不是Laravel.
这适用于我public/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
你尝试过index.php/contacts而不是/contacts吗?如果可行,问题是Apache,而不是Laravel.
| 归档时间: |
|
| 查看次数: |
7614 次 |
| 最近记录: |