欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    2022年Joomla.MVC组件开发教程 2.pdf

    • 资源ID:27266212       资源大小:215.30KB        全文页数:19页
    • 资源格式: PDF        下载积分:4.3金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要4.3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    2022年Joomla.MVC组件开发教程 2.pdf

    本节标题:添加访问控制列表(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 different ACL into two sections: components and messages. admin/access.xml 限制访问组件ACL的主要目的是限制对用户组的直接操作行为,第一个行为就是对组件本身的访问。修改入口文件:admin/helloworld.php名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 19 页 - - - - - - - - - authorise(core.manage, com_helloworld) return JError: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 = 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 for 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-setDocument(); /* * Setting the toolbar */ protected function addToolBar() /每个都加入了判断来控制显示与否 $canDo = HelloWorldHelper:getActions(); JToolBarHelper:title(JText:_(COM_HELLOWORLD_MANAGER_HELLOWORLDS), helloworld); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 19 页 - - - - - - - - - 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) JToolBarHelper: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.html.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-addToolBar(); / Display the template parent:display($tpl); / Set the document $this-setDocument(); /* * Setting the toolbar */ 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 19 页 - - - - - - - - - protected function addToolBar() JRequest:setVar(hidemainmenu, true); $user = 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 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_SAVE_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 permission 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 ($canDo-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-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/helloworld/submitbutton.js); JText:script(COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 19 页 - - - - - - - - - 以上两个文件使用了admin/helpers/helloworld.php中定义的getActions方法。修改该文件如下admin/helpers/helloworld.phpaddStyleDeclaration(.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 页 - - - - - - - - - /* * 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:getActions(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之类的 ACL 权限是从信息本身而不是从组件中提取出来的,。admin/models/helloworld.php名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 19 页 - - - - - - - - - authorise(core.edit, com_helloworld.message. (int) isset($data$key) ? $data$key : 0) or parent:allowEdit($data, $key); /* * Returns a reference to the a Table object, always creating it. * * param type The table type to instantiate * param string A prefix for the table class name. Optional. * param array Configuration array for model. Optional. * return JTable A database object * since 2.5 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 19 页 - - - - - - - - - */ public function getTable($type = HelloWorld, $prefix = HelloWorldTable, $config = array() return JTable:getInstance($type, $prefix, $config); /* * Method to get the record form. * * param array $data Data for the form. * param boolean $loadData True if the form is to load its own data (default case), false if not. * return mixed A JForm object on success, false on failure * since 2.5 */ public function getForm($data = array(), $loadData = true) / Get the form. $form = $this-loadForm(com_helloworld.helloworld, helloworld, array(control = jform, load_data = $loadData); if (empty($form) return false; return $form; /* * Method to get the script that have to be included on the form * * return string Script files */ public function getScript() return administrator/components/com_helloworld/models/forms/helloworld.js; /* * Method to get the data that should be injected in the form. * * return mixed The data for the form. 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 19 页 - - - - - - - - - * since 2.5 */ protected function loadFormData() / Check the session for previously entered form data. $data = JFactory:getApplication()-getUserState(com_helloworld.edit.helloworld.data, array(); if (empty($data) $data = $this-getItem(); return $data; 其次,在 helloworld表中设置权限的 name 、title和 parent (父权限)admin/tables/helloworld.phploadArray($arrayparams); $arrayparams = (string)$parameter; return parent:bind($array, $ignore); /* * Overloaded load function * * param int $pk primary key * param boolean $reset reset data * return boolean * see JTable:load */ public function load($pk = null, $reset = true) if (parent:load($pk, $reset) / Convert the params field to a registry. $params = new JRegistry; $params-loadJSON($this-params); $this-params = $params; return true; else return false; /* 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 19 页 - - - - - - - - - * Method to compute the default name of the asset. * The default name is in the form table_name.id * where id is the value of the primary key of the table. * * return string * since 2.5 */ protected function _getAssetName() $k = $this-_tbl_key; return com_helloworld.message.(int) $this-$k; /* * Method to return the title to use for the asset table. * * return string * since 2.5 */ protected function _getAssetTitle() return $this-greeting; /* * Get the parent asset id for the record * * return int * since 2.5 */ protected function _getAssetParentId() $asset = JTable:getInstance(Asset); $asset-loadByName(com_helloworld); return $asset-id; 扩展阅读关于 actions, assets and ACL 更多的信息可以从以下教程中获取:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共 19 页 - - - - - - - - - ACL Tutorial for Joomla 1.6(超级链接不改,回头有兴趣的朋友可以访问)How to implement actions in your code打包升级文件如下:helloworld.xmlsite/index.htmlsite/helloworld.phpsite/controller.phpsite/views/index.htmlsite/views/helloworld/index.htmlsite/views/helloworld/view.html.phpsite/views/helloworld/tmpl/index.htmlsite/views/helloworld/tmpl/default.xmlsite/views/helloworld/tmpl/default.phpsite/models/index.htmlsite/models/helloworld.phpsite/language/index.htmlsite/language/en-GB/index.htmlsite/language/en-GB/en-GB.com_helloworld.iniadmin/index.htmladmin/access.xmladmin/config.xmladmin/helloworld.phpadmin/controller.phpadmin/sql/index.htmladmin/sql/install.mysql.utf8.sqladmin/sql/uninstall.mysql.utf8.sqladmin/sql/updates/index.htmladmin/sql/updates/mysql/index.htmladmin/sql/updates/mysql/0.0.1.sqladmin/sql/updates/mysql/0.0.6.sqladmin/sql/updates/mysql/0.0.12.sqladmin/sql/updates/mysql/0.0.13.sqladmin/models/index.htmladmin/models/fields/index.htmladmin/models/fields/helloworld.phpadmin/models/forms/index.htmladmin/models/forms/helloworld.xmladmin/models/forms/helloworld.jsadmin/models/rules/index.html名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 19 页 - - - - - - - - - admin/models/rules/greeting.phpadmin/models/helloworld.phpadmin/models/helloworlds.phpadmin/views/index.htmladmin/views/helloworlds/index.htmladmin/views/helloworlds/view.html.phpadmin/views/helloworlds/tmpl/index.htmladmin/views/helloworlds/tmpl/default.phpadmin/views/helloworlds/tmpl/default_head.phpadmin/views/helloworlds/tmpl/default_body.phpadmin/views/helloworlds/tmpl/default_foot.phpadmin/views/helloworld/index.htmladmin/views/helloworld/view.html.phpadmin/views/helloworld/submitbutton.jsadmin/views/helloworld/tmpl/index.htmladmin/views/helloworld/tmpl/edit.phpadmin/helpers/index.htmladmin/helpers/helloworld.phpadmin/tables/index.htmladmin/tables/helloworld.phpadmin/language/en-GB/en-GB.com_helloworld.iniadmin/language/en-GB/en-GB.com_helloworld.sys.iniadmin/controllers/index.htmladmin/controllers/helloworld.phpadmin/controllers/helloworlds.phplanguage/en-GB/en-GB.inimedia/index.htmlmedia/images/index.htmlmedia/images/tux-16x16.pngmedia/images/tux-48x48.pnghelloworld.xml 文件内容如下: COM_HELLOWORLD November 2009 John Doe john.doeexample.org http:/www.example.org Copyright Info 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 17 页,共 19 页 - - - - - - - - - License Info 0.0.14 COM_HELLOWORLD_DESCRIPTION sql/install.mysql.utf8.sql sql/uninstall.mysql.utf8.sql sql/updates/mysql index.html helloworld.php controller.php views models language index.html 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 18 页,共 19 页 - - - - - - - - - images COM_HELLOWORLD_MENU index.html config.xml access.xml helloworld.php controller.php sql tables models views controllers helpers language/en-GB/en-GB.com_helloworld.ini language/en-GB/en-GB.com_helloworld.sys.ini 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 19 页,共 19 页 - - - - - - - - -

    注意事项

    本文(2022年Joomla.MVC组件开发教程 2.pdf)为本站会员(Che****ry)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开