fuel / docs

Fuel PHP Framework - Fuel v1.x documentation
http://fuelphp.com/docs
Other
168 stars 234 forks source link

before() #590

Closed acidm closed 11 years ago

acidm commented 11 years ago

before()... " It will not be called if that method turns out not to exist. " This is not true, before method is called always.This is a bug in docs or core? When she should be called?

WanWizard commented 11 years ago

Obviously, the docs are correct. And so is the code.

If it would always be called, you would get a method before() not defined on the first controller that doesn't have a before method...

acidm commented 11 years ago

Ok please tell me why ,if i called not existed method "tester->noexists()" my request is redirected... My request: http://localhost/index.php/tester/noexists/

All config in fuelphp is default.

And code: <?php

class Controller_Tester extends Controller {

public function before()
{
     return Response::redirect('http://www.google.pl');
}

public function action_work()
{
return Response::forge('Worked,worked,werked');
}

}

PS.sorry for my english ... :)

frankdejonge commented 11 years ago

@acidm the before function is a substitute for a __constructor function. Because we use the constructor internally to set the Request and check for internal routing, we allow users to specify the before method. In your case, the before method redirects the user away, like with a normal constructor, this is always called. That's why it's redirected.

acidm commented 11 years ago

Ok thanks :) , but why in the docs is write " It will not be called if that method turns out not to exist." ?

frankdejonge commented 11 years ago

It's if the before method does not exists in the controller class, not the other method.

acidm commented 11 years ago

ok thanks again :)