本文整理汇总了PHP中MenuItem::model方法的典型用法代码示例。如果您正苦于以下问题:PHP MenuItem::model方法的具体用法?PHP MenuItem::model怎么用?PHP MenuItem::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItem
的用法示例。
在下文中一共展示了MenuItem::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
if (empty($this->template)) {
return;
}
$url = trim(Yii::app()->request->url, '/');
$items = MenuItem::model()->onSite()->byParent(0)->byMenuId($this->menuId)->orderDefault()->findAll();
$itemsArr = array();
foreach ($items as $item) {
// Убираем язык из урла
$domains = explode('/', ltrim($url, '/'));
if (in_array($domains[0], array_keys(Yii::app()->params['languages']))) {
array_shift($domains);
$url = implode('/', $domains);
}
$select = strpos($url, trim($item->link, '/')) === 0 ? true : false;
$blank = 0;
if (strpos($item->link, 'http://') === 0 || strpos($item->link, 'https://') === 0) {
$link = $item->link;
$blank = 1;
} else {
$link = isset(Yii::app()->params['routes'][$item->link]) ? array('/' . Yii::app()->params['routes'][$item->link]) : '/' . $item->link;
// Ссылка без языка, будет вести на дефолтную страницу
$link = CHtml::normalizeUrl($link);
}
$iconUrl = $item->getIconUrl();
$itemsArr[] = array('name' => $item->name, 'link' => $link, 'select' => $select, 'iconUrl' => $iconUrl, 'blank' => $blank, 'enabled' => $item->active);
}
$this->beforeRender($itemsArr);
$this->render($this->template, array('items' => $itemsArr));
}
示例2: actionView
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id = null, $path = null)
{
//if path is given, find the content_id from the menu item
if ($path) {
$Content = Content::model()->findByAttributes(array('path' => $path));
} else {
$Content = $this->loadModel($id);
}
$Content = $this->loadModel($id);
$MI = MenuItem::model()->findByAttributes(array('content_id' => $Content->id));
if (!Yii::app()->user->checkAccess('Update Content')) {
$today = new DateTime();
$publish_on = new DateTime($Content->publish_on);
$unpublish_on = new DateTime($Content->unpublish_on);
if (!$Content->published || $publish_on > $today || $unpublish_on < $today) {
throw new CHttpException(403, Yii::t('yii', 'You are not authorized to perform this action.'));
}
}
//$this->layout = '//layouts/column1';
$view = 'view';
if ($this->getLayoutFile('//layouts/content_types/' . $Content->type)) {
$this->layout = '//layouts/content_types/' . $Content->type;
}
if ($this->getViewFile($Content->type)) {
$view = $Content->type;
}
$this->meta_keywords = CHtml::value($Content, 'meta_keywords');
$this->meta_description = CHtml::value($Content, 'meta_description');
$this->meta_author = CHtml::value($Content, 'UserCreated.full_name');
//Used by the admin bar
$this->Content = $Content;
$this->render($view, array('Content' => $Content, 'MenuItem' => $MI));
}
示例3: loadModel
/**
* Возвращает модель по указанному идентификатору
* Если модель не будет найдена - возникнет HTTP-исключение.
*
* @param integer идентификатор нужной модели
*
* @return void
*
* @throws CHttpException If MenuItem record not found
*/
public function loadModel($id)
{
if (($model = MenuItem::model()->findByPk($id)) === null) {
throw new CHttpException(404, Yii::t('MenuModule.menu', 'Page was not found!'));
}
return $model;
}
示例4: loadModel
public function loadModel($id)
{
if (($model = MenuItem::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例5: deleteMenu
protected function deleteMenu($menuId)
{
$menuItems = MenuItem::model()->findAllByAttributes(array('menuId' => $menuId));
foreach ($menuItems as $item) {
$item->delete();
}
Menu::model()->deleteByPk($menuId);
}
示例6: getMenuItems
public static function getMenuItems($parent_id, $menu_id)
{
$menu_items = MenuItem::model()->findAll(array('condition' => 'parent=:pid AND menu_id=:mid', 'params' => array(':pid' => $parent_id, ':mid' => $menu_id), 'order' => ' t.order ASC '));
$result = array();
foreach ($menu_items as $menu_item) {
$result[] = array('name' => $menu_item->name, 'link' => self::buildLink($menu_item), 'id' => $menu_item->menu_item_id);
}
return $result;
}
示例7: getSubItems
protected function getSubItems($item_id)
{
$dependencia = new CDbCacheDependency("SELECT GREATEST(MAX(creado), MAX(modificado)) FROM menuItem WHERE estado = 1");
$c = new CDbCriteria();
$c->addCondition('t.estado <> 0');
$c->order = 't.orden ASC';
$menu_items = MenuItem::model()->cache(21600, $dependencia)->findAllByAttributes(array('item_id' => $this->id), $c);
return $menu_items ? $menu_items : false;
}
示例8: up
public function up()
{
Yii::app()->getModule('menu');
$Menu = Menu::model()->findByAttributes(['code' => 'top-menu-cabinet']);
$menuItems = $Menu->menuItems(['condition' => 'href=:href', 'params' => ['href' => '/cabinet/deal']]);
if (!is_null($menuItems) && count($menuItems)) {
$menuItem = $menuItems[0];
MenuItem::model()->deleteByPk($menuItem->id);
}
}
示例9: parseUrl
public function parseUrl($request)
{
$path = '/' . Yii::app()->request->pathInfo;
$MI = MenuItem::model()->findByAttributes(array('path' => $path));
if ($MI && $MI->content_id) {
$route = 'content/view/id/' . $MI->content_id;
} else {
$route = parent::parseUrl($request);
}
return lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route))));
}
示例10: safeDown
public function safeDown()
{
if (Yii::app()->hasModule('menu')) {
Yii::import('application.modules.menu.models.*');
Yii::import('application.modules.menu.MenuModule');
$item = MenuItem::model()->find('href = :href', [':href' => '/store/product/index']);
if ($item !== null) {
$item->delete();
}
}
}
示例11: safeUp
public function safeUp()
{
if (Yii::app()->hasModule('menu')) {
Yii::import('application.modules.menu.models.*');
Yii::import('application.modules.menu.MenuModule');
$item = MenuItem::model()->find('href = :href', [':href' => '/store/catalog/index']);
if (null !== $item) {
$item->href = '/store/product/index';
$item->save();
}
}
}
示例12: getMenuItemFromMenu
public static function getMenuItemFromMenu($menu_id, $render = true)
{
$menus = MenuItem::model()->findAll('menu_id = :id', array(':id' => $menu_id));
$data = array(0 => t('cms', "None"));
if ($menus && count($menus) > 0) {
$data = CMap::mergeArray($data, CHtml::listData($menus, 'menu_item_id', 'name'));
}
if ($render) {
foreach ($data as $value => $name) {
echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
}
} else {
return $data;
}
}
示例13: beforeDelete
protected function beforeDelete()
{
try {
foreach ($this->menuItems as $menuItem) {
$mi = MenuItem::model()->findByPk($menuItem->id);
$mi->delete();
}
foreach ($this->micrositios as $micrositio) {
$m = $micrositio->findByPk($micrositio->id);
$m->menu_id = NULL;
$m->save();
}
return parent::beforeDelete();
} catch (Exception $e) {
return false;
}
}
示例14: actionView
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id = null, $path = null)
{
if ($path) {
$MI = MenuItem::model()->findByAttributes(array('path' => $path));
$id = $MI ? $MI->content_id : null;
}
$Content = $this->loadModel($id);
$this->layout = '//layouts/column1';
$view = 'view';
if ($this->getLayoutFile('//layouts/content_types/' . $Content->type)) {
$this->layout = '//layouts/content_types/' . $Content->type;
}
if ($this->getViewFile('content_types/' . $Content->type)) {
$view = 'content_types/' . $Content->type;
}
$this->render($view, array('Content' => $Content));
}
示例15: actionSave
public function actionSave()
{
foreach ($_POST['list'] as $item) {
print_r($_POST);
if ($item['item_id'] == 'root') {
continue;
}
if ($item['parent_id'] == "root") {
$item['parent_id'] = "0";
}
$menuItem = MenuItem::model()->findByPk($item['item_id']);
$menuItem->parent = $item['parent_id'];
$menuItem->depth = $item['depth'];
$menuItem->lft = $item['left'];
$menuItem->rgt = $item['right'];
$menuItem->save();
}
}