0

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:


Not Found

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?

My code:

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');
1
  • 2
    Are you sure this is a problem with controllers? Have you confirmed that plain routes work, like Route::get('my/something', function() { return 'world'; }); Perhaps try visiting myproject/index.php/account/login - this will confirm whether your rewriting rules are working. Commented Apr 5, 2013 at 14:15

1 Answer 1

1

@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;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.