/** * @param CActiveRecord $model **/ public function getModelAttributes($model) { $result = array(); $attributes = $model->attributeLabels(); // UtilHelper::dump($attributes); foreach ($attributes as $key => $value) { $result[$value] = get_class($model) . '.findByPk.' . $key . '|pk=:id'; } return $result; }
/** * @static * @param CActiveRecord $model * @param array|string $columns can also passed from js ,if so you can use $_GET to retrive it * array('id','name') | 'id,name' 或者带别名 't.id,user.name....' * @param array $headers */ public static function export(CActiveRecord $model, $columns = array(), $headers = array()) { if (isset($_GET[self::$actionKey])) { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'CSVExport.php'; $provider = $model->search(); if (!empty($columns)) { $criteria = $provider->getCriteria(); $criteria->select = $columns; } $csv = new CSVExport($provider); if (!empty($headers)) { $csv->headers = $headers; } $csv->headers = $model->attributeLabels(); $csv->exportFull = false; //default use pagination if (!empty(self::$options)) { foreach (self::$options as $key => $value) { $csv->{$key} = $value; } } // echo var_export($provider->getCriteria()->toArray(),true); $content = $csv->toCSV(null, "\t", '"'); Yii::app()->getRequest()->sendFile(self::$fileName, $content, "text/csv", false); die; // exit; } /* else{ $actionKey = self::$actionKey; throw new CException("something wrog with your request,must contain the key '{$actionKey}' your get is: ".CJSON::encode($_GET) ); }*/ }
/** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array_merge(parent::attributeLabels(), array('id' => 'ID', 'parent_id' => 'Родитель', 'title' => 'Название', 'description' => 'Описание', 'listorder' => 'Порядок в списке', 'is_locked' => 'Заблокирован?', 'isCat' => 'Категория?')); }
/** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array_merge(parent::attributeLabels(), array('id' => 'ID', 'author_id' => 'Author', 'thread_id' => 'Thread', 'editor_id' => 'Editor', 'content' => 'Текст', 'created' => 'Дата создания', 'updated' => 'Дата обновления')); }
/** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array_merge(parent::attributeLabels(), array('id' => 'ID', 'forum_id' => 'Форум', 'subject' => 'Тема', 'is_sticky' => 'Прикреплена?', 'is_locked' => 'Закрыта?', 'view_count' => 'Кол. просмотров', 'created' => 'Дата создания')); }