如何在创建组件时正确添加任务/操作



我正在为Joomla 2.5的后端做我的第一个组件。第一部分是可以的,我创建了一个带有通用控制器的组件,现在我在一个表中显示所有元素

我遵循了本教程,但现在我想添加编辑、新建和删除等操作。我遵循了本教程,但当我单击编辑时,例如。我转到一个白色页面。我的名称组件是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;
    }
}

这是我的型号/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>

在controllers/I中有restaurantes.php和restaurante.php。最后一个没有任何功能。最后在views/restaurante中,我有view.html和views/srestaurante/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');               
    }
}

在编辑中.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>

这与教程中出现的内容相同,但当我单击编辑时,我会看到一个白色页面。

任何想法。我忘了做点什么。

谢谢。

要查看可能出现的问题,您需要在php.ini中启用php错误日志。当php.xml包过期时,我遇到了这个问题。在php.ini中,您可能需要添加/取消注释这些行

显示PHP错误

php_flag显示错误php_value error_reporting 6143

启用PHP错误日志记录

php_flag日志错误php_value error_log/Some_path/php_errors.log

最新更新