Page 1 of 1

How to make custom module show error404

Posted: Mon Apr 12, 2010 1:41 am
by Augustas
Hello,

I am creating a module which introduces a new Content Type for the pages.
In some cases I need the page with My Content Type to show error 404 (not found).

What is the best way to do it?

I would like to show the content of CMSMS built-in page with alias "error404", and at the same type to send http header status = 404 (not found).

I tried this:

Code: Select all

if(    [condition not met]    ){
    $contentops =& $gCms->GetContentOperations();
    $this->RedirectContent($contentops->GetPageIDFromAlias('error404'));
}
however in this case it sends http header = 302 and once redirection was done - status = 200 Ok

Maybe I should try something like this?

Code: Select all

if(    [condition not met]    ){
    header("HTTP/1.0 404 Not Found");
    [include the contents of error404 page]
    die();
}
Question: how to get and display the content of the page with alias "error404"?

Or maybe there is another solution to my problem?

Re: How to make custom module show error404

Posted: Mon Apr 12, 2010 12:26 pm
by Augustas
So far I have solved my problem in this way:

Code: Select all

if(    [condition not met]    ){
	$_GET['page'] = $_REQUEST['page'] = 'none-existant-page-alias';
	include(dirname(__FILE__).'/../../index.php');
	exit;
}
I simply call for the page which does not exists.
Not very clean, but it works...

UPDATE:
this method works properly only when in the "config.php" 'process whole template' is set to TRUE:
$config['process_whole_template'] = true;
However, still looking for a solution, when $config['process_whole_template'] = false;