JOOMLA:调用非对象上的成员函数 getFieldset()
JOOMLA: Call to a member function getFieldset() on a non-object
我是 PHP 的初学者,正在为 Joomla 开发自己的组件。我已经替换了 HelloWorld 示例中的所有 类,但我还没有更改视图的名称。如果我尝试在后端打开特定的 message/record,我会收到错误消息:
致命错误:在第 12[=12= 行 administrator/components/com_mycom/views/helloworld/tmpl/edit.php 中的非对象上调用成员函数 getFieldset() ]
第 12 行:<?php foreach ($this->form->getFieldset('details') as $field) : ?>
我的代码administrator/components/com_mycom/models/fields/mycom.php:
<?php
defined('_JEXEC') or die;
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldHelloWorld extends JFormFieldList
{
protected $type = 'Mycom';
protected function getOptions()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('h.id, h.header, h.parent')
->from('#__pages as h')
->select('c.title as category')
->leftJoin('#__categories AS c ON c.id = h.parent');
$db->setQuery($query);
$messages = $db->loadObjectList();
$options = array();
if ($messages)
{
foreach ($messages as $message)
{
$options[] = JHtml::_('select.option', $message->id,
$message->header . ($message->parent ? ' (' . $message->category . ')' : '')
);
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
Joomla 3.4
单条记录必须有administrator/components/com_mycom/models/fields/helloworld.php as model/view
创建表单时,表单字段在 models/forms/helloworld 的 XML 文件中指定。xml 表单字段在 中指定字段集。要获取视图页面中的表单字段,我们可以使用以下任何一种方法。
$this->form = $this->get('Form'); // use in view.html.php file where we store data to be used in view file (edit.php)
在helloworld.php的模型文件中定义函数
public function getForm($data = array(), $loadData = true) {
// Initialise variables.
$app = JFactory::getApplication();
// Get the form.
$form = $this->loadForm('com_helloworld.helloworld', 'helloworld', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
在视图中 edit.php 文件
<?php echo $this->form->getLabel('name'); ?> // label name
<?php echo $this->form->getInput('name'); ?> // input text fields
另一种方法是
$fieldset = $this->form->getFieldset('fieldset_name'); // name of the fieldset in xml file.
这个returns一个数组。
我是 PHP 的初学者,正在为 Joomla 开发自己的组件。我已经替换了 HelloWorld 示例中的所有 类,但我还没有更改视图的名称。如果我尝试在后端打开特定的 message/record,我会收到错误消息:
致命错误:在第 12[=12= 行 administrator/components/com_mycom/views/helloworld/tmpl/edit.php 中的非对象上调用成员函数 getFieldset() ]
第 12 行:<?php foreach ($this->form->getFieldset('details') as $field) : ?>
我的代码administrator/components/com_mycom/models/fields/mycom.php:
<?php
defined('_JEXEC') or die;
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldHelloWorld extends JFormFieldList
{
protected $type = 'Mycom';
protected function getOptions()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('h.id, h.header, h.parent')
->from('#__pages as h')
->select('c.title as category')
->leftJoin('#__categories AS c ON c.id = h.parent');
$db->setQuery($query);
$messages = $db->loadObjectList();
$options = array();
if ($messages)
{
foreach ($messages as $message)
{
$options[] = JHtml::_('select.option', $message->id,
$message->header . ($message->parent ? ' (' . $message->category . ')' : '')
);
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
Joomla 3.4
单条记录必须有administrator/components/com_mycom/models/fields/helloworld.php as model/view
创建表单时,表单字段在 models/forms/helloworld 的 XML 文件中指定。xml 表单字段在 中指定字段集。要获取视图页面中的表单字段,我们可以使用以下任何一种方法。
$this->form = $this->get('Form'); // use in view.html.php file where we store data to be used in view file (edit.php)
在helloworld.php的模型文件中定义函数
public function getForm($data = array(), $loadData = true) {
// Initialise variables.
$app = JFactory::getApplication();
// Get the form.
$form = $this->loadForm('com_helloworld.helloworld', 'helloworld', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
在视图中 edit.php 文件
<?php echo $this->form->getLabel('name'); ?> // label name
<?php echo $this->form->getInput('name'); ?> // input text fields
另一种方法是
$fieldset = $this->form->getFieldset('fieldset_name'); // name of the fieldset in xml file.
这个returns一个数组。