请注意这里的安装和卸载方法。我正在编写用于创建表的代码。但我想将此安装方法称为自动安装的插件,它应该像pimcore doc建议的那样表现。
namespace Newsletter;
use Pimcore\API\Plugin as PluginLib;
use Pimcore\Db;
class Plugin extends PluginLib\AbstractPlugin implements PluginLib\PluginInterface
{
public function init()
{
parent::init();
// register your events here
// using anonymous function
\Pimcore::getEventManager()->attach("document.postAdd", function ($event) {
// do something
$document = $event->getTarget();
});
// using methods
\Pimcore::getEventManager()->attach("document.postUpdate", [$this, "handleDocument"]);
}
public function handleDocument($event)
{
// do something
$document = $event->getTarget();
}
public static function install()
{
$this->dbConnection = Db::getConnection();
$this->dbConnection->query("CREATE TABLE IF NOT EXISTS newsLetter(id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, cname VARCHAR(100) NOT NULL)");
return true;
}
public static function uninstall()
{
// implement your own logic here
$this->dbConnection->query("DROP TABLE newsLetter");
Db::close(); // closes connection
return true;
}
public static function isInstalled()
{
// implement your own logic here
return true;
}
}
答案 0 :(得分:0)
您应该实现isInstalled方法,并在该方法中检查表是否已创建,否则返回false。 然后,用户必须单击安装按钮才能实际触发安装。 由于您在isInstalled方法中返回true,因此系统永远不会触发安装。