當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Action::exportKey方法代碼示例

本文整理匯總了PHP中yii\base\Action::exportKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP Action::exportKey方法的具體用法?PHP Action::exportKey怎麽用?PHP Action::exportKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\Action的用法示例。


在下文中一共展示了Action::exportKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getMenuCurrent

 /**
  * @param \yii\base\Action $action
  * @param ActiveRecord $model
  * @param bool $horizontal
  * @param array $privs
  * @param array $defaultActions
  * @param array $confirms
  * @return array
  */
 public function getMenuCurrent(\yii\base\Action $action, $model, $horizontal, $privs, $defaultActions, $confirms)
 {
     $menu = [];
     $id = null;
     if (!$model->isNewRecord) {
         $id = $action instanceof Action ? $action->exportKey($model->getPrimaryKey(true)) : implode(';', $model->getPrimaryKey(true));
     }
     if ($privs['read'] && $defaultActions['history'] && (!$model->isNewRecord || $action->id === 'update') && $model->getBehavior('trackable') !== null) {
         $menu['history'] = ['label' => Yii::t('app', 'History of changes'), 'icon' => 'list-alt', 'url' => array_merge(['history', 'id' => $id], $this->getUrlParams('history', $id))];
     }
     if (!$horizontal && $model->isNewRecord) {
         return $menu;
     }
     if ($privs['update'] && ($horizontal || $action->id !== 'update')) {
         $menu['update'] = ['label' => Yii::t('app', 'Update'), 'icon' => 'pencil', 'url' => array_merge(['update', 'id' => $id], $this->getUrlParams('update', $id)), 'active' => $action->id === 'update' && !$model->isNewRecord];
     }
     if ($privs['read'] && $defaultActions['view'] && ($horizontal || $action->id !== 'view')) {
         $menu['view'] = ['label' => Yii::t('app', 'View'), 'icon' => 'eye-open', 'url' => array_merge(['view', 'id' => $id], $this->getUrlParams('view', $id)), 'linkOptions' => $action->id === 'view' ? [] : ['data-confirm' => $confirms['leave']], 'active' => $action->id === 'view'];
     }
     if ($privs['read'] && $defaultActions['print'] && ($horizontal || $action->id !== 'print')) {
         $menu['print'] = ['label' => Yii::t('app', 'Print'), 'icon' => 'print', 'url' => array_merge(['print', 'id' => $id, '_format' => 'pdf'], $this->getUrlParams('print', $id)), 'linkOptions' => $action->id === 'print' ? [] : ['data-confirm' => $confirms['leave']], 'active' => $action->id === 'print'];
     }
     if ($privs['delete']) {
         $menu['delete'] = ['label' => Yii::t('app', 'Delete'), 'icon' => 'trash', 'url' => array_merge(['delete', 'id' => $id], $this->getUrlParams('delete', $id)), 'linkOptions' => ['data-confirm' => $confirms['delete'], 'data-method' => 'post']];
     }
     if ($privs['toggle']) {
         $enabled = !$model->isNewRecord && $model->getIsEnabled();
         $menu['toggle'] = ['label' => $enabled ? Yii::t('app', 'Disable') : Yii::t('app', 'Enable'), 'icon' => $enabled ? 'ban' : 'reply', 'url' => array_merge(['toggle', 'id' => $id], $this->getUrlParams('toggle', $id)), 'linkOptions' => $enabled ? ['data-confirm' => $confirms['disable']] : []];
     }
     if (!$model->isNewRecord && class_exists('netis\\fsm\\components\\StateAction') && $model instanceof \netis\fsm\components\IStateful && $privs['state']) {
         $controllerActions = $this->owner->actions();
         $action = null;
         if (isset($controllerActions['state'])) {
             $action = Yii::createObject($controllerActions['state'], ['state', $this->owner]);
         }
         if ($action === null || !$action instanceof StateActionInterface) {
             $action = Yii::createObject(\netis\fsm\components\StateAction::className(), ['state', $this->owner]);
         }
         $transitions = $model->getTransitionsGroupedByTarget();
         $stateAttribute = $model->getStateAttributeName();
         $stateMenu = $action->getContextMenuItem('state', $transitions, $model, $model->{$stateAttribute}, [$this->owner, 'hasAccess'], $this->useDropDownMenuForTransitions);
         //if label is set then it's drop down menu
         //todo set active item for buttons
         if (isset($stateMenu['label']) && $action->id === 'state') {
             $stateMenu['active'] = true;
         }
         $menu = array_merge($menu, $stateMenu);
     }
     foreach ($menu as $key => $item) {
         if ($model->isNewRecord) {
             $menu[$key]['disabled'] = true;
         }
     }
     return $menu;
 }
開發者ID:netis-pl,項目名稱:yii2-crud,代碼行數:64,代碼來源:ActiveNavigation.php


注:本文中的yii\base\Action::exportKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。