我为 CakePHP 3.4.* 编写了一个插件。
该插件将检查是否已设置数据库配置,如果没有,则您可以通过 GUI 界面移动用户来设置数据库配置,就像 wordpress 一样。
该插件运行良好,但必须通过访问插件的 url 手动加载
http://example.com/installer/install
在目录installer
中调用InstallController
类的插件名称在哪里plugins/Installer/src/Controller/
现在我想自动检查它并在无法建立数据库连接时将用户重定向到安装界面。
为此,我在InstallController
插件的控制器中编写了一个函数
public function installationCheck() {
$db = ConnectionManager::get('default');
if(!$db->connect()) {
if(Configure::read('Database.installed') == true) {
$this->Flash->error(__("Database connection couldn't be established. Please, re-configure it to start the application"));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__("Please configure your database settings for working of your application"));
return $this->redirect(['action' => 'index']);
}
}
return true;
}
现在的问题。
/app/src/Controller/AppController.php
从主应用程序的文件中调用此方法的最简单方法是什么?