BaseCWidget::init PHP Method

init() public method

public init ( )
    public function init()
    {
        if (is_object($this->element) && $this->field) {
            $this->value = $this->element->{$this->field};
        }
        // if the widget has javascript, load it in
        if (file_exists('protected/widgets/js/' . get_class($this) . '.js')) {
            $assetManager = Yii::app()->getAssetManager();
            $asset_folder = $assetManager->publish('protected/widgets/js');
            $assetManager->registerScriptFile('js/' . get_class($this) . '.js', 'application.widgets', $this->scriptPriority);
        }
        $this->htmlOptions['autocomplete'] = Yii::app()->params['html_autocomplete'];
    }

Usage Example

コード例 #1
0
 public function init()
 {
     $model = $this->model;
     if (!$this->extra_fields) {
         $this->extra_fields = array();
     }
     if (empty($_POST['id'])) {
         $this->data = $model::model()->findAll(array('order' => 'display_order asc'));
     } else {
         $this->data = array();
         foreach ($_POST['id'] as $i => $id) {
             $item = new $model();
             $item->id = $id;
             $item->name = $_POST['name'][$i];
             $attributes = $item->getAttributes();
             if (array_key_exists('active', $attributes)) {
                 $item->active = isset($_POST['active'][$i]) || intval($id) == 0 ? 1 : 0;
             }
             foreach ($this->extra_fields as $field) {
                 $item->{$field['field']} = $_POST[$field['field']][$i];
             }
             $this->data[] = $item;
         }
     }
     return parent::init();
 }
All Usage Examples Of BaseCWidget::init