如何修复 cakephp4 的 beforeSave 方法?

问题描述 投票:0回答:0

我正在按照 https://book.cakephp.org/4/en/tutorials-and-examples/cms/articles-controller.html 上的教程进行操作,并在添加此功能后:

public function beforeSave(EventInterface $event, $entity, $options)
{
    if ($entity->isNew() && !$entity->slug) {
        $sluggedTitle = Text::slug($entity->title);
        // trim slug to maximum length defined in schema
        $entity->slug = substr($sluggedTitle, 0, 191);
    }
}

我收到错误消息“找不到类“App\Model\Table\Text””。有谁知道如何解决这个问题? screenshot of the error

当我注释掉该函数时,即使根据教程,文章也能够保存,这不应该被允许,因为 slug 列不是 NULL。

php database cakephp cakephp-4.x
© www.soinside.com 2019 - 2024. All rights reserved.