Cakephp 3回调方法未达到 [英] Cakephp 3 Callback method not reached

查看:74
本文介绍了Cakephp 3回调方法未达到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对afterDelete回调方法有疑问。我不能使用它们。

I have a problem with the afterDelete callback method. I can't use them.

在我的一个存储插件控制器中,我想删除一条记录,然后再做一些其他思考,但是未达到回调方法。我已经在afterDelete()回调方法中添加了一条日志消息来进行检查。

Inside one of my "Storages" plugin controllers I want to delete a record and after that I want to do some other thinks, but the callback method is not reached. I have checked this with adding a log message inside the afterDelete() callback method.

这是删除记录的控制器:

This is the controller where I removed a record:

namespace Storages\Controller;

class StoragecontainerBlocksController extends AppController {

   public function initialize() {
       parent::initialize();
       $this->loadComponent('RequestHandler');
   }

   public function ajaxDeleteBlockElement() {
       $this->autoRender = false;

       // load model
       $this->loadModel("StoragecontainerBlockElements");

       // get element id
       $elementId = $this->request->data('id');

       $this->request->allowMethod(['post', 'delete']);

       // delete element
       $storagecontainerBlockElement = $this->StoragecontainerBlockElements->get($elementId);
       $this->StoragecontainerBlockElements->delete($storagecontainerBlockElement);
   }
}

这是(模型)表,其中afterDelete回调定义为:

This is the (model) table where the afterDelete callback is defined:

  use Cake\Log\Log;
  class StoragecontainerBlockElementsTable extends Table {

   public function afterDelete(Event $event) {
       Log::debug('Got here');
   }
  }

更新:

当我在ajaxDeleteBlockElement函数中调试 Log :: debug($ this-> StoragecontainerBlockElements); 时,得到以下内容debug.log文件中的数组:

When I debugged Log::debug($this->StoragecontainerBlockElements); inside the ajaxDeleteBlockElement function I got the following array inside debug.log file:

2017-03-31 07:03:48 Debug: Cake\ORM\Table Object
(
    [registryAlias] => StoragecontainerBlockElements
    [table] => storagecontainer_block_elements
    [alias] => StoragecontainerBlockElements
    [entityClass] => \Cake\ORM\Entity
    [associations] => Array
        (
        )

    [behaviors] => Array
        (
        )

    [defaultConnection] => default
    [connectionName] => default

更新:

namespace Storages\Model\Table;

use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\Log\Log;

class StoragecontainerBlockElementsTable extends Table {

    public function initialize(array $config) {
       parent::initialize($config);
    }

    public function afterDelete(Event $event) {
       Log::debug('Got here');
    }
}


推荐答案

As在调试结果中可以看到, $ this-> StoragecontainerBlockElements 不是您想的那样,它是所谓的自动表或通用表 ,即 \Cake\ORM\Table 的实例,而不是其具体子类。

As can be seen in the debugging results, $this->StoragecontainerBlockElements is not what you thought it is, it is a so called "auto-table" or "generic table", that is, an instance of \Cake\ORM\Table instead of a concrete subclass thereof.

由于某种原因找不到/加载您的 StoragecontainerBlockElementsTable 类/文件,因此回退到 \Cake\ORM\Table 。可能是由于

Your StoragecontainerBlockElementsTable class/file cannot be found/loaded for some reason, hence the fallback to \Cake\ORM\Table. Might be caused by


  • 文件名,类名或名称空间中的错字

  • 或名称空间完全丢失(这不是您的问题)

  • 或该类位于插件中,并且您没有使用插件符号来加载它

  • 或文件权限不允许读取文件

  • 或文件丢失(未部署)

  • ...

  • a typo in the filename, classname, or the namespace
  • or the namespace is missing completely (it's not in your question)
  • or the class lives in a plugin, and you didn't used plugin notation for loading it
  • or the file permissions do not allow reading file
  • or the file is missing (not deployed)
  • ...

另请参见

这篇关于Cakephp 3回调方法未达到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆