2022年Joomla.MVC组件开发教程 2.pdf
《2022年Joomla.MVC组件开发教程 2.pdf》由会员分享,可在线阅读,更多相关《2022年Joomla.MVC组件开发教程 2.pdf(19页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、本节标题:添加访问控制列表(ACL) ACL (Access Control List)的描述Each component has its own ACL. They can be described in an access.xml file located at the root of the admin folder. This file describes the ACL for the com_helloworld component in a different section. In this example, we have chosen to separate the dif
2、ferent ACL into two sections: components and messages. admin/access.xml 限制访问组件ACL的主要目的是限制对用户组的直接操作行为,第一个行为就是对组件本身的访问。修改入口文件:admin/helloworld.php名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 19 页 - - - - - - - - - authorise(core.manage, com_helloworld) return J
3、Error:raiseWarning(404, JText:_(JERROR_ALERTNOAUTHOR); / require helper file JLoader:register(HelloWorldHelper, dirname(_FILE_) . DS . helpers . DS . helloworld.php); / import joomla controller library jimport(ponent.controller); / Get an instance of the controller prefixed by HelloWorld $controller
4、 = JController:getInstance(HelloWorld); / Perform the Request task $controller-execute(JRequest:getCmd(task); / Redirect if set by the controller $controller-redirect(); 根据权限显示工具栏按钮为了使工具栏的按钮按照ACL显示,需要修改视图:admin/views/helloworlds/view.html.phpget(Items); $pagination = $this-get(Pagination); / Check f
5、or errors. if (count($errors = $this-get(Errors) JError:raiseError(500, implode(, $errors); return false; / Assign data to the view $this-items = $items; $this-pagination = $pagination; / Set the toolbar $this-addToolBar(); / Display the template parent:display($tpl); / Set the document $this-setDoc
6、ument(); /* * Setting the toolbar */ protected function addToolBar() /每个都加入了判断来控制显示与否 $canDo = HelloWorldHelper:getActions(); JToolBarHelper:title(JText:_(COM_HELLOWORLD_MANAGER_HELLOWORLDS), helloworld); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 19 页 - -
7、- - - - - - - if ($canDo-get(core.create) JToolBarHelper:addNew(helloworld.add, JTOOLBAR_NEW); if ($canDo-get(core.edit) JToolBarHelper:editList(helloworld.edit, JTOOLBAR_EDIT); if ($canDo-get(core.delete) JToolBarHelper:deleteList(, helloworlds.delete, JTOOLBAR_DELETE); if ($canDo-get(core.admin) J
8、ToolBarHelper:divider(); JToolBarHelper:preferences(com_helloworld); /* * Method to set up the document properties * * return void */ protected function setDocument() $document = JFactory:getDocument(); $document-setTitle(JText:_(COM_HELLOWORLD_ADMINISTRATION); 修改编辑视图如下:admin/views/helloworld/view.h
9、tml.phpget(Form); $item = $this-get(Item); $script = $this-get(Script); / Check for errors. if (count($errors = $this-get(Errors) JError:raiseError(500, implode(, $errors); return false; / Assign the Data $this-form = $form; $this-item = $item; $this-script = $script; / Set the toolbar $this-addTool
10、Bar(); / Display the template parent:display($tpl); / Set the document $this-setDocument(); /* * Setting the toolbar */ 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 19 页 - - - - - - - - - protected function addToolBar() JRequest:setVar(hidemainmenu, true); $u
11、ser = JFactory:getUser(); $userId = $user-id; $isNew = $this-item-id = 0; $canDo = HelloWorldHelper:getActions($this-item-id); JToolBarHelper:title($isNew ? JText:_(COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW) : JText:_(COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT), helloworld); / Built the actions for new and
12、existing records. if ($isNew) / For new records, check the create permission. if ($canDo-get(core.create) JToolBarHelper:apply(helloworld.apply, JTOOLBAR_APPLY); JToolBarHelper:save(helloworld.save, JTOOLBAR_SAVE); JToolBarHelper:custom(helloworld.save2new, save-new.png, save-new_f2.png, JTOOLBAR_SA
13、VE_AND_NEW, false); JToolBarHelper:cancel(helloworld.cancel, JTOOLBAR_CANCEL); else if ($canDo-get(core.edit) / We can save the new record JToolBarHelper:apply(helloworld.apply, JTOOLBAR_APPLY); JToolBarHelper:save(helloworld.save, JTOOLBAR_SAVE); / We can save this record, but check the create perm
14、ission to see 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 19 页 - - - - - - - - - / if we can return to make a new one. if ($canDo-get(core.create) JToolBarHelper:custom(helloworld.save2new, save-new.png, save-new_f2.png, JTOOLBAR_SAVE_AND_NEW, false); if ($c
15、anDo-get(core.create) JToolBarHelper:custom(helloworld.save2copy, save-copy.png, save-copy_f2.png, JTOOLBAR_SAVE_AS_COPY, false); JToolBarHelper:cancel(helloworld.cancel, JTOOLBAR_CLOSE); /* * Method to set up the document properties * * return void */ protected function setDocument() $isNew = $this
16、-item-id = 0; $document = JFactory:getDocument(); $document-setTitle($isNew ? JText:_(COM_HELLOWORLD_HELLOWORLD_CREATING) : JText:_(COM_HELLOWORLD_HELLOWORLD_EDITING); $document-addScript(JURI:root() . $this-script); $document-addScript(JURI:root() . /administrator/components/com_helloworld . /views
17、/helloworld/submitbutton.js); JText:script(COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 19 页 - - - - - - - - - 以上两个文件使用了admin/helpers/helloworld.php中定义的getActions方法。修改该文件如下admin/helpers/helloworld.phpaddStyleDecl
18、aration(.icon-48-helloworld . background-image: url(./media/com_helloworld/images/tux-48x48.png);); if ($submenu = categories) $document-setTitle(JText:_(COM_HELLOWORLD_ADMINISTRATION_CATEGORIES); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 19 页 - - - - - -
19、- - - /* * Get the actions */ public static function getActions($messageId = 0) jimport(joomla.access.access); $user = JFactory:getUser(); $result = new JObject; if (empty($messageId) $assetName = com_helloworld; else $assetName = com_helloworld.message.(int) $messageId; $actions = JAccess:getAction
20、s(com_helloworld, component); foreach ($actions as $action) $result-set($action-name, $user-authorise($action-name, $assetName); return $result; 在组件的首选项中添加许可设置因为我们是在组件中应用ACL控制,所以需要在组件层级上设置,这当然应该在首选项中修改。admin/config.xml JHIDE JSHOW 在权限表( assets table)中设置值为了给每条信息设置权限(asset ),我们需要做以下两件事:首先, core.edit之类
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Joomla.MVC组件开发教程 2022 Joomla MVC 组件 开发 教程
限制150内