我一直在开发 CI 应用程序,但遇到了一个问题。
我想完成以下任务,而不是使用 CronJob:
通常,当用户打开我的网站时,CodeIgniter 会在后台加载。当 CI 完成加载时,我想从我编写的模型中调用一个函数。我怎样才能完成这个任务?
(我不知道查看器会加载哪个 Controller ,因此我很困惑)
希望您理解我,我正在等待您的答复
最佳答案
我建议您阅读 Hooks 在 CodeIgniter 中。您可以指定希望钩子(Hook)在应用程序中的哪个点运行,并且根据您的描述,post_system
钩子(Hook)就是您所需要的。
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.
在钩子(Hook)定义中,您指定要运行的类和方法。
$hook['pre_controller'] = array(
'class' => 'MyClass',
'function' => 'Myfunction',
'filename' => 'Myclass.php',
'filepath' => 'hooks',
'params' => array('beer', 'wine', 'snacks')
);
关于php - CodeIgniter 加载时调用模型函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061601/