2022年Joomla.MVC组件开发教程 .pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年Joomla.MVC组件开发教程 .pdf》由会员分享,可在线阅读,更多相关《2022年Joomla.MVC组件开发教程 .pdf(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、本节标题:添加类Joomla 框架已经实现了对所有组件分类的使用(has implemented the use of categories for all components),给一个组件添加分类会变得相当简单。修改 sql 为了管理分类,我们需要修改sql 表。.修改以下文件:admin/sql/install.mysql.utf8.sqlDROP TABLE IF EXISTS#_helloworld;CREATE TABLE#_helloworld(id int(11)NOT NULL AUTO_INCREMENT,greeting varchar(25)NOT NULL,catid
2、 int(11)NOT NULL DEFAULT 0,PRIMARY KEY (id)ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;INSERT INTO#_helloworld(greeting)VALUES(Hello World!),(Good bye World!);admin/sql/updates/mysql/0.0.12.sqlALTER TABLE#_helloworld ADD catid int(11)NOT NULL DEFAULT 0 修改表单现在每条 HelloWorld 信息将属于一个分类。我们需要修改它的编
3、辑表单,根据以前的学习,我们知道只需要修改如下xml 文件就可以实现了。admin/models/forms/helloworld.xml 名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 11 页 -JOPTION_SELECT_CATEGORY 注意,分类可以为0(代表未分类)。名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 11 页 -修改菜单样式HelloWorld 的当前菜单样式显示一个所有信息的列表,当信息分类以后,我们需要修改这个显示方式以显示分类。修改admin/models/fields/helloworld.php如下:admin/models/f
4、ields/helloworld.phpgetQuery(true);$query-select(#_helloworld.id as id,greeting,#_categories.title as category,catid);$query-from(#_helloworld);名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 11 页 -$query-leftJoin(#_categories on catid=#_categories.id);$db-setQuery(string)$query);$messages=$db-loadObjectList();$opti
5、ons=array();if($messages)foreach($messages as$message)$options=JHtml:_(select.option,$message-id,$message-greeting.($message-catid?(.$message-category.):);$options=array_merge(parent:getOptions(),$options);return$options;现在将在元括弧中间显示分类。It will now display the category between parenthesis.管理子菜单com_cat
6、egories组件允许通过 helper 文件设置子菜单,创建文件如下: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);com_categories组件将自动调用该函数注意它将修改子菜单修改
7、一些 css 属性(以便显示图标)在子菜单是categories 时将修改浏览器标题修改标题并添加一个选择“分类”的按钮现在我们需要修改基本控制器来调用这个函数,并且需要修改(注意.icon-48-helloworld css 样式在 addSubmenu函数中已经设置了)admin/controller.php名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 11 页 -?php/No direct access to this file defined(_JEXEC)or die(Restricted access);/import Joomla controller libr
8、ary jimport(ponent.controller);/*General Controller of HelloWorld component */class HelloWorldController extends JController /*display task *return void */function display($cachable=false)/set default view if not set JRequest:setVar(view,JRequest:getCmd(view,HelloWorlds);/call parent behavior parent
9、:display($cachable);/Set the submenu HelloWorldHelper:addSubmenu(messages);admin/helloworld.phpexecute(JRequest:getCmd(task);/Redirect if set by the controller$controller-redirect();添加一些翻译字句admin/language/en-GB/en-GB.com_helloworld.ini(使用中文的记得在zh-CN,中)COM_HELLOWORLD=Hello World!COM_HELLOWORLD_ADMINI
10、STRATION=HelloWorld-Administration COM_HELLOWORLD_ADMINISTRATION_CATEGORIES=HelloWorld-Categories COM_HELLOWORLD_HELLOWORLD_CREATING=HelloWorld-Creating COM_HELLOWORLD_HELLOWORLD_DETAILS=Details COM_HELLOWORLD_HELLOWORLD_EDITING=HelloWorld-Editing COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE=Some va
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Joomla.MVC组件开发教程 2022 Joomla MVC 组件 开发 教程
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内