Reputation: 36227
I am coming from codeigniter, and trying to wrap my head around routing. I am following the http://codehappy.daylerees.com/using-controllers tutorial
If you scroll down to RESTful controllers, Dayle talks about Home_Controller extending the base_controller and adding public function get_index() and post_index(). I have copied the code, but when I go to
http://localhost/m1/public/account/superwelcome/Dayle/Wales
I get:
We took a wrong turn. Server Error: 404 (Not Found).
Is there anything obvious that I'm doing wrong ? Should I be putting the code somewhere else? Here's my code
class Base_Controller extends Controller {
/**
* Catch-all method for requests that can't be matched.
*
* @param string $method
* @param array $parameters
* @return Response
*/
public function __call($method, $parameters)
{
return Response::error('404');
}
public $restful = true;
public function get_index()
{
//
}
public function post_index()
{
//
}
}
In the routes.php file I have:
// application/routes.php
Route::get('superwelcome/(:any)/(:any)', 'account@welcome');
my account controller ( from the tutorial) is:
// application/controllers/account.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.";
}
public function action_welcome($name, $place)
{
$data = array(
'name' => $name,
'place' => $place
);
return View::make('welcome', $data);
}
}
Upvotes: 3
Views: 5788
Reputation: 5900
You should change the line in application/controllers/account.php
public function action_welcome($name, $place)
to
public function get_welcome($name, $place)
since the Account_Controller inherits $restful = TRUE
from Base_Controller class, making action_
-prefixed function name unusable.
Additionally, you must change all the function prefixes in account.php
to get_
for the same reason :)
Upvotes: 6