Presenter lifecycle redirect

Bill Lions
Member | 47
+
0
-

The presenter lifecyle, as described https://doc.nette.org/…n/presenters#… shows, that a redirect may occur after startup() and action(View).

Is there any way to log, or view if a redirect occurs, and what causes the redirect?

The reason I ask, is my presenter startup() method is called, but then is redirected, without calling the renderDefault() method.

namespace App\Presenters;

// alias Nette for use when extending
use Nette;
use Nette\Application\UI;
use Nette\Application\UI\Form;
use Nette\Application\UI\Presenter;
use Nette\Application\Helpers;


class ContactPresenter extends UI\Presenter
{
        private $form;

        public function __construct()
        {
                $path = __DIR__.'/../../layouts/@common.latte';
                $this->setLayout( $path );
        }

        public function startup()
        {
                parent::startup();
        }

        public function renderDefault()
        {
                $this->template->title = "NBN";
        }
}
jiri.pudil
Nette Blogger | 1032
+
0
-

Hello, in that phase of the lifecycle, the redirect happens due to canonization, which suggests there most likely is a problem in your router – if it generates a different URL than the actual one for the current request, Nette redirects to the new one.

I see in your other thread that you are using custom routers — I'd start by placing a breakpoint in the router's constructUrl method and trying to see what it does.

Bill Lions
Member | 47
+
0
-

jiri.pudil wrote:

Hello, in that phase of the lifecycle, the redirect happens due to canonization, which suggests there most likely is a problem in your router – if it generates a different URL than the actual one for the current request, Nette redirects to the new one.

I see in your other thread that you are using custom routers — I'd start by placing a breakpoint in the router's constructUrl method and trying to see what it does.

Thanks Jiri,
When I put a breakpoint in match(), I get the expected result.
Putting a breakpoint in constructUrl() never triggers.
It seems that somewhere between match() and constructUrl(), that the error occurs.. Or, I could horribly mistaken.

jiri.pudil
Nette Blogger | 1032
+
+1
-

Oh, I see now. Routers are evaluated one by one in the order of registration, and the first non-null result is used. It seems that you are only checking the action parameter in the constructUrl() method, so the router that is registered first matches any presenter with the 'default' action. You should also check the target presenter.

By the way, Nette provides a pretty powerful routing solution which would spare you these pains :)

Bill Lions
Member | 47
+
0
-

jiri.pudil wrote:

Oh, I see now. Routers are evaluated one by one in the order of registration, and the first non-null result is used. It seems that you are only checking the action parameter in the constructUrl() method, so the router that is registered first matches any presenter with the 'default' action. You should also check the target presenter.

By the way, Nette provides a pretty powerful routing solution which would spare you these pains :)

Ahh, now I get it, I thought that if it matched in the match() method, all would be well.

My thinking was (is) that each module should be a stand-alone module, and any routes specific to the module, could be included in the modules own route file.