首页 > 解决方案 > 未定义的属性:第 92 行 C:\..\..\Joomla\administrator\components\com_helloworld\views\helloworlds\tmpl\default.php 中的 stdClass::$contactno

问题描述

我在 helloworld 组件后端添加了一个contactno 字段。我添加一个不。行代码与添加类别相同。

文件位置:

  1. admin/sql/install.mysql.utf8.sql ...我添加了一个contactno字段

  2. admin/models/forms/helloworld.xml ...我在问候字段下方添加了一个contactno字段

<field name="contactno" type="text" default="Some text" 
 description="COM_HELLOWORLD_HELLOWORLD_CONTACT_DESC"
label="COM_HELLOWORLD_HELLOWORLD_CONTACT_LABEL" 
size="10" />
  1. admin/models/fields/helloworld.php我在受保护的函数 getOptions()中添加了一个查询
$query->select('#__helloworld.id as id,greeting,#__helloworld.contactno as contactno,#__categories.title as category,catid');   
  1. admin/views/helloworlds/tmpl/default.php ...我在作者字段下方表格添加了一个contactno 字段
<th width="30%">
                <?php echo JHtml::_('searchtools.sort', 'COM_HELLOWORLD_CONTACTNO', 'contactno', $listDirn, $listOrder); ?>
            </th>

和作者下面的td

<td align="center"> <?php echo $row->contactno; ?> </td>

当我运行 helloworld 组件时出现错误

注意:未定义的属性:第 92 行 C:\xampp\htdocs\Joomla\administrator\components\com_helloworld\views\helloworlds\tmpl\default.php 中的 stdClass::$contactno

我的错误是什么...在哪里定义一个新字段...?

标签: joomla3.0joomla-component

解决方案


我通过添加配置设置的关联数组来解决。文件位置是:admin/models/helloworlds.php 我在数组中添加了一个新字段contactno并在getListQuery()的查询中更新

 $query->select('a.id as id, a.greeting as greeting, a.contactno as contactno, a.published as published, a.created as created')

推荐阅读