1

I follow Programming with YII2 tutorial on tuts+ but when I finish chapter Programming With Yii2: Sluggable Behavior and try to visit /status/ page i see next error message error message

Model where i connect to SluggableBehavior

namespace app\models;

use Yii;
use yii\behaviors\SluggableBehavior;


class Status extends \yii\db\ActiveRecord
{
    const PERMISSIONS_PRIVATE = 10;
    const PERMISSIONS_PUBLIC = 20;

    public function behaviors()
    {
        return [
            [
                'class' => SluggableBehavior::className(),
                'attribute' => 'message',
                // 'slugAttribute' => 'slug',
            ],
        ];
    }
    . . .

What i'm doing wrong? I read definitive guide and example of usage in SluggableBehavior class in yii2 directory, but not found anything special.

4

2 に答える 2

3

yii2 とスラッグ可能な動作に関するドキュメントとフォーラムを数時間読んだ後、必要なものを見つけました。

valueプロパティを指定すると、すべて正常に動作します。

'value' => function($event){
    if(!empty($event->sender->slug))
        return $event->sender->slug;
    return Inflector::slug($event->sender->title);
},
于 2015-06-28T14:16:08.597 に答える