0
votes

I am doing my first component for the backend of Joomla 2.5. The first part is ok, I create a a component with general contoller and now I show all the elements in a table

I followed this tutorial for this, but now I want to add actions like edit, new and delete. I followed this tutorial but when I click in edit, for example. I go to a white page. My name component is Busqueda and my table is restaurantes.

This is the model for edit action 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;
    }
}

this is my 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>

In controllers/ I have restaurantes.php and restaurante.php. The last one doesn't have any function. Finally in views/restaurante, I have view.html and views/restaurante/tmpl/edit.php.

The view is:

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');               
    }
}

in 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>

this is the same that appears in the tutorial, but when I click in edit I see a white page.

Any idea. I'm forgetting to do something.

Thanks.

1

1 Answers

0
votes

To see what could be going wrong you need to enable php error logging in php.ini. I got this problem when php-xml package was out of date. In php.ini you might need to add/uncomment these lines

Displaying PHP errors

php_flag display_errors on php_value error_reporting 6143

enable PHP error logging

php_flag log_errors on php_value error_log /Some_path/PHP_errors.log