Throw a 404 error

Permalink
How do I throw a 404 error, I want to do this from a block.

In Concrete 5.6 I could do:

$v = View::getInstance();
$v->render('/page_not_found');

But this doesn't seem to work anymore, I get the following error:

include(/Library/WebServer/Documents/site/concrete/views/.php): failed to open stream: No such file or directory

Does anyone know the best method?

Many thanks

bvcreative
 
Mnkras replied on at Permalink Reply
Mnkras
in 5.7 from your controller you can do:

$this->replace('/page_not_found');


where $this is an instance of PageController
bvcreative replied on at Permalink Reply
bvcreative
Hi Mnkras

Thanks for your response, unfortunately I get a Call to undefined method error. I am trying this from a block rather than a page though.

Many thanks
greg403 replied on at Permalink Reply
Below is a code snippet to throw a 404 error from within a Block.
The important part is the $c...

$c = \Page::getCurrentPage();
$c->getPageController()->replace('/page_not_found');


As part of a function within a block...

public function action_details($slug)
    {
        $release = $this->getReleaseService()->getReleaseBySlug($slug);
        if ($release == null) {
            $c = \Page::getCurrentPage();
            $c->getPageController()->replace('/page_not_found');
            return;
        }
...


Sorry to bring back this old post, but since I just figured it out and this is the place Google keeps sending me to, below