97
Продолжение приложения А
$deleted=Category::model()->findByPk($id);
$deleted->delete();
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
Yii::app()->end();
} else {
$this->redirect(CHtml::normalizeUrl(array('content/index')));
}
}
}
Листинг файла SiteController.php
class SiteController extends Controller
{
/**
* Declares class-based actions.
*/
public $menu_nav;
public $cats;
public function init()
{
$this->cats = MainCategory::model()->findAll();
//
$this->menu_nav['index'] = array('label' => 'Новинки', 'url' => array('site/index'));
//
foreach ($cats as $cat) {
//
$this->menu_nav[$cat->id] = array('label' => $cat->name, 'url' => array('site/index', 'cid' =>
$cat->id));
//
}
}
public function actions()
{
return array(
//
captcha action renders the CAPTCHA image displayed on the contact page
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
),
//
page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
);
}
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
$criteria = new CDbCriteria();
if(Yii::app()->getRequest()->getQuery('cid')){
$criteria->addCondition('`isVisible`=1 AND `cid`=:id');
$criteria->params = array(':id'=>Yii::app()->getRequest()->getQuery('cid'));
$count = Catalog::model()->count($criteria);;
$data['cat'] = Category::model()->findByPk(Yii::app()->getRequest()->getQuery('cid'));
$data['pages'] = new CPagination($count);
//
элементов на страницу