Welcome Guest, Not a member yet? Register   Sign In
How to prevent a controller to run from web?
#13

[eluser]paulc010[/eluser]
@mddd Sorry I confused the issue by mentioning modules. I was merely pointing out that the addition of the underscore just prevents "normal" CI routing (and thus prevents the method from being accessible from a web client). In PHP terms the method is still public and callable from outside the class, as opposed to declaring it "private".

Personally I would place the cron script as well as all but main index.php and associated css/js and images above the document root for the site. Cron has no problem running scripts there, and that renders it inaccessible from a browser. I always set CI up that way as I don't see the need to have the system or application folders accessible.

WanWizard's solution will work if indeed the entire controller should only be available via cron which I think is what the OP is trying to do. My case is slightly more complex, as you'll see below.

The "problem" with my method is that we still need the main CodeIgniter.php file to use all of CI's goodness - and that is where the test for the underscore lies. I would suggest that it would be only a slightly naughty hack to create a "cron version" with the test for the underscore removed.... e.g. CodeIgniterCron.php. This can then be included instead of the standard version by our cron script.

I'm looking at it from the point of view of having each controller (and module) contain its own code that I want to execute via cron. That way I can keep the code self-contained, rather than having all the scheduled code lumped into one place. I may also want to only activate the cron elements for a particular controller or module when that part of the site is installed and/or enabled (e.g. from the admin panel). I could use WanWizard's test in every "cron" controller method, but in my opinion that's messy and prone to errors/omissions.

Experimentation required I think....

Paul


Messages In This Thread
How to prevent a controller to run from web? - by El Forum - 04-25-2010, 04:14 PM
How to prevent a controller to run from web? - by El Forum - 04-25-2010, 06:29 PM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 12:41 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 01:28 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 01:36 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 01:44 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 01:49 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 01:55 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 01:56 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 02:14 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 02:19 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 02:50 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 05:27 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 05:45 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 06:31 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 06:38 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 06:41 AM
How to prevent a controller to run from web? - by El Forum - 04-26-2010, 08:41 AM
How to prevent a controller to run from web? - by El Forum - 06-06-2010, 01:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB