我正在做Joomla 2.5後端的第一個組件。 第一部分是好的,我創建了一個通用控制器的組件,現在我顯示了表中的所有元素如何在創建組件時正確添加任務/操作
我跟着這個tutorial,但現在我想添加諸如edit,new和delete之類的操作。我跟着這個tutorial,但是當我點擊編輯時,例如。我去了一個白頁。我的名字是Busqueda
,我的表格是restaurantes
。
這是編輯操作模式/模式restaurante.php
class BusquedaModelRestaurante extends JModelAdmin{
public function getTable($type= 'Restaurantes', $prefix='RestaurantesTable', $config=array()){
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true){
$form = $this->loadForm('com_busqueda.restaurante', 'restaurante', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
protected function loadFormData(){
$data= JFactory::getApplication()->getUserState('com_busqueda.edit.restaurante.data', array());
if(empty($data)){
$data=$this->getItem();
}
return $data;
}
}
這是我的模型/表格/ form.xml
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field
name="id"
type="hidden"
/>
<field name="nombre" type="text" class="inputbox"
size="40" label="nombre"
description="Nombre" />
<field name="direccion" type="text" class="inputbox"
size="40" label="direccion"
description="Direccion" />
...
</fieldset>
</form>
在控制器/我有restaurantes.php和用餐.PHP。最後一個沒有任何功能。最後在views/restaurante中,我有view.html和views/restaurante/tmpl/edit.php。
的觀點是:
class BusquedaViewRestaurante extends JView
{
public function display($tpl = null)
{
$form = $this->get('Form');
$item = $this->get('Item');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->form =$form;
$this->item =$item;
$this->addToolbar();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addToolbar()
{
$input =JFactory::getApplication()->input;
$input->set('hidemainmenu', true);
$isNew = ($this->item->id == 0);
JToolBarHelper::title($isNew ? JText::_('NEW')
: JText::_('EDIT'));
JToolBarHelper::save('busqueda.save');
JToolBarHelper::cancel('busqueda.cancel', $isNew ? 'JTOOLBAR_CANCEL'
: 'JTOOLBAR_CLOSE');
}
}
在edit.php
<form action="<?php echo JRoute::_('index.php?option=com_busqueda&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="restaurante-form" class="form-validate">
<fieldset class="adminform">
<legend><?php echo JText::_('DETALLES'); ?></legend>
<ul class="adminformlist">
<li><?php echo $this->form->getLabel('nombre'); ?>
<?php echo $this->form->getInput('nombre'); ?></li>
<li><?php echo $this->form->getLabel('direccion'); ?>
<?php echo $this->form->getInput('direccion'); ?></li>
....
</ul>
</fieldset>
<div>
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
這是出現在教程中的一樣,但是當我在編輯點擊我看到一個白色的頁面。
任何想法。我忘了做點什麼。
謝謝。
你可以試試這個:http://www.notwebdesign.com/joomla-component-creator/ – ChelseaStats 2012-07-26 09:20:01