如果您使用的是 Joomla 1.6,简单的方法是让 Joomla 为您完成所有工作。如何?
首先你需要在你的xml表单(/model/forms/YOURFORM.xml)中包含类似的东西......
<field name="imageurl" type="media" directory="CUSTOMDIRECTORY?"
hide_none="1" label="COM_YOURCOMPONENT_IMG_LABEL"
size="40"
description="COM_YOURCOMPONENT_IMG_DESCRIPTION" />
您的模型中没有 getForm() 吗?
public function getForm($data = array(), $loadData = true)
{
// Get the form.
try {
//throw new Exception(JText::_('JLIB_FORM_ERROR_NO_DATA'));
$form = $this->loadForm('com_kfiles', 'files');
} catch (Exception $e) {
echo "e";
echo 'Caught exception: ', $e->getMessage(), "\n";
}
if (empty($form)) {
return false;
}
return $form;
}
在您的视图(/views/xxxx/view.html.php)中,您需要加载表单
$this->form = $this->get('Form');
最后,您只需要将模板中的元素打印到您想要的任何位置。
echo $this->form->getLabel('imageurl');
echo $this->form->getInput('imageurl');
再见