Symfony1 如何在管理生成器中重写processForm()
我正试图为任务Symfony1 如何在管理生成器中重写processForm(),symfony1,symfony-1.4,Symfony1,Symfony 1.4,我正试图为任务条令:生成管理员生成的模块中的更新和删除操作添加一些额外的逻辑。我阅读并发现我可以在/application/mymodule/actions/actions.class.php中创建executeUpdate()和executelet()方法。因为executeUpdate()调用processform()方法,所以我认为最好的方法是重写它,而不是executeUpdate(),但不知道如何重写。我需要添加的代码如下: $q = Doctrine_Core::getTable('
条令:生成管理员生成的模块中的更新
和删除
操作添加一些额外的逻辑。我阅读并发现我可以在/application/mymodule/actions/actions.class.php
中创建executeUpdate()
和executelet()
方法。因为executeUpdate()
调用processform()
方法,所以我认为最好的方法是重写它,而不是executeUpdate()
,但不知道如何重写。我需要添加的代码如下:
$q = Doctrine_Core::getTable('SdrivingEmpresa')
->createQuery('a')
->where('idempresa = ?', $request->getParameter('idempresa'))
->execute();
$file = new sfFilesystem();
$file->remove(sfConfig::get('sf_upload_dir') . '/' . $q[0]->getLogotipo());
我通过复制生成的已编码缓存并写入我的逻辑来为ExecuteElete()
执行此操作,请参见下文:
public function executeDelete(sfWebRequest $request) {
$request->checkCSRFProtection();
$this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $this->getRoute()->getObject())));
$q = Doctrine_Core::getTable('SdrivingEmpresa')
->createQuery('a')
->where('idempresa = ?', $request->getParameter('idempresa'))
->execute();
$file = new sfFilesystem();
$file->remove(sfConfig::get('sf_upload_dir') . '/' . $q[0]->getLogotipo());
if ($this->getRoute()->getObject()->delete()) {
$this->getUser()->setFlash('notice', 'The item was deleted successfully.');
}
$this->redirect('@sdriving_empresa');
}
但我认为这是不对的,所以我的问题是,我应该对processForm()也这样做,还是有更好的方法来做到这一点?任何建议或帮助?您可以在管理模块操作中复制在应用程序缓存中生成的过程表单()
,以覆盖它。您应该使用模型对象上可用的生命周期事件。您可以添加诸如preDelete
,postDelete
,preUpdate
,postapdate
,preSave
,postSave
,preInsert
,postInsert
。您可以添加任何应该与给定事件关联的逻辑。