Visit function available in controllers etc


When I make some conditional checks to see if some url is a valid one or if it should return 404 in a controller I need to use:

if( $page->status() == 'hah' ) {
  header::redirect( $site->errorPage() );

While it work I don’t like to redirect it. I would prefer to show the 404 message on that url. Another issue is that it appear in the Google Webmaster Tools:

It’s not really a page, so why is it needed as an url anyway!?

In a route we can use the visit() but a route might not have all the information we need.

Better visit function

I want a better visit() function that is not just for routes, but for controllers or functions or even in the header.php snippet (before anything else loads).

In my world it would be nice if it would look like this:

echo $site->visit('some/uri', $lang);

I would not mind calling it something else if this is kind of bound to the routes, something like:

echo $site->emulate('some/uri', $lang);


That’s a good idea in general, but it’s another one of those execution order issues. At the time the controller is loaded, Kirby has already decided on the page to use, otherwise it wouldn’t know which controller to use.

There might be a way however to visit another page if Kirby is told to in the controller, but it might be complicated. There will definitely be no way to do this in the header snippet though as there may already be output from the “old” page.

I’ll keep this open as a suggestion in case someone else needs/wants this as well.

1 Like