2017-01-23 83 views
0

我有这样的代码在我看来如何限制redactor限制器插件上的max char?

<div class="col-xs-6"> 
     <?php echo $form->field($model, 'deskripsi_produk')->widget(Redactor::className(),['clientOptions'=>['autoresize'=>'true', 'limiter' => 20, 'plugins' => ['limiter'], 'buttons'=> ['html', 'formatting', 'bold', 'italic','underline','lists','horizontalrule'],]]);?> 
     </div> 

它可以限制20个字符,但如何限制文本区域的模型来代替具体的数量限制定义最大字符串?

这里是我的模型

class TbProduk extends \yii\db\ActiveRecord 
{ 
    /** 
    * @inheritdoc 
    */ 
    public $image; 
    public static function tableName() 
    { 
     return 'tb_produk'; 
    } 

public function rules() 
{ 
    return [ 
     ... 
     [['deskripsi_produk'], 'string', 'max' => 2000], 
     [['deskripsi_produk'], 'checkDesc'], 
     ... 
    ]; 
} 
} 
+0

哪里是在模型中定义的最大长度? – topher

+0

@topher问题已更新 –

回答

0

尝试通过rules得到的值是一个可怕的想法。相反,你应该创造TbProduk恒定,将举行长度:

class TbProduk extends \yii\db\ActiveRecord 
{ 
    const DESKRIPSI_PRODUK_LENGTH = 2000; 
    ... 
    public function rules() 
    { 
     return [ 
      ... 
      [['deskripsi_produk'], 'string', 'max' => static::DESKRIPSI_PRODUK_LENGTH], 
      ... 
     ]; 
    } 
} 

而在你的看法:

<div class="col-xs-6"> 
    <?php echo $form->field($model, 'deskripsi_produk')->widget(Redactor::className(),['clientOptions'=>['autoresize'=>'true', 'limiter' => TbProduk::DESKRIPSI_PRODUK_LENGTH, 'plugins' => ['limiter'], 'buttons'=> ['html', 'formatting', 'bold', 'italic','underline','lists','horizontalrule'],]]);?> 
</div>