本文整理汇总了PHP中Category::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::model方法的具体用法?PHP Category::model怎么用?PHP Category::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
public function loadModel($id)
{
if (($model = Category::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($cat_id = null)
{
if (Yii::app()->user->checkAccess($this->id . '.' . $this->action->id)) {
$model = new PaymentType();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['PaymentType'])) {
$model->attributes = $_POST['PaymentType'];
$model->category_id = $cat_id;
if ($model->save()) {
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'success', 'div' => 'Payment Type successfully added.'));
exit;
} else {
// Yii::app()->user->setFlash('success', 'Payment Type added successfully!');
$this->redirect(Yii::app()->user->returnUrl);
}
}
}
// $model->category_id = $cat_id;
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $this->renderPartial('_form', array('model' => $model), true, true)));
exit;
} else {
$this->render('create', array('model' => $model, 'cat_name' => Category::model()->findByPk($cat_id)->getFullCategory()));
}
} else {
$this->accessDenied();
}
}
示例3: init
public function init()
{
// Yii::app()->theme = 'forum';
// Yii::app()->name = 'ifuckforum';
$this->isconfig = Sconfig::model()->find();
$this->controllerId = ucfirst($this->getId());
if (Yii::app()->user->getState('cplang')) {
Yii::app()->language = Yii::app()->user->getState('cplang');
}
//Yii::app()->language = 'en_us';
//print_r( Yii::app()->language);
if (Yii::app()->user->getState('scategory')) {
//print_r(Yii::app()->user->getState('scategory'));
} else {
$_scategory = Category::model()->findAll(array('select' => 'id,name'));
$__scategory = array();
foreach ($_scategory as $icat) {
$__scategory[$icat['id']]['id'] = $icat['name'];
}
unset($_scategory);
Yii::app()->user->setState('scategory', $__scategory);
}
if ($this->isconfig && $this->isconfig->is_oops) {
//echo "oops";
//exit;
}
if (!Yii::app()->user->isGuest) {
$this->iuser = User::model()->findByPk(Yii::app()->user->id);
}
}
示例4: run
public function run()
{
$inn = false;
$cat = Category::model()->with('categoryDescriptions')->find('categoryDescriptions.link=:link', array(':link' => $this->current));
if (!empty($cat)) {
$catName = $cat->getName();
$categories = $cat->categories;
if (empty($categories)) {
$categories = array($cat);
$inn = true;
}
//echo print_r($categories);
} else {
$catName = 'All';
$categories = Category::model()->findAll();
}
$products = array();
$nbrands = $brands = array();
foreach ($categories as $category) {
$products = array_merge($products, $category->products);
}
foreach ($products as $product) {
$nbrands[] = $product->manufacturer_id;
}
$nbrands = array_unique($nbrands, SORT_NUMERIC);
foreach ($nbrands as $nbrand) {
$manu = Manufacturer::model()->findByPk($nbrand);
if (!empty($manu)) {
$brands[$nbrand] = $manu->name;
}
}
//$brands = asort($brands);
$this->render('category_navigation', array('inn' => $inn, 'cat' => $cat, 'name' => $catName, 'categories' => $categories, 'products' => $products, 'brands' => $brands, 'current' => $this->current));
}
示例5: getAllCategories
private function getAllCategories()
{
$criteria = new CDbCriteria();
$criteria->order = "name asc";
$categories = Category::model()->findAll($criteria);
return $categories;
}
示例6: actionAdmin
public function actionAdmin($catPk, $opts = array())
{
$cat = Category::model()->findByPk($catPk);
$model = $this->loadModel($catPk, null, 'search');
$this->ajaxSetNextValue('published', $model, 'published', array(BaseDataType::PUBLISHED, BaseDataType::NOT_PUBLISHED));
$model->unsetAttributes(); // clear any default values
$model = $model->current($cat);
if (isset($_GET[get_class($model)]))
$model->attributes=$_GET[get_class($model)];
$opts['model'] = $model;
$opts['cat'] = $cat;
$opts['columns'] = array();
$opts = Y::hooks()->cmsAdminGetGridColumns($this, &$opts);
if (isset($_GET['ajax'])) {
$this->renderPartial('admingrid',$opts);
} else {
$this->render('admin',$opts);
}
}
示例7: actionEdit
public function actionEdit($id)
{
//var_dump($_POST);
if ($_POST && $id) {
if ($_POST['nest-act'] == 'create-parent' && $_POST['name_cat'] !== '') {
//echo '<script>alert("111")</script>';
$node = Category::model()->findByPk($id);
$category = new Category();
$category->name = CHtml::encode($_POST['name_cat']);
$category->appendTo($node);
//$this->actionIndex();
}
if ($_POST['nest-act'] == 'delete' && $id !== '11') {
$node = Category::model()->findByPk($id);
$node->deleteNode();
}
if ($_POST['nest-act'] == 'rename') {
$node = Category::model()->findByPk($id);
$node->name = CHtml::encode($_POST['name_cat']);
$node->saveNode();
}
header('Location: /category');
die;
}
$param = Category::model()->findByPk($id);
$this->render('edit', ['model' => $param]);
}
示例8: loadModel
private function loadModel($param = '')
{
$status = 'publish';
$criteria = new CDbCriteria();
$criteria->condition = "parent=0";
$this->_labels = Label::model()->findAll($criteria);
$this->_category = Category::model()->findAll($criteria);
$criteria->condition = "post_status =:status";
$criteria->params = array(':status' => $status);
if ($param == 'post') {
$criteria->order = "ID desc";
} elseif ($param == 'populer') {
$criteria->order = "post_hits desc";
} else {
$criteria->order = "ID desc";
}
foreach ($this->_labels as $label) {
if ($label->slug == $param) {
$criteria->with = array("labels");
$criteria->together = true;
$criteria->condition = "labels.slug='{$param}'";
$criteria->order = "ID desc";
}
}
foreach ($this->_category as $cat) {
if ($cat->slug == $param) {
$criteria->with = array("categories");
$criteria->together = true;
$criteria->condition = "categories.slug='{$param}'";
$criteria->order = "ID desc";
}
}
$dataProvider = new CActiveDataProvider('Post', array('criteria' => $criteria, 'pagination' => array('pageSize' => 10)));
return $dataProvider;
}
示例9: actions
public function actions()
{
if (!($limit = (int) $this->module->rssCount)) {
throw new CHttpException(404);
}
$criteria = new CDbCriteria();
$criteria->order = 'date DESC';
$criteria->params = array();
$criteria->limit = $limit;
$title = $this->yupe->siteName;
$description = $this->yupe->siteDescription;
$categoryId = (int) Yii::app()->getRequest()->getQuery('category');
if (!empty($categoryId)) {
$category = Category::model()->cache($this->yupe->coreCacheTime)->published()->findByPk($categoryId);
if (null === $category) {
throw new CHttpException(404);
}
$title = $category->name;
$description = $category->description;
$criteria->addCondition('category_id = :category_id');
$criteria->params[':category_id'] = $categoryId;
}
$data = News::model()->cache($this->yupe->coreCacheTime)->with('user')->published()->public()->findAll($criteria);
return array('feed' => array('class' => 'yupe\\components\\actions\\YFeedAction', 'data' => $data, 'title' => $title, 'description' => $description, 'itemFields' => array('author_object' => 'user', 'author_nickname' => 'nick_name', 'content' => 'short_text', 'datetime' => 'date', 'link' => '/news/news/show', 'linkParams' => array('title' => 'alias'), 'title' => 'title', 'updated' => 'change_date')));
}
示例10: actionView
public function actionView()
{
$pid = Yii::app()->request->getParam('pid');
$cid = Yii::app()->request->getParam('cid');
$id = Yii::app()->request->getParam('id');
$category = Category::model()->findByPk($pid);
if ($category->taxonomy_id == $this->root_id) {
$data = array();
$data['item'] = Content::model()->findbyPk($id);
if ($data['item']->category_id == $cid) {
$data['cat'] = Category::model()->findbyPk($data['item']->category_id);
$data['root_cat'] = Taxonomy::model()->findbyPk($data['cat']->taxonomy_id);
$this->title = $data['item']->title;
Content::model()->updateByPk($id, array('view' => $data['item']->view + 1));
$data['comment_model'] = Comment::model()->findAll(array('condition' => 'content_id = :cid and state = 1', 'params' => array(':cid' => $id)));
if ($data['item']->category_id != $cid) {
throw new CHttpException(404, 'PAGE NOT FOUND.');
}
$this->render('view', $data);
} else {
throw new CHttpException(404, 'PAGE NOT FOUND.');
}
} else {
throw new CHttpException(404, 'PAGE NOT FOUND.');
}
}
示例11: actionSubmitIdea
public function actionSubmitIdea()
{
$model = new SubmitIdeaForm();
$categories = CHtml::listData(Category::model()->findAll(), 'idCategory', 'category');
$truthOrDare = array('Truth' => 'Truth', 'Dare' => 'Dare');
$model->username = Yii::app()->user->name;
if (isset($_POST['SubmitIdeaForm'])) {
$model->attributes = $_POST['SubmitIdeaForm'];
if ($model->validate()) {
$type = strtolower($model->truthOrDare);
$modelTruthOrDare = new $type();
$modelTruthOrDare->idCategory = $model->idCategory;
$modelTruthOrDare->idUser = Yii::app()->user->getId();
$modelTruthOrDare->dateSubmit = date('Y-m-d, H:i:s');
$modelTruthOrDare->anonymous = $model->anonymous;
$modelTruthOrDare->{$type} = $model->idea;
if ($modelTruthOrDare->save()) {
Yii::app()->user->setFlash('submitIdea', 'Your idea has been submited and will be displayed on the website after validation of the Truth Or Dare Team!');
} else {
Yii::app()->user->setFlash('submitIdea', 'Sorry, there was a problem during the saving process..! Please try again...');
}
}
}
$this->render('submitIdea', array('model' => $model, 'truthOrDare' => $truthOrDare, 'categories' => $categories));
}
示例12: actionIndex
/**
* 分类页面默认控制器
*/
public function actionIndex()
{
$filter = Category::model()->parseFilter($_REQUEST);
$result = Category::model()->getCategoryProducts($filter);
if (empty($result) || empty($result['list']) || $result['count'] <= 0) {
$this->redirect('/?from=no_list');
//跳转到首页
}
$options = Category::model()->getCategoryOptions($filter);
$pages = '';
//正常分页信息
$pageShort = '';
//短分页信息
$urlStr = '/category/' . Common::instance()->getFormatUrl('category', $filter);
if ($result['count'] > 0) {
$pages = Common::instance()->get_page_list($result['count'], $filter['p'], $filter['limit'], $urlStr, 'category');
$pageShort = Common::instance()->get_page_short($result['count'], $filter['p'], $filter['limit'], $urlStr, 'category');
}
$cakeInfo = Category::model()->getCakeLine($filter['id']);
$userId = $this->user_id;
if ($userId) {
$result['list'] = Category::model()->getCategoryProductLikeStatus($userId, $result['list']);
}
$viewData = array();
$viewData['list'] = $result['list'];
$viewData['count'] = $result['count'];
$viewData['options'] = $options;
$viewData['filter'] = $filter;
$viewData['pages'] = $pages;
$viewData['pageShort'] = $pageShort;
$viewData['cakeInfo'] = $cakeInfo;
$this->render('category/index', $viewData);
}
示例13: run
public function run()
{
$criteria = new CdbCriteria();
$criteria->limit = $this->data('limit');
$criteria->offset = $this->data('offset');
$criteria->condition = "post_status='publish' AND (post_modified <= '" . date('Y-m-d H:i:s') . "' AND post_modified >= '" . $this->data('time') . "')";
$criteria->order = 'post_hits DESC';
if ($this->data('autoByTerm')) {
if (isset($_GET['id'])) {
$category = Category::model()->findByPK((int) $_GET['id']);
$label = Label::model()->findByPK((int) $_GET['id']);
$topic = Topic::model()->findByPK((int) $_GET['id']);
$tag = Tag::model()->findByPK((int) $_GET['id']);
if ($category != null) {
$criteria = $this->getCriteriaTerm('categories', $criteria);
} elseif ($label != null) {
$criteria = $this->getCriteriaTerm('labels', $criteria);
} elseif ($topic != null) {
$criteria = $this->getCriteriaTerm('topics', $criteria);
} elseif ($tag != null) {
$criteria = $this->getCriteriaTerm('tags', $criteria);
}
}
}
$model = Post::model()->findAll($criteria);
if ($model != null) {
$this->layout($model);
}
}
示例14: run
public function run()
{
parent::run();
$data = array();
$id_listen_cat = Category::model()->findAll("taxonomy_id = " . $this->_id_bai_hoc . " and state = 1");
$id_listen_cat_array = array();
foreach ($id_listen_cat as $k) {
$id_listen_cat_array[] = $k->id;
}
$id_news_cat = Category::model()->findAll("taxonomy_id = " . $this->_id__tintuc . " and state = 1");
$id_news_cat_array = array();
foreach ($id_news_cat as $k) {
$id_news_cat_array[] = $k->id;
}
$comment = Comment::model()->findAll(array("condition" => "state = 1", "limit" => 5, "order" => "id desc"));
$options = array();
$i = 0;
foreach ($comment as $k) {
$options[$i]['content'] = Content::model()->findByPk($k->content_id);
$options[$i]['category'] = Category::model()->findByPk($options[$i]['content']->category_id);
$options[$i]['parent'] = '';
if ($options[$i]['category']->parent != 0) {
$options[$i]['parent'] = Category::model()->findByPk($options[$i]['category']->parent);
}
$options[$i]['taxonomy'] = Taxonomy::model()->findByPk($options[$i]['category']->taxonomy_id);
$i++;
}
$data['comments'] = $comment;
$data['options'] = $options;
$data['news'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_news_cat_array) . ")", "limit" => 10, "order" => "id desc"));
$data['listen'] = Content::model()->findAll(array("condition" => "state = 1 and category_id in (" . implode(",", $id_listen_cat_array) . ")", "limit" => 10, "order" => "id desc"));
$this->render('news_lession_comment', $data);
}
示例15: actionIndex
public function actionIndex()
{
$product_id = intval($_REQUEST['id']);
$pInfo = Product::model()->getProductInfoById($product_id);
if (empty($pInfo)) {
$this->redirect('/?from=no_goods');
//跳转到首页
}
$brandInfo = '';
if ($pInfo['brand_id']) {
$brandInfo = Brand::model()->findByPk($pInfo['brand_id']);
}
$stock = Product::model()->getProductStock($product_id, $pInfo['is_multiple']);
$attrList = ProductAttributes::model()->getProductAttrNameList();
$extendAttrList = ProductExtend::model()->getProductExtendAttrs($product_id);
$is_like = Like::model()->getLikeStatus($this->user_id, $product_id);
$cake = Category::model()->getCakeLine($pInfo['cat_id']);
//获取商品的面包屑
$viewData = array();
$viewData['pInfo'] = $pInfo;
$viewData['brandInfo'] = $brandInfo;
$viewData['is_like'] = $is_like;
$viewData['cake'] = $cake;
$viewData['stock'] = $stock;
$viewData['attrList'] = $attrList;
$viewData['extendAttrList'] = $extendAttrList;
$this->render('item/index', $viewData);
}