i've inspected cms code for search method with return 404 error
i'm found Response::make(View::make('cms::404'), 404);
but this returns system 404
also exists
if (!$page && !($page = $this->router->findByUrl('/404')))
return Response::make(View::make('cms::404'), 404);
$this->page = $page;
but this code doesn't run from component, first variant is better, but cannot shows my 404 page
class Something extends ComponentBase
{
public function onRun()
{
return $this->controller->run('404');
}
}
This allows you to show your own 404 page, or any page you'd like for that matter. The issue is the HTTP status code. This will be HTTP 200 "OK" no matter what. We should have a way of passing a statuscode to the run() method.
Another solution would be to do something like this:
App::abort(404); // triggers NotFoundHttpException
This is Laravel's built in solution. The router or controller (i'm not sure which one) might want to listen for "NotFoundHttpException" and show the default 404 page instead of a fatal error page, automatically setting the status code to 404.
class Something extends ComponentBase
{
public function onRun()
{
return Response::make($this->controller->run('404'), 404);
}
}
Fair enough. Not the most developer friendly solution, but it floats my boat :-)

My code:
title = "Test"
url = "/news/:post_slug"
layout = "default"
==
<?php
use RainLab\Blog\Models\Post;
function onStart()
{
return Response::make($this->controller->run('404'), 404);
// $slug = $this->param('post_slug');
// $this['article'] = Post::isPublished()->where('slug', $slug)->first();
// if (!$this['article']) {
// }
}
?>
==
Test
But this working fine:
return Response::make(View::make('cms::404'), 404);
But,
return Response::make(View::make('cms::404'), 404);
return laraval 404 page, not cms custom 404.htm
return Response::make($this->controller->run('404'), 404);
insert response text in body tag ... (HTTP.....)
What i should to do to display custom 404 page from component correctly?
solved https://github.com/octobercms/october/issues/563#issuecomment-61360021
I'm experiencing this issue when trying to use a 404 in a component. Any ideas?
public function onRender()
{
$this->category = Category::where('slug', $this->param('category'))->get()->first();
if(!$this->category['id']) {
$this->setStatusCode(404);
return $this->controller->run('404');
}
Not only is the header status being displayed, but the entire 404 page is being injected into {% page %}, layout and all.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Missing Page </title>
...
<body>
<div class="main-container">
HTTP/1.0 404 Not Found
Cache-Control: no-cache
Date: Sun, 10 Sep 2017 22:10:26 GMT
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Missing Page </title>
@buckhornmktg That's because you're doing that in onRender(). Do that in onRun() instead and it will work fine.
Doh! Thanks Luke, that was the problem.
Not a problem, happy to help.
I just need to ask is octobercms has only capable of setting two types of errors ???
1.404 [by creating a page with /404 url ]
2.500 [by creating a page with /error url ]
how can we set 401, 402, 403 etc ??????
public function onRun(){
return $this->controller->setStatusCode(404)->run(404);
}
Most helpful comment
I just need to ask is octobercms has only capable of setting two types of errors ???
1.404 [by creating a page with /404 url ]
2.500 [by creating a page with /error url ]
how can we set 401, 402, 403 etc ??????