Welcome Guest, Not a member yet? Register   Sign In
Autorun a controller with CI
#1

[eluser]Fatih[/eluser]
Dears,

I coded a MVC structure for create a rss.xml file which is updated one time in every day, on a rss subdirectory. I need to create a mechanism to perform every loading on my website like this:

1. Check the rss.xml file date with system date.
2. If system date is new than rss.xml file date, run controller file with MVC structure.

How can I perform this?
#2

[eluser]m9dfukc[/eluser]
I would say you need a cron job.
#3

[eluser]xwero[/eluser]
You can use the php function filemtime to get the latest modification time of the file.
#4

[eluser]Fatih[/eluser]
Thanks xwero.

But my problem is not to check file creation or modification date. My problem is how I can start the controller file on loading a every different pages. When my website is loaded, I have to run a controller file. Then this file will be check this modification date and If the system date is new than rss.xml file date, create new one on background.

But I cannot find the starter mechanism Sad
#5

[eluser]xwero[/eluser]
If you want to run an action on every page load you should check hooks
#6

[eluser]Fatih[/eluser]
I read about hooks before. But it cannot be applicable for MVC structure. My code is applicable is MVC structure. If it is not possible to start a MVC structure in every loaded pages, I will change my codes to hooks.
#7

[eluser]ontguy[/eluser]
Using Michael Wales dev pack you could have a function in the your Public_Controller; http://www.michaelwales.com/2008/01/my-c...-dev-pack/. Every controller that extends Public_Controller would run that function.

application\libraries\MY_Controller.php
Code:
class Public_Controller extends Controller {
    function Public_Controller() {
        parent::Controller();
        $this->run_function_everytime();
    }

    function run_function_everytime() {
    //beautiful code
    }
}

application\controllers\feed.php
Code:
class Feed extends Public_Controller {
  function __construct() {
        parent::Public_Controller();
    }
}

application\controllers\page.php
Code:
class Page extends Public_Controller {
  function __construct() {
        parent::Public_Controller();
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB