0

I made a contest where members could register to win prizes. Now, it's time to display results and winners of the contest. I want to allow only one controller and one method, to disable the possibility to still register to the contest.

I think redirections may be a great solution but how to do this on the whole application without copy and paste the code in every methods of each controller?

Any ideas/advices welcomed!

Dacobah
  • 779
  • 3
  • 15
  • 35
  • I would have a contests table in DB... this way you can set a isOpen flag or something and check the status of the contest from within any page you may want to check if a specific contest is still running. – Brian Aug 06 '12 at 15:57

2 Answers2

0

In the constructor of the controller, you can add a check to see if the user is calling a specific function or not by matching uri_string() to your required method's uri, and then redirect him using redirect(). This is effective because, a check in controller's constructor means, the user doesn't even have access to the methods when the check happens. So there is no way he/she can execute them.

EDIT: It works.

public function __construct(){
    parent::__construct();
    $this->load->helper('url');
    if(uri_string() !== "controller_name/allowed_method_name"){
        redirect("/"); // some where
    }
}
Prasanth
  • 5,230
  • 2
  • 29
  • 61
0

The easiest way would be to catch any url in your routes file (config/routes.php) and assign it to the controller action you want to show:

$route['default_controller'] = 'controller';
$route['(:any)'] = "controller/action";

This is also faster than using redirects.

Mischa
  • 42,876
  • 8
  • 99
  • 111