Reputation: 155
1. I'm following CodeHappy: Using Controllers to learn to use laravel controllers, in my PC "myproject/" points to "wamp/www/laravel/public" folder, when I try "myproject/account/login" the browser shows:
The requested URL /account/login was not found on this server.
2. Obviously, the browser tries to find the "account" folder instead of using controller, I created the "account" folder under "public" and tried again, my guess was proved right. Should I config anywhere before using controllers?
application/controllers/account.php
<?php
class Account_Controller extends Base_Controller
{
public function action_index(){
echo "This is the profile page.";
}
public function action_login(){
echo "This is the login form.";
}
public function action_logout(){
echo "This is the logout action.";
}
}
/application/routes.php
Route::get('/', function()
{
return View::make('home.index');
});
Route::controller('account');
Upvotes: 0
Views: 1387
Reputation: 19662
@Phill Sparks has it completely right (rightfully so! He's been using Laravel for ages). If your browser is reporting a 404 from the server, unless you completely removed the 404 event, then the request did not even go through Laravel.
Try /index.php/account/login
. If it works, you know that your rewrite rules are botched. If it doesn't work either, then you have a much more serious issue at hand.
If you are using Apache, you should find in your htaccess
file the rewrite rules for Laravel. If you cannot load mod_rewrite through htaccess, you'll need to migrate them to your server config.
If you are using nginx, you will need something similar to this in your server
block:
location / {
try_files $uri $uri/ @laravel;
}
location @laravelDesktop {
rewrite ^/(.*)$ /index.php?/$1 last;
}
Or if in a subdirectory
location /my/subdir/ {
try_files $uri $uri/ @laravel;
}
location @laravel {
rewrite ^/my/subdir/(.*)$ /index.php?/$1 last;
}
Upvotes: 1