Welcome Guest, Not a member yet? Register   Sign In
Using __call() to redirect unknown methods in PHP5
#1

[eluser]Unknown[/eluser]
Hi guys

I am putting together a simple CMS and have a controller called site to display the pages created therein, the idea being that the url will become http://example.com/site/page_name for any page created within this system.

Obviously the site controller will not have methods for each of the pages but (at the moment) I am looking to use the __call() magic method to pass any request for a pages (i.e. a method that doesn't exist) to a page load function as follows:

Code:
<?php
class Site extends CC_Controller
{
    public function __construct()
    {
        parent::__construct();
    }    
    
    public function __call($name, $args)
    {
        $this->_load_page($name);
    }
    
    public function _load_page($name)
    {
        echo "hello";
    }    
}
?>


This seems to work fine in principle but CI always shows a 404 message after my output so I have two questions:
1) Does this seem like a reasonable way to handle this, or would you recommend something else?
2) If it is reasonable, is there any way of surpressing the 404 for just the site controller?

Cheers

Chris
#2

[eluser]Unknown[/eluser]
OK big slap round the face with CI Manual for me - might as well use _remap() for this :lol:




Theme © iAndrew 2016 - Forum software by © MyBB