我有点混乱的问题......正如你在下面的代码中看到的,我有一个array
,其中包含其他数组。它根据角色创建用户导航。导航项目是继承的,这是我的问题。我需要在最低角色'dokumenty'
中为关键EXPERT
设置值,而不应为角色REPORTER
和REFERENT
设置值,而不是{{1} }}。所以我正在分享EDITOR
和EXPERT
代码,我尝试删除REPORTER
的值,但是它在'dokumenty'
时给我一个错误......我会很高兴的任何帮助,如何使用array_merge()
键删除行。我想我不应该分享整个'dokumenty'
,因为它很长。
return
尝试 return array(
AuthRoleEnum::EXPERT => array(
'prehled' => array('order' => 1, 'href' => ':Dashboard:Default:default', 'label' => 'Prehled', 'ico' => 'fa fa-th-list'),
'pozemky' => array('order' => 3, 'href' => '#', 'label' => 'Pozemky', 'ico' => 'fa fa-flag-o', 'nodes' => array(
array('order' => 1, 'href' => ':Land:List:default', 'label' => 'Seznam pozemku', 'ico' => 'fa fa-flag-o'),
array('order' => 2, 'href' => ':Land:List:selected', 'label' => 'Muj vyber', 'ico' => 'fa fa-flag-o'),
)),
'mapa' => array('order' => 4, 'href' => ':Map:Default:default', 'label' => 'Mapa', 'ico' => 'fa fa-globe'),
'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
)),
),
AuthRoleEnum::REPORTER => array(
'dokumenty' => null,
'workflow' => array('order' => 20, 'href' => ':Construction:List:workflow', 'label' => 'Workflow', 'ico' => 'fa fa-cubes'),
),
AuthRoleEnum::REFERENT => array(
'stavby' => array('order' => 2, 'href' => ':Construction:List:default', 'label' => 'Stavby', 'ico' => 'fa fa-road', 'nodes' => [
['order' => 1, 'href' => ':Construction:List:default', 'label' => 'Seznam staveb', 'ico' => 'fa fa-road']
]),
'kontakty' => array('order' => 9, 'href' => ':Contact:List:default', 'label' => 'Kontakty', 'ico' => 'fa fa-user', 'nodes' => []),
'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
array('order' => 9, 'href' => ':Document:List:default', 'hrefArgs' => array('landId' => null), 'label' => 'Seznam dokumentu', 'ico' => 'fa fa-newspaper-o'),
)),
),
AuthRoleEnum::EDITOR => array(
'alarmy' => array('order' => 5, 'href' => '#', 'label' => 'Alarmy', 'ico' => 'fa fa-bell-o', 'nodes' => array(
array('order' => 6, 'href' => ':Alarm:List:default', 'label' => 'Seznam alarmu', 'ico' => 'fa fa-bell-o', 'class' => 'alarm-menu-field')
)),
'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
array('order' => 10, 'href' => ':InsertionCadastral:GenerateInsertion:list', 'label' => 'Pozadavky na vklad do KN', 'ico' => 'fa fa-cloud-upload'),
array('order' => 11, 'href' => ':Document:GenerateDocx:firstStep', 'label' => 'Generovani dokumentu', 'ico' => 'fa fa-pencil-square', 'class' => 'show-in-modal'),
array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
)),
'fronta' => array('order' => 15, 'href' => ':Queue:List:default', 'label' => '', 'ico' => 'fa fa-circle', 'class' => 'queue-menu-field'),
'pozemky' => array('order' => 3, 'href' => '#', 'label' => 'Pozemky', 'ico' => 'fa fa-flag-o', 'nodes' => array(
array('order' => 3, 'href' => ':Land:Comment:list', 'label' => 'Parcely s poznamkou', 'ico' => 'fa fa-flag-o'),
array('order' => 4, 'href' => ':BuildingObject:List:default', 'label' => '_T_MAIN_MENU_TITLE_BUILDING_OBJECT', 'ico' => 'fa fa-building')
)),
),
AuthRoleEnum::ADMIN => array(
'stavby' => array('order' => 2, 'href' => ':Construction:List:default', 'label' => 'Stavby', 'ico' => 'fa fa-road', 'nodes' => [
['order' => 2, 'href' => ':Construction:UserActivity:default', 'label' => 'Aktivita uzivatelu', 'ico' => 'fa fa-user']
]),
'system' => array('order' => 10, 'href' => '#', 'label' => 'System', 'ico' => 'fa fa-cog', 'nodes' => array(
array('order' => 4, 'href' => ':Setting:UserConstruction:default', 'label' => 'Sprava opravneni uzivatelu a staveb', 'ico' => 'fa fa-building-o'),
array('href' => ':Setting:User:default', 'label' => 'Uzivatelske ucty', 'ico' => 'fa fa-list')
)),
'alarmy' => array('order' => 5, 'href' => '#', 'label' => 'Alarmy', 'ico' => 'fa fa-bell-o', 'nodes' => array(
array('order' => 7, 'href' => ':Alarm:Edit:add', 'label' => 'Pridani alarmu', 'ico' => 'fa fa-pencil-square', 'class' => 'show-in-modal')
)),
),
AuthRoleEnum::SUPERADMIN => array(
'kontakty' => array('order' => 18, 'href' => '#', 'label' => 'Kontakty', 'ico' => 'fa fa-user', 'nodes' => array(
array('href' => ':Contact:List:default', 'label' => 'Kontakty', 'ico' => 'fa fa-folder'),
array('href' => ':ExpertReview:Contact:default', 'label' => 'Posudkari', 'ico' => 'fa fa-folder')
)),
'system' => array('order' => 11, 'href' => '#', 'label' => 'System', 'ico' => 'fa fa-list', 'nodes' => array(
array('href' => ':Setting:Selection:default', 'label' => 'Ciselniky', 'ico' => 'fa fa-list'),
array('href' => ':Setting:System:edit', 'label' => 'Zakladni parametry', 'ico' => 'fa fa-list', 'class' => 'show-in-modal', 'dataredirect' => 'false'),
array('href' => ':Setting:ConstructionGeneratedSelections:default', 'label' => 'Sablony generovanych dokumentu', 'ico' => 'fa fa-list'),
array('href' => ':Setting:ConstructionInsertedSelections:default', 'label' => 'Sablony vkladanych dokumentu', 'ico' => 'fa fa-list'),
array('href' => ':Setting:WsUsers:default', 'label' => 'Uzivatele webovych sluzeb', 'ico' => 'fa fa-credit-card'),
array('href' => ':Setting:UserLog:default', 'label' => 'Kompletni log', 'ico' => 'fa fa-h-square'),
array('href' => 'changeDebugMode!', 'label' => $debugModeLabel, 'ico' => 'fa fa-gears'),
array('href' => ':Setting:Changelog:list', 'label' => 'Changelog', 'ico' => 'fa fa-gears'),
)),
)
);
时出错:
'dokumenty' => null,
答案 0 :(得分:1)
解决了,我必须使用if
的简写,它才有用。
'dokumenty' => (($userRole[0] == "EXPERT") ? (array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'hidden' => 0, 'nodes' => array(
array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
))) : null),
),
答案 1 :(得分:0)
如果我理解你的权利比你想要从数组中移除Dokumentry键那么可以使用未设置的方法取消设置($ arrayName [' keyName']);
如果您只是想在该数组中取消设置Dokumentry的值,那么应该这样做:
$yourArray = array(
AuthRoleEnum::EXPERT => array(
'prehled' => array('order' => 1, 'href' => ':Dashboard:Default:default', 'label' => 'Prehled', 'ico' => 'fa fa-th-list'),
'pozemky' => array('order' => 3, 'href' => '#', 'label' => 'Pozemky', 'ico' => 'fa fa-flag-o', 'nodes' => array(
array('order' => 1, 'href' => ':Land:List:default', 'label' => 'Seznam pozemku', 'ico' => 'fa fa-flag-o'),
array('order' => 2, 'href' => ':Land:List:selected', 'label' => 'Muj vyber', 'ico' => 'fa fa-flag-o'),
)),
'mapa' => array('order' => 4, 'href' => ':Map:Default:default', 'label' => 'Mapa', 'ico' => 'fa fa-globe'),
'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
)),
),
AuthRoleEnum::REPORTER => array(
'dokumenty' => null,
'workflow' => array('order' => 20, 'href' => ':Construction:List:workflow', 'label' => 'Workflow', 'ico' => 'fa fa-cubes'),
));
unset($yourArray[AuthRoleEnum::REPORTER]['dokumenty'] );
return $yourArray;
或许你的问题可以通过使用null来解决,而不是使用qoutes''。
return array(
AuthRoleEnum::EXPERT => array(
'prehled' => array('order' => 1, 'href' => ':Dashboard:Default:default', 'label' => 'Prehled', 'ico' => 'fa fa-th-list'),
'pozemky' => array('order' => 3, 'href' => '#', 'label' => 'Pozemky', 'ico' => 'fa fa-flag-o', 'nodes' => array(
array('order' => 1, 'href' => ':Land:List:default', 'label' => 'Seznam pozemku', 'ico' => 'fa fa-flag-o'),
array('order' => 2, 'href' => ':Land:List:selected', 'label' => 'Muj vyber', 'ico' => 'fa fa-flag-o'),
)),
'mapa' => array('order' => 4, 'href' => ':Map:Default:default', 'label' => 'Mapa', 'ico' => 'fa fa-globe'),
'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
)),
),
AuthRoleEnum::REPORTER => array(
'dokumenty' => null,
'workflow' => array('order' => 20, 'href' => ':Construction:List:workflow', 'label' => 'Workflow', 'ico' => 'fa fa-cubes'),
),
如果这对您没有帮助,请提供完整的退货错误消息,并尝试更准确地定义您要做的事情。
此问题Warning: array_merge(): Argument #1 is not an array, when processing two $_POST
中解释了同样的错误