zoukankan      html  css  js  c++  java
  • joomla 1.5 笔记

    Joomla1.5 笔记

    MVC结构

    index.php?option=组件名&view=视图名&controller=控制器名&layout=视图分页名

     

    index.php?option=com_test

    模板和组件com_test的展示

    index2.php?option=com_test

    仅组件com_test的展示

     

    组件开发需要在数据库添加记录,并以com_开头,组件分前台与后台,后台组件放在administrator/components下,前台组件放在components下。

     

    TaskController下的分支,没有Task时用默认处理。

     

    建立了View可以用 index.php?option=com_test&view=? 来显示,不需要写Controller,但必需有Controller存在

     

    命名规则:

             Controller

                       类名:控制器名Controller, 控制器名随时,但会影响ViewModel的命名

                       文件名随时,由主文件调用

             View

                       类名:控制器名View视图名

                       放在views目录下,以视图名作为目录名,主文件为view.html.php,模板页在tmpl

             Model

                       类名:控制器名Model视图名

                       放在models目录下,以视图名为文件名

     

    Model:

             继承JModel,所有以get开头的成员函数都作用参数。比如getXXX(), View中可以用$this->get('xxx')获取返回值

            

    Controller:

             JController成员名对应task

     

    常用功能

    获得表单提交数据:

             JRequest::getCmd( 'task' );              过滤提交数据

             JRequest::getInt('limit', 0);               取整型提交数据

             JRequest::getVar('message', '');     直接取提交数据

     

    绑定模板数据:

    view.html.php:

             $this->assignRef('lists', 'value');

     

    $mainframe (class JApplication):

             $mainframe->getCfg('sitename');  网站名

             $mainframe->getCfg('mailfrom');   管理员名

             $mainframe->getCfg('fromname');          邮箱

             $mainframe->isSite()                 判断是否前台

     

    当前完整Url:

             $uri = JFactory::getURI();

             $uri->toString()

     

    网站根地址:

             JURI::base()

     

     

    配置文件设置方法:

     

             // Get the path of the configuration file

             $fname = JPATH_CONFIGURATION.DS.'configuration.php';

            

             // clear cache

             $cache = JFactory::getCache();

             $cache->clean();

     

             // Update the credentials with the new settings

             $config =& JFactory::getConfig();

             $config->setValue('config.form_email', 'xxx');

     

             // Get the config registry in PHP class format and write it to configuation.php

             jimport('joomla.filesystem.file');

             if (!JFile::write($fname, $config->toString('PHP', 'config', array('class' => 'JConfig')))) {

                       die(JText::_('ERRORCONFIGFILE'));

             }

     

    路由地址为HTML全地址:

             JRoute::_( 'index.php?option=com_ccNewsletter' );

     

    获得工厂对象:

     

             $user                =& JFactory::getUser();            用户对象

             $db                  =& JFactory::getDBO();            数据操作对象

             $document       =& JFactory::getDocument(); 上下文对象

             $lang                =& JFactory::getLanguage();  语言包对象

     

    数据库对象操作:

     

             $db =& JFactory::getDBO();

             $db->setQuery($sql);

             $db->loadObjectList();              对象列表

             $db->loadObject();            一行对象

             $db->loadResult();            单个结果

             $db->Quote();                    过滤敏感字

             $db->query();

     

    Document对象操作:

     

             $document->addStyleSheet(url);     添加样式

             $document->addScript(url);    添加脚本

     

    语言对象操作:

     

             $lang->_lang === 'en-GB' or $lang->_lang === 'zh-TW'

     

    用户对象操作:

     

             $user->get('guest') 是否登录,登录了返回false

             $user->xxx                 可以直接访问数据库中的字段,xxx为字段名

             $user->setParam('xxx')   设置默认参数以外的参数

             $user->getParam('xxx')   提取参数

     

    获得组件的Menuid:

     

             $menu = &JSite::getMenu();

             $Items     = $menu->getItems('link', 'index.php?option=com_idoblog&view=idoblog');

             $Itemid=$Items[0]->id;

     

    获得当前Menuid:

     

             $menus = &JSite::getMenu();

             $menu = $menus->getActive();

     

    发送Email:

     

    $sent = JUtility::sendMail(发送者邮箱, $contactname, 接收者邮箱, $subject, $body, true);

    if (!$sent) {

             $this->setError("Send email failed.");

    }

     

    Javascript弹出小窗口:

     

    <a class="modal" href="xx" rel="{handler: 'iframe', size: {x: 570, y: 350}}">xx</a>

     

    JFolder用法:

     

    JFolder::files($path, 'jpg|png|JPG|PNG', false, true);             指定目录下的文件列表

     

    防止刷新提交:

     

    view:                  <?php echo JHTML::_( 'form.token' ); ?>

    controller:        JRequest::checkToken() or jexit( 'Invalid Token' );

     

    地址操作

    给当前地址添加参数:

             $uri = JFactory::getURI();

             $uri->setQuery($uri->getQuery().'&lang=en');

             $uri->toString()

     

    JRoute::_("&limitstart=");

     

    JHTML控件

    日历:

    JHTML::_('calendar', '1980-1-1', 'ielts_score_date', 'ielts_score_date', '%Y-%m-%d', array('class'=>'short', 'size'=>'25',  'maxlength'=>'19'))

     

    日期显示:

    JHTML::_('date', <data>, JText::_('DATE_FORMAT_LC2'));

     

    载入脚本:

             JHTML::script('upload.js', 'components/com_smipa/js/', false);

             JTHML::Stylesheet('style.css', 'components/com_smipa/css/');

             JHTML::_('behavior.mootools');                载入mootools

     

    JHTML::_('select.booleanlist', 'published','class="inputbox"', $item->published); //不能用于tinyint(1)类型

    <input type="checkbox" name="custom_link" value="1" <?php echo $this->item->xxx?'checked="checked"':'' ?> /> //适用于tinyint(1)

    JHTML::_('list.category', 'catid', $option, intval($item->catid));

    JHTML::_('list.specificordering', $item, $item->id, $query,1);

    JHTML::_('select.genericlist',$list,'postname',null,'id','title', 'default-value');

     

    模块开发

    $params->get("count", "0");                              //modules中获取参数

     

    选择模板:

             require JModuleHelper::getLayoutPath('mod_menu', 'default');

     

     

    <jdoc:include type="head" />                                //这句话引入了页面的header部分。

    <jdoc:include type="modules" name="top" style="xhtml" />    //模块组位,namexml文件上描述

    <jdoc:include type="component" style="xhtml" />             //组件位

    style是可选的,可选值定义在/templates/system/html/modules.php,能添加新的style

    $this->countModules('left')                                 //如果left有模块显示,则返回true

     

    模块输出到任何位置:

    $module = JModuleHelper::getModule('custom',$title);

    echo JModuleHelper::renderModule($module);

     

    模板位置:

    ----------------------------------

    /templates/xxxx/index.php         //模板页面,phphtml描述

    templateDetails.xml               //模板结构描述

    /element/template_thumbnail.png   //140*90的截图

    /element/css/template_css.css     //模板CSS

    ---------------------------------

     

    模板配置文件:

             <files> 部分包含模板涉及到的重要文档

             <images> 部分包含涉及到的图片文件

             <css>  部分是css文件

             <languages> 不用说是语言文件

             <positions> 定义了模板中的模块位置

             <params> 模板中的参数

             <filename>params.ini</filename>

             <folder>images/</folder>

            

    $this->baseurl

    $this->language;

    $this->params->get('widthStyle')      //在视图中获取参数

    $this->template                       //当前模板名

    $user= JFactory::getUser();

     

    自定义模块style:

     

    function modChrome_{style_name}($module, &$params, &$attribs)

    {

             $url = isset($attribs['url']) ? $attribs['url'] : '#';       //接收参数

             if (!empty ($module->content)) : ?>

                       <div class="moduletable<?php echo $params->get('moduleclass_sfx'); ?>">

                       <?php if ($module->showtitle != 0) : ?>

                                <h3><?php echo $module->title; ?><a href="<?php echo $url ?>">Read More</a></h3>

                       <?php endif; ?>

                                <?php echo $module->content; ?>

                       </div>

             <?php endif;

    }

     

    插件开发

    插件在plugins目录里以插件类型命名的目录下。每个类型都有个example.php的例子可以作为建立插件类与事件处理的参考。

     

    XML参数

    参数类型:

    <param name="" type="text" default="" label="" description="" />

    <param name="" type="radio" default="" label="" description="">

             <option value=""></option>

    </param>

    <param name="" type="list" default="" label="" description="">

             <option value="">Use Global</option>

    </param>

    <param name="description" type="textarea" default="" label="Description" description="" rows="5" cols="30" />

     

    在非文章组件/模块内调用分类参数

    <params addpath="libraries/joomla/html/parameter/element/category">

             <param name="catid" type="category" label="Category" description="Choose a category..." />

             ...

    </params>

     

    组件参数取值方法:

             global $mainframe;

             $params  =& $mainframe->getParams('com_xxx');

             $params->get(key)

     

             $cparams =& JComponentHelper::getParams('com_media');

     

    Component参数(基于组件,即option的值):

     

             位置:                 组件后台根目录下的config.xml

     

             后台设置点:   menus里选中组件类型后可以设置

                                JToolBarHelper::preferences('com_xxx')

     

    Basic参数(基于Menu,即Itemid的值):

     

             位置:                 安装包XML,写在<params>节点

                                前台view/tmpl下,与layout同名的XML,可参考con_contentXML

     

             后台设置点:   menus里选中组件类型后可以设置

     

    后台组件功能开发

    配置组件后台子级菜单:

    -------------------------

     

    安装组件包前,在后台组件的安装XML里修改submenu节点,安装后会自动在menu与组件节点添加对面的名称。安装组件包后如有修改需求,可以在#__component表中修改submenu

     

    -------------------------

     

    工具栏(ToolBar):

    -----------------------------

    JHTML::_('behavior.tooltip');            启动toolbar

             JToolBarHelper::title(JText::_('Newtech'), 'generic.png');

             JToolBarHelper::save();

             JToolBarHelper::custom('publish', 'publish', '', JText::_( 'CC_ENABLED' ), true);

             JToolBarHelper::preferences('com_xxx');        参数设置,对应config.xml

             JToolBarHelper::customX(<task>, 'new.png', 'new.png', 'Create', false);

    ---------------------------

     

    controller:

    ------------------------

     

             $this->setRedirect( 'index.php?option=com_ccNewsletter&controller=newsletter', $msg );// 页面跳转

             JController->getModel();         // 得到对应的model实例,可以获得组件所有model

     

    model:

    ---------------------------

     

             JModel->getTable    获得表实例,只可以获得对应的table

     

    table中:

    -------------------------------

             $post = JRequest::get("post");

             JTable->bind($post);                  //对应POST数据更新表

             JTable->check();             //检查数据的正确性

             JTable->store();             //把数据表写入到数据库

     

    view:

    ------------------------------

     

             JView->getModel              只可以获得对应的model

             JView->get("xxx")    调用对应model的方法

     

    ------------------------------

     

    加在后台模板中的验证脚本:

     

                       <script type="text/javascript">

                       function submitbutton(pressbutton) {

                                var form = document.adminForm;

                                if (pressbutton == 'cancel') {

                                         submitform( pressbutton );

                                         return;

                                }

                                email = form.mail.value; 

                                pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 

                                flag = pattern.test(email); 

                                if(!flag)

                                {

                                         alert("Invalid Email");

                                         return;

                                }

                                submitform(pressbutton);

                       }

                       </script>

     

    多语言 (language)

    多语言包注意事项:

             JText::_("")函数会把字串转成大写再搜索语言包中的字串,如果找不到对应的语言包,就会原样输出。

     

    权限管理 (ACL)

     

    添加权限

    JAuthorization::addACL(访问资源节点(组件), 访问资源(具体权限), 访问对象节点(users), 访问对象())

    验证权限

    JUser::authorize(访问资源节点(组件), 访问资源(具体权限))

     

    添加新的权限

    61: libraries/joomla/user/authorization.php

     

    后台菜单权限验证

    34: administrator/modules/mod_menu/help.php

     

    组件后台验证一般写在组件入口中,如admin.frontpage.php

    组件前台验证一般写在view.html.php

     

    加载juqery.js

    jquery copymedia/system/js

    调用JHTML::script('jquery.js');

     

    自定义事件 (event)

    VM插件为例

    把插件安装包XMLgroup="vm"

    插件代码:

    jimport( 'joomla.plugin.plugin' );

    $mainframe->registerEvent( 'onEventType', 'plgFunction' );

    function plgFunction(){

             // 处理过程

    }

     

    触发事件

    JPluginHelper::importPlugin('vm');

    $dispatcher =& JDispatcher::getInstance();

    $dispatcher->trigger('onEventType');               // 触发onEventType事件

            

    sh404sef

    应该在页面和参数都调好后再开sh404sef,如果因为sh404sef生成错误地址所影响,可以在后台查询地址路径再修改。

     

    h2:

    sh404sef默认把h1标签改成h2,这个要在后台设置。

     

    404:

    sh404sef安装后会自动新建404的文章页,当找不到页面会自动跳到404文章页。但默认没有指定Itemid,可能页面会受影响,可以在后台高级设置页上修改以下参数:

    $shDefaultParams['sh404SEF_PAGE_NOT_FOUND_FORCED_ITEMID'] = 0;

     

    page title:

    开了sh404sefpage title需要在sh404sef的配置中设置,比如首页的title,要在URL Manager中的Home page Meta处修改

     

    局部关闭sef:

    virtuemart为例

    components/com_sh404sef/sef_ext/com_virtuemart.php

    在对应的case支点最下方(break之上)加上 $dosef = false;

     

    .号替换:

    URL最尾带后缀会使rewrite不生效,所以404后台配置需要把.替换掉。例如: .|-

     

    地址出现中文:

    由于sh404sef默认使用title作为URL,对于中文网站也将使用中文titleURL,这样就会生成中文URL,解决方法是把Use Title Alias, Use category alias, Use section alias, Use menu alias全部选上。

     

    VM 结构

    vmpage是页面逻辑部分,template是视图部分,func是业务逻辑部分

     

    可以通过URLpage参数找到对应的page程序,阅读代码可以找到template的准确位置

     

    有关功能性程序,可以跟据页面代码中找到form中的func参数,之后利用后台List Modules功能找到代码。

    比如:

    1: 从页面的form找到参数,func = orderStatusSet

    2: 到后台的List Modules找到与订单相关的order Module

    3: 点击order Modulefunction list,找到记录如下:

             Function Name:  orderStatusSet

             Class Name:     ps_order

             Class Method:   order_status_update

    4: 找到ps_order.php,这个是ps_order类的代码,里面能找到方法order_status_update,就是我们要修改的代码部分。

     

     

    page的位置:

    administrator/components/com_virtuemart/html/

     

    template的位置:

    com_virtuemart/themes/default/templates/

     

    class的位置:

    administrator/components/com_virtuemart/classes/

     

    VM 设置问题

    paypal接口调试模式:

     

    后台 > Store > List Payment Methods > PayPal > Configuration

    修改为:

    $url = "https://www.sandbox.paypal.com/cgi-bin/webscr";

     

    后台的List Modules可以针对几种用户进行功能设置,比如可以把帐户分成管理员与仓库管理员。

     

    VM有子产品概念,可以实现不同属性不同价格。要添加子产品必须先Add Attribute

     

    VM 模板位置

    Featured Products模板:

    components/com_virtuemart/themes/default/templates/common/featuredProducts.tpl.php

     

    分页模板:

    administrator/components/com_virtuemart/classes/pageNavigation.class.php

     

    产品列表页模板(可添加)

    Category Browse Page:

    components/com_virtuemart/themes/default/templates/browse/Browse_x.php

     

    产品内容页模板(可添加)

    Category Flypage:

    components/com_virtuemart/themes/default/templates/product_details/flypage_x.php

     

    components/com_virtuemart/themes/default/theme.php

    输出附件缩略图片,不包含原图,flypage_images.tpl依赖于此函数

    function vmlistAdditionalImages( $product_id, $images, $title='', $limit=1000 )

     

    产品列表默认次序修改:

    23行: administrator/components/com_virtuemart/html/shop_browse_queries.php

     

    VM email

    Ask a question about this product

    咨询邮件内容(客户):

    VM语言包common

    VM_ENQUIRY_SHOPPER_EMAIL_MESSAGE

     

    咨询邮件内容(店主):

    VM语言包common

    VM_ENQUIRY_VENDOR_EMAIL_MESSAGE

     

    咨询邮件模板:

    components/com_virtuemart/themes/default/templates/order_emails/enquiry_email.tpl.php

     

    Checkout邮件:

    components/com_virtuemart/themes/default/templates/order_emails/confirmation_email.tpl.php

     

    订单更新状态邮件:

    365: administrator/components/com_virtuemart/classes/ps_order.php

  • 相关阅读:
    Ubuntu下设置静态网址
    Ubuntu下qemu环境搭建vexpress开发平台
    Ubuntu管理员密码设置
    学习MFC创建界面
    opencv3.0之后IPLimage转换成MAT的问题
    C++的ofstream与ifstream使用
    PCA主成分分析
    pycharm但多行注释快捷键
    fiddler不同代理模式的区别
    Python 常用模块大全(整理)
  • 原文地址:https://www.cnblogs.com/catcat811/p/2159093.html
Copyright © 2011-2022 走看看