Joomla 2.5你好世界模块开发

时间:2012-08-06 18:26:35

标签: php database joomla module joomla2.5

我是Joomla 2.5模块开发的新手,所以我阅读This教程并复制并粘贴所有内容而不做任何更改,当我安装的所有内容都在服务器端工作正常但在前端它显示了这些错误:

1)严格标准:非静态方法modUserDataHelper :: getData()不应在第16行的C:\ xampp \ htdocs \ joomla \ modules \ mod_userdata \ mod_userdata.php中静态调用

2)严格标准:第24行的C:\ xampp \ htdocs \ joomla \ modules \ mod_userdata \ helper.php中只能通过引用分配变量

所以你能告诉我我的代码有什么问题吗?

文件:

mod_userdata.xml
mod_userdata.php
helper.php
index.html
tmpl/default.php
tmpl/index.html

mod_userdata.xml

<?xml version="1.0" encoding="UTF-8"?>
<extension type="module" version="1.7" client="site" method="upgrade">
 <name>User Data Module</name>
 <author>Minitek.gr</author>
 <creationDate>03/08/2011</creationDate>
 <copyright>Copyright (C) 2011. All rights reserved.</copyright>
 <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
 <authorEmail>your_email</authorEmail>
 <authorUrl>www.minitek.gr</authorUrl>
 <version>1.7.1</version>
 <description>Users Data Module</description>
 <languages>
 </languages>
 <files>
  <filename module="mod_userdata">mod_userdata.php</filename>
  <filename>mod_userdata.xml</filename>
  <filename>helper.php</filename>
  <filename>index.html</filename>
  <folder>tmpl</folder>
 </files>
 <config>
  <fields name="params">
   <fieldset name="basic">
    <field name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="Suffix for individual css styling" />
    <field name="limit" type="text" default="10" label="Limit Displayed Users" description="Limit Displayed Users" />
    <field name="user_id" type="radio" default="1" label="Display user ID" description="Display user ID">
     <option value="0">JNO</option>
     <option value="1">JYES</option>
    </field>
    <field name="user_name" type="radio" default="1" label="Display Name" description="Display Name">
     <option value="0">JNO</option>
     <option value="1">JYES</option>
    </field>
    <field name="user_username" type="radio" default="1" label="Display Username" description="Display Username">
     <option value="0">JNO</option>
     <option value="1">JYES</option>
    </field>
   </fieldset>
  </fields>
 </config>
</extension>

mod_userdata.php

<?php
/**
 * @package Joomla.Site
 * @subpackage  mod_userdata
 * @copyright   Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

// Include the syndicate functions only once
require_once dirname(__FILE__).'/helper.php';

// Get the user data
$list   = modUserDataHelper::getData($params);  // <-- ERROR IS HERE!!!

// Get the layout
require JModuleHelper::getLayoutPath('mod_userdata', $params->get('layout', 'default'));

helper.php

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_userdata
 * @copyright   Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

class modUserDataHelper
{
  function getData( &$params )
  {

   // Database query        
   $list = array();         
   $query = " SELECT id, name, username "               
   ." FROM #__users "
   ." WHERE block=0 "               
   ." ORDER BY id DESC "
   ." LIMIT " . $params->get( 'limit' );                
   $db =& JFactory::getDBO();   // <-- ERROR IS HERE!!!
   $db->setQuery( $query );     
   $rows = $db->loadObjectList();

   // Get list items
   if ($rows!=null)
   {
    $i=0;
    foreach ($rows as $row) 
    {               
     $list["users"][$i]["id"]=$row->id;
     $list["users"][$i]["name"]=$row->name;
     $list["users"][$i]["username"]=$row->username;
     $i++;      
    }
    return $list;
   }

  }
}

TMPL /如default.php

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_userdata
 * @copyright   Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die; ?>

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

 <ul>
  <?php for ($i=0;$i< sizeof($list["users"]); $i++) { ?>    

     <li>
      <?php if ($params->get( 'user_id' )) { ?>
         <span><?php echo $list["users"][$i]["id"];?></span>
        <?php } ?>
        <?php if ($params->get( 'user_name' )) { ?>
         <span><?php echo $list["users"][$i]["name"];?></span>
        <?php } ?>
        <?php if ($params->get( 'user_username' )) { ?>
         <span><?php echo $list["users"][$i]["username"];?></span>
        <?php } ?>
     </li>

    <?php } ?>
 </ul>

</div>

1 个答案:

答案 0 :(得分:3)

你已经开启了“严格的标准”,由于为(可能)php 5.3而不是5.4编写代码而导致一些错误。看起来像对象被实例化或通过引用(&new MyClass而不是new MyClass)和modUserDataHelper::getData()进行实例化,而未定义为静态被称为{{1} }。

你可以做两件事:关闭严格的标准(相当于在地毯下扫除灰尘的代码)或修复坏代码。在这种情况下,调用static是不好的形式。它需要从实例化对象调用,而不是从静态上下文调用。创建它的实例(modUserDataHelper::getData()或类似的东西),然后从该对象($tempObj)调用该方法。