How to make custom module show error404

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

How to make custom module show error404

Post 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?
http://FollowTheRoad.com/ - living on the road...
http://www.kligys.com/ - asmeninis blog'as...
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

Re: How to make custom module show error404

Post 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;
Last edited by Augustas on Tue Apr 13, 2010 6:13 am, edited 1 time in total.
http://FollowTheRoad.com/ - living on the road...
http://www.kligys.com/ - asmeninis blog'as...
Post Reply

Return to “Developers Discussion”