首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在创建组件时正确添加任务/操作

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

Stack Overflow用户
提问于 2012-07-26 00:58:33
回答 1查看 2.2K关注 0票数 0

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

我遵循了这个tutorial,但现在我想添加诸如编辑、新建和删除之类的操作。我遵循了这个tutorial,但是当我点击编辑时,例如。我转到一个白页。我的name组件是Busqueda,我的表是restaurantes。

这是用于编辑操作模型/restaurante.php的模型

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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>

在控制器/I中有restaurantes.php和restaurante.php。最后一个没有任何功能。最后,在views/restaurante中,我有view.html和views/restaurante/tmpl/edit.php。

视图是:

代码语言:javascript
复制
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中

代码语言:javascript
复制
<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>

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

任何想法。我忘了做一件事。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-07-27 17:59:32

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

显示PHP错误

php_flag display_errors on php_value error_reporting 6143

启用PHP错误记录

php_value error_log上的php_flag log_errors /Some_path/PHP_errors.log

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11654870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档