public function actionIndex($id) { $this->processPageRequest('page'); if ($dataStr = Yii::app()->request->getParam('data')) { if (!empty($dataStr)) { if ($id == null) { $id = 1; } $data = strtotime($dataStr); $criteria = new CDbCriteria(); $criteria->condition = 'category_id =:id AND status=2 AND DATE_FORMAT(FROM_UNIXTIME(created), "%Y%m%d")=:data'; $criteria->params = array(':data' => date('Ymd', $data), ':id' => $id); $model = CmsSetting::model()->findByPk(1); $prow = new CActiveDataProvider('CmsPage', array('criteria' => $criteria, 'pagination' => array('pageSize' => $model->ct_page, 'pageVar' => 'page'))); } } else { $category = CmsCategory::model()->findByPk($id); $criteria = new CDbCriteria(); $criteria->condition = 'status = 2 AND category_id =:id AND ' . 'created < :time'; $criteria->params = array(':id' => $id, ':time' => time()); $criteria->order = 'created DESC'; $model = CmsSetting::model()->findByPk(1); $prow = new CActiveDataProvider('CmsPage', array('criteria' => $criteria, 'pagination' => array('pageSize' => $model->ct_page, 'pageVar' => 'page'))); } if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('widget_ajax', array('category' => $category, 'data' => $prow)); Yii::app()->end(); } else { $this->render('index', array('category' => $category, 'data' => $prow, 'val' => $dataStr)); } }
//$id = array_rand(array_fill_keys(range('a','z'), null), 1); $id = NULL; Yii::app()->getClientScript()->registerScript('editorparam', 'window.KEDITOR_PARAM = "action=' . $action . '&id=' . $id . '"', CClientScript::POS_HEAD); $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'article-form', 'htmlOptions' => array('enctype' => 'multipart/form-data'), 'enableAjaxValidation' => false)); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <?php echo '<select id="CmsArticle_category_id" name="CmsArticle[CategoryID]">'; $category = CmsCategory::model()->findByPk(5); $descendants = $category->descendants()->findAll(); $level = 1; echo '<option value="">请选择分类</option>'; foreach ($descendants as $child) { $string = ' '; $string .= str_repeat(' ', $child->Level - $level); if ($child->isLeaf() && !$child->next()->find()) { $string .= ''; } else { $string .= ''; } $string .= '' . $child->Name; // echo $string; if (!$model->isNewRecord) { if ($model->CategoryID == $child->ID) {
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'cmscategory-form', 'enableAjaxValidation' => false)); ?> <p class="help-block">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); if (!$model->isNewRecord) { $category_check = CmsCategory::model()->findByPk($model->ID); $parent = $category_check->parent()->find(); } echo '<select id="CmsCategory_node" name="CmsCategory[node]">'; $descendants = CmsCategory::model()->findAll(array('condition' => 'Root=1', 'order' => 'Lft')); $level = 1; foreach ($descendants as $child) { $string = ' '; $string .= str_repeat(' ', 2 * ($child->Level - $level)); // if ($child->isLeaf() && !$child->next()->find()) { // $string .= ' '; // } else { // // $string .= ''; // } $string .= $child->Name; // echo $string; if (!$model->isNewRecord) { if ($parent->ID == $child->ID) { $selected = 'selected'; echo '<option value="' . $child->ID . '" selected="' . $selected . '">' . $string . '</option>';
<?php echo '<select id="SettingsForm_menu_' . $key . '" name="SettingsForm[menu][' . $key . ']">'; $menu = CmsCategory::model()->roots()->findAll(); $level = 1; echo '<option value="0">请选择分类</option>'; foreach ($menu as $n => $m) { if ($val) { if ($val == $m->ID) { $selected = 'selected'; echo '<option value="' . $m->ID . '" selected="' . $selected . '">' . $m->Name . '</option>'; } else { echo '<option value="' . $m->ID . '">' . $m->Name . '</option>'; } } else { echo '<option value="' . $m->ID . '">' . $m->Name . '</option>'; } $children = $m->descendants()->findAll(); foreach ($children as $child) { $string = ' '; $string .= str_repeat(' ', 2 * ($child->Level - $level)); $string .= $child->Name; if ($val) { if ($val == $child->ID) { $selected = 'selected'; echo '<option value="' . $child->ID . '" selected="' . $selected . '">' . $string . '</option>'; } else { echo '<option value="' . $child->ID . '" >' . $string . '</option>'; } } else { echo '<option value="' . $child->ID . '" >' . $string . '</option>';
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return CmsCategory the loaded model * @throws CHttpException */ public function loadModel($id) { $model = CmsCategory::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }