| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 | <?phpnamespace backend\widgets;use yii\helpers\Html;class BoxField extends \yii\widgets\ActiveField{    public $collapsed = false;    public $options = [        'class' => 'box box-solid'    ];    public $headerOptions = [        'class' => 'box-header with-border'    ];    public $bodyOptions = [        'class' => 'box-body'    ];    public $footerOptions = [        'class' => 'box-footer small'    ];    public $template = "{header}\n{body}\n{footer}";    public function render($content = null)    {        if ($content === null) {            if (! isset($this->parts['{body}'])) {                $this->body();            }            if (! isset($this->parts['{header}'])) {                $this->header();            }            if (! isset($this->parts['{footer}'])) {                $this->footer();            }            $content = strtr($this->template, $this->parts);        } elseif (! is_string($content)) {            $content = call_user_func($content, $this);        }        return $this->begin() . "\n" . $content . "\n" . $this->end();    }    public function begin()    {        if($this->collapsed == true) {            $this->options["class"] .= " collapsed-box";        }        return parent::begin();    }    public function header($title = null, $options = [])    {        if ($title === false) { // 为false则不显示            $this->parts['{header}'] = '';            return $this;        }        $options = array_merge($this->headerOptions, $options);        $attribute = Html::getAttributeName($this->attribute);        if ($title !== null) {            $options['title'] = $title;        }        $title = isset($options['title']) ? $options['title'] : Html::encode($this->model->getAttributeLabel($attribute));        if($this->collapsed == true) {            $faclass= "fa-plus";        } else {            $faclass= "fa-minus";        }        $content = '<h3 class="box-title">' . $title . '</h3>                  <div class="box-tools pull-right">                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa '.$faclass.'"></i></button>                  </div>';        $this->parts['{header}'] = Html::tag("div", $content, $options);        return $this;    }    public function body($options = [])    {        $options = array_merge($this->bodyOptions, $options);        if (! isset($this->parts['{input}'])) {            $this->textInput();        }        $content = $this->parts['{input}'];        $this->parts['{body}'] = Html::tag("div", $content, $options);        return $this;    }    public function footer($options = [])    {        if (isset($options["hidden"])) {            $this->parts['{footer}'] = '';            return $this;        }        $options = array_merge($this->footerOptions, $options);        if (! isset($this->parts['{error}'])) {            $this->error();        }        $error = $this->parts['{error}'];        if (! isset($this->parts['{hint}'])) {            $this->hint(null);        }        $hint = $this->parts['{hint}'];        $this->parts['{footer}'] = Html::tag("div", $hint . "\n" . $error, $options);        return $this;    }}?>
 |