0
我希望在我的更新頁面的taggable中設置默認值,但我無法做到!in yii2:如何在2 amigos/yii2-taggable-behavior中設置誹謗值
這是我在_form.php這個代碼
https://github.com/2amigos/yii2-taggable-behavior
<?=
$form->field($model, 'tags')->widget(SelectizeTextInput::className(), [
// calls an action that returns a JSON object with matched
// tags
'loadUrl' => ['tags/list'],
'options' => ['class' => 'form-control'],
'clientOptions' => [
'plugins' => ['remove_button'],
'valueField' => 'name',
'labelField' => 'name',
'searchField' => ['name'],
'create' => true,
],
])->hint('Use commas to separate tags')
?>
這是我的模型:
class Post extends \yii\db\ActiveRecord
{
public $category;
public $prime;
public $metaNames;
public $metaDec;
public $tags;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'post';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['menu', 'prime', 'slideshow', 'special', 'visit', 'deleted', 'active'], 'integer'],
[['name', 'summary', 'text', 'sutitr', 'reference', 'slug', 'menu', 'slideshow', 'special', 'visit', 'created', 'modified', 'deleted', 'active'], 'required'],
[['summary', 'tagDec', 'metaDec', 'tags', 'text', 'sutitr'], 'string'],
[['created', 'modified'], 'safe'],
['category', 'each', 'rule' => ['integer']],
[['tagNames'], 'safe'],
[['headline'], 'string', 'max' => 255],
[['name', 'reference'], 'string', 'max' => 100],
[['slug'], 'string', 'max' => 200],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
我想在更新頁面
我想設置靜態值!我不能忍受那個! – Saltern
然後你的代碼的形式是這樣的: '<?= $ form-> field($ model,'tags') - > widget(SelectizeTextInput :: className(),[ 'value'=>'some ,'static',value' 'loadUrl'=> ['tags/list'], 'options'=> ['class'=>'form-control'], 'clientOptions'=> ['plugins'=' > [ 'remove_button'], 'valueField'=> '名稱', '的labelField'=> '名稱', 'searchField'=> [ '名稱'], '創建'=>真, ] ('使用逗號分隔標籤') ?>' – vityapro
不!默認選定的值。在頁面打開時自動選擇一個標籤! – Saltern