/** * 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 the ID of the model to be loaded */ public function loadModel($id) { $model = FriendLink::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function getLink() { $cri = new CDbCriteria(array('order' => 'sort_order asc', 'limit' => '7')); $friendlink = FriendLink::model()->findAll($cri); return $friendlink; }
<?php $category = Category::model()->findByPk(107); $childs = $category->children()->findAll(); foreach ($childs as $child) { ?> <div class="row"> <div class="col-span-12 friend-link"> <ul> <li><?php echo $child->name; ?> </li> <?php $cri = new CDbCriteria(array('condition' => 'category_id = ' . $child->id, 'order' => 'link_id asc, sort_order asc')); $links = FriendLink::model()->findAll($cri); foreach ($links as $l) { ?> <li><?php echo CHtml::link($l->title, $l->url, array('target' => '_blank')); ?> </li> <?php } ?> </ul> </div> </div> <?php }
public function actionaddflink() { $model = new FriendLink; if(isset($_POST['FriendLink'])){ $model->title = $_POST['FriendLink']['title']; $model->url = $_POST['FriendLink']['url']; $model->updatetime = time(); if(empty($model->title) || empty($model->url)){ Yii::app()->user->setFlash('error','标题和链接必须填写!'); }else{ if($model->save()){ $this->redirect('/srbac/config/flink'); }else{ Yii::app()->user->setFlash('error','保存失败,请重试!'); } } } $this->render('addflink',array( 'model'=>$model, )); }