Joomla定制JForm。使用foreach循环生成值
谁能告诉我为什么这不起作用?错误就在每个周期的某个地方。Joomla定制JForm。使用foreach循环生成值,joomla,jform,Joomla,Jform,谁能告诉我为什么这不起作用?错误就在每个周期的某个地方。 jimport('joomla.form.formfield'); class JFormFieldCity extends JFormField { protected $type = 'city'; public function getInput() { $db = JFactory::getDBO(); $db->setQuery(
jimport('joomla.form.formfield');
class JFormFieldCity extends JFormField {
protected $type = 'city';
public function getInput() {
$db = JFactory::getDBO();
$db->setQuery(
'SELECT title' .
' FROM #__content'
);
$title = $db->loadObjectList;
return '<select id="'.$this->id.'" name="'.$this->name.'">'.
foreach ($title as $titlex)
{
'<option value="6" >'.$titlex.'</option>'
}
'</select>';} }
下面是一段经过编辑的代码,如果您是从xml创建自定义字段,这将非常有用。请尝试一下,如果不起作用,请告诉我
// No direct access to this file
defined('_JEXEC') or die;
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldCity extends JFormFieldList
{
/**
* The field type.
*
* @var string
*/
protected $type = 'city';
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*/
protected function getOptions()
{
$db = JFactory::getDBO();
//$query = new JDatabaseQuery;
$query = $db->getQuery(true);
$query->select('id,title');
$query->from('#__content');
$query->order('title');
$db->setQuery((string)$query);
$messages = $db->loadObjectList();
$options = array();
if ($messages)
{
foreach($messages as $message)
{
$options[] = JHtml::_('select.option', $message->title, $message->title);
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
不工作。foreach Cycle肯定有问题什么不起作用?你看到了什么?你期望什么?一切都正常,但我添加了这一行->foreach$title作为$titlex{.$title..}它停止工作了什么停止了工作?出现错误了吗?或者下拉列表没有显示?我得到的不是完整的文章编辑窗口,而是编辑文章标题*别名状态。这就是全部。表单停止工作。