简体   繁体   中英

Call a model function when CodeIgniter loads

I've been working on a CI application and I came across an issue.

Instead of using a CronJob, I want to acomplish the following:

normally, when a user opens my website CodeIgniter loads in the background. When CI finishes loading I want to call a function from a model that I've written. How can I acomplish this?

(I don't know which controller would be loaded by the viewer, hence my confusion)

Hopefully you understood me and I'm awaiting your answers

I suggest you read about Hooks in CodeIgniter. You can specify at what point in the application you want the hook to run, and from what you describe the post_system hook is what you need.

post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.

In the hook definition you specify what class and method to run.

$hook['pre_controller'] = array(
                                'class'    => 'MyClass',
                                'function' => 'Myfunction',
                                'filename' => 'Myclass.php',
                                'filepath' => 'hooks',
                                'params'   => array('beer', 'wine', 'snacks')
                                );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM