Blog-plugin: Doesn't show 404 page when post is not exists

Created on 26 Feb 2015  路  10Comments  路  Source: rainlab/blog-plugin

I made this.
function onEnd()
{
if(!$this->post){
$this->setStatusCode(404);
Response::make( $this->controller->run('404'), 404 );
return;
}
}
but it's not working when we don't have a 404 page. It must to show octobercms 404 and also
index route is /:page?1|^[0-9]+$
blog route is /:slug

It's only routes to blog not to page

Any idea?

Most helpful comment

Is there any reason to not include this into the plugin be default? Perhaps on the Post.php component?

All 10 comments

function onEnd()
{
    if (!$this->post) return App::make('Cms\Classes\Controller')->setStatusCode(404)->run('/404');
}

Should work

Is there any reason to not include this into the plugin be default? Perhaps on the Post.php component?

@daftspunk, is there a reason for this? Why did you decide to return a 200 response in such a case?

@rodrigogoncalves I suggest creating a new issue for this, would probably get it looked at faster

this issue persist in 458 version

@mdsaicom @rodrigogoncalves @mbaxter91288 feel free to submit a PR with @daftspunk's recommendation.

I think the reason here is to have full control over how to handle the response or page in case the blog post does not exist. In my case, I don't want a 404 redirect instead, I want the user to know that the blog does not (no longer) exists then I can suggest other blogs for further reading.

@nozreh while adding the 404 handling to the plugin may (temporarily) break that use case for you, I think it's probably worth doing. You'd still be able to have that custom handling if you so desire, but the point is that the post doesn't exist so it should be returning a 404 response. If that response happens to include helpful links to other blog posts that's fine but the key response should still be a 404.

@LukeTowers for me it's fine as long as I can still do custom handling but I find it odd if that is the case because at the end of the day the blogPost is still a component and it'll be a bad design at least for me if a "component" decides on what response the whole page should return. If 404 is needed then I'll handle it in the page life cycle (like what daftspunk suggests) but then again that is just my use case.

@nozreh I agree with you generally that a component shouldn't really dictate what the response of the page is, however it's a little bit more of a grey issue when you considered the intended use case of this blogPost component, it's entire purpose is to basically provide that response in the form of a blog post returned from the DB. It's not like it's a signup form or some other smaller component that is meant to form a piece of the overall page experience being delivered to the user, it's meant to be the main part of the response.

Perhaps a good compromise would be to have the component have a "Return 404" property of some sort that triggers that behaviour?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rickmills picture rickmills  路  5Comments

sabuz picture sabuz  路  5Comments

MaTToX3 picture MaTToX3  路  6Comments

daveharrisonnet picture daveharrisonnet  路  9Comments

HugoBossOD picture HugoBossOD  路  5Comments