当前位置: 首页>>代码示例>>PHP>>正文


PHP MenuItem::setAttributes方法代码示例

本文整理汇总了PHP中MenuItem::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP MenuItem::setAttributes方法的具体用法?PHP MenuItem::setAttributes怎么用?PHP MenuItem::setAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MenuItem的用法示例。


在下文中一共展示了MenuItem::setAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 public function actionCreate()
 {
     $model = new MenuItem();
     if (isset($_POST['MenuItem'])) {
         $model->setAttributes($_POST['MenuItem']);
         if (isset($_POST['MenuItem']['menu'])) {
             $model->menu = $_POST['MenuItem']['menu'];
         }
         if (isset($_POST['MenuItem']['parent'])) {
             $model->parent = $_POST['MenuItem']['parent'];
         }
         $model->link = $_POST['MenuItem'][$_POST['MenuItem']['type']];
         if (isset($_POST['MenuItem']['role'])) {
             $model->role = implode(',', $_POST['MenuItem']['role']);
         } else {
             $model->role = '';
         }
         //pushing newly added item to last
         $maxRight = $model->getMaxRight();
         $model->lft = $maxRight + 1;
         $model->rgt = $maxRight + 2;
         try {
             if ($model->save()) {
                 $this->redirect(array('/' . $this->module->id . '/item/index', 'id' => $model->menu_id, 'activeId' => $model->id));
             }
         } catch (Exception $e) {
             $model->addError('', $e->getMessage());
         }
     } elseif (isset($_GET['MenuItem'])) {
         $model->attributes = $_GET['MenuItem'];
     }
     $this->render('create', array('model' => $model, 'menuId' => key($_GET)));
 }
开发者ID:awecode,项目名称:awecms,代码行数:33,代码来源:ItemController.php

示例2: actionDynamicParent

 /**
  * Обновление дерева пунктов меню в завимости от родителя.
  *
  * @return void
  */
 public function actionDynamicParent()
 {
     if (Yii::app()->getRequest()->getIsAjaxRequest() && ($data = Yii::app()->getRequest()->getParam('MenuItem')) !== null) {
         $model = new MenuItem('search');
         $model->setAttributes($data);
         if ($model->menu_id) {
             if (isset($_GET['id'])) {
                 $model->id = $_GET['id'];
             }
             $data = $model->parentTree;
             foreach ($data as $value => $name) {
                 echo CHtml::tag('option', array('value' => $value), $name, true);
             }
         }
     }
     Yii::app()->end();
 }
开发者ID:kuzmina-mariya,项目名称:unizaro-kamin,代码行数:22,代码来源:MenuitemBackendController.php

示例3: createMenu

 protected function createMenu($menuArr, $items)
 {
     $menu = new Menu();
     $menu->multilang();
     $attr = array('name' => $menuArr['name']);
     foreach (Yii::app()->params['languages'] as $lang => $langName) {
         $attr['name_' . $lang] = $menuArr['name_' . $lang];
     }
     $menu->setAttributes($attr);
     $menu->id = $menuArr['id'];
     $menu->save();
     $orderNum = 1;
     foreach ($items as $item) {
         $menuItem = new MenuItem();
         $menuItem->multilang();
         $attr = array('menuId' => $menuArr['id'], 'name' => $item['name'], 'link' => $item['link'], 'orderNum' => $orderNum++, 'active' => 1, 'visible' => 1);
         foreach (Yii::app()->params['languages'] as $lang => $langName) {
             $attr['name_' . $lang] = $item['name_' . $lang];
         }
         $menuItem->setAttributes($attr);
         $menuItem->save();
     }
 }
开发者ID:DarkAiR,项目名称:test,代码行数:23,代码来源:ExtendedDbMigration.php

示例4: addItem

 /**
  * Добавляет новый пункт меню в меню
  * @param $title string - Заголовок
  * @param $href string - Ссылка
  * @param $parentId int - Родитель
  * @param bool $regularLink - Обычная ссылка
  * @return bool
  */
 public function addItem($title, $href, $parentId, $regularLink = false)
 {
     $menuItem = new MenuItem();
     $menuItem->setAttributes(['parent_id' => (int) $parentId, 'menu_id' => $this->id, 'title' => $title, 'href' => $href, 'regular_link' => $regularLink]);
     if (true === $menuItem->save()) {
         Yii::app()->getCache()->clear(['menu', $this->code]);
         return true;
     }
     return false;
 }
开发者ID:yupe,项目名称:yupe,代码行数:18,代码来源:Menu.php

示例5: actionDynamicParent

 /**
  * @throws CHttpException
  */
 public function actionDynamicParent()
 {
     if (!Yii::app()->getRequest()->getIsAjaxRequest()) {
         throw new CHttpException(404);
     }
     $model = new MenuItem('search');
     $model->setAttributes(Yii::app()->getRequest()->getParam('MenuItem'));
     if ($model->menu_id) {
         $model->id = Yii::app()->getRequest()->getQuery('id');
         $data = $model->getParentTree();
         foreach ($data as $value => $name) {
             echo CHtml::tag('option', ['value' => $value], $name, true);
         }
     }
     Yii::app()->end();
 }
开发者ID:yupe,项目名称:yupe,代码行数:19,代码来源:MenuitemBackendController.php


注:本文中的MenuItem::setAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。