class ArticlesTable extends Table
{
public function initialize(array $config): void
{
$this->addBehavior('Timestamp');
$this->belongsToMany('Tags');
$this->hasOne('Users');
}
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);
}
}
}
1条答案
按热度按时间q3aa05251#
我的目标是在发布文章的用户电子邮件中添加一行。
articlescontroller.php
我的模板/articles/index.php
my articlestable.php