Joomla 2.5 のバックエンド用に最初のコンポーネントを作成しています。最初の部分は問題ありません。一般的なコントローラーを使用してコンポーネントを作成し、すべての要素をテーブルに表示します
これについてはこのチュートリアルに従いましたが、編集、新規作成、削除などのアクションを追加したいと思います。私はこのチュートリアルに従いましたが、たとえば、編集をクリックすると. 白いページに行きます。私の名前のコンポーネントはBusqueda
で、テーブルはrestaurantes
です。
これは編集アクションのモデルです models/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;
}
}
これは私のmodels/forms/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 と restaurante.php があります。最後のものには何の機能もありません。最後に、views/restaurant には、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>
これはチュートリアルに表示されるものと同じですが、[編集] をクリックすると白いページが表示されます。
何か案が。私は何かをするのを忘れています。
ありがとう。