making component,data not saving

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
sanitar
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed Aug 27, 2014 3:42 pm

making component,data not saving

Postby sanitar » Tue Nov 14, 2017 12:22 pm

Good day to all. I create my first component, for internal needs. up to a certain stage, the data was stored in a database, but then I decided to split the functionality a bit according to different views and that's all. no longer stores. when you click on the apply button - the application sends the form, and simply opens the address specified in the action, but does not save the data to the database.

events.xml:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
    <form>
        <fieldset>
            <field
                name="id"
                type="hidden"
            />
            <field
                name="name"
                type="text"
                label="COM_SIMPLEEC_EVENT_NAME"
                description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC"
                class="inputbox"
                default=""
            />
            <field
                name="color"
                type="text"
                label="COM_SIMPLEEC_EVENT_COLOR"
                description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC"
                class="inputbox"
                default=""
                id="valueInput"
            />
        </fieldset>
    </form>




models/events:


Code: Select all

defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.modeladmin');

class SimpleEventCalendarModelEvents extends JModelAdmin
 {


  public function getTable($type = 'EventsType', $prefix = 'SimpleEventCalendarTable', $config = array())
    {
        return JTable::getInstance($type, $prefix, $config);
    }
   public function getForm($data = array(), $loadData = true) {
        // Get the form.
        $form = $this->loadForm('com_simpleeventcalendar.events', 'events', array('control' => 'jform', 'load_data' => $loadData));
        if (empty($form))
            return false;

        return $form;
    }

    protected function loadFormData() {
        // Check the session for previously entered form data.
        $data = JFactory::getApplication()->getUserState('com_simpleeventcalendar.events.edit.data', array());

        if (empty($data))
            $data = $this->getItem();

        return $data;
    }


 }





controllers/events.php:


Code: Select all

defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controlleradmin');
class SimpleEventCalendarControllerEvents extends JControllerForm
 {
    public function getModel($name = 'Events', $prefix = 'SimpleEventCalendarModel')
    {
        return parent::getModel($name, $prefix, array('ignore_request' => true));
    }
 }






views/events/view.html.php:



Code: Select all

defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.view');

class SimpleEventCalendarViewEvents extends JViewLegacy
{   

  protected $items;
  protected $form;
  protected $layout;

  public function display($tpl = null) {
  $this->layout     = $this->getLayout();
    try
        {
            $this->form = $this->get('Form');
            $this->item = $this->get('Item');

            $this->addToolBar();
            parent::display($tpl);
        }
        catch (Exception $e)
        {
            throw new Exception($e->getMessage());
        }
  }

  protected function addToolBar()
    {
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     JToolBarHelper::title(JText::_('COM_SIMPLEEVENTCALENDAR_GLOBAL_TITLE'));
     $doc=JFactory::getDocument();
     $doc->addStyleSheet(JURI::root(true).'/administrator/components/com_simpleeventcalendar/assets/css/simpleeventcalendar.css');
    }

  protected function getETypeList() {
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        $query->clear()
            ->select($db->qn('id'))->select($db->qn('name'))->select($db->qn('color'))
            ->from($db->qn('#__simpleec_etype'));
        $db->setQuery($query);
        return $db->loadObjectList();
    }
}




views/events/tmpl/edit.php:


Code: Select all

defined( '_JEXEC' ) or die( 'Restricted access' );
JHtml::_('behavior.tooltip');


<form action="<?php echo JRoute::_('index.php?option=com_simpleeventcalendar&view=events&layout=edit&id=' . (int) $this->item->id); ?>" method="post" class="add_event_form" name="adminForm" id="adminForm" enctype="multipart/form-data">
< ? p h p f o r e a c h ( $ t h i s - > f o r m - > g e t F i e l d s e t ( ) a s $ f i e l d ) : ? >
                <?php echo $field->label; echo $field->input;?><?php echo ($field->name=="jform[color]" ? "<button id='button_color_pick' class='btn jscolor {valueElement:jform_valueInput, styleElement:jform_valueInput}'><i class='icon-palette'></i></button>":"");?>
            <?php endforeach; ?>
  <?php echo JHTML::_('form.token')."\n"; ?>
  <input type="hidden" name="task" value="" />
</form>





tables\EventsType.php


Code: Select all

<?php
defined('_JEXEC') or die;

jimport('joomla.database.table');


class SimpleEventCalendarTableEventsType extends JTable
{

    function __construct(&$db)
    {
        parent::__construct('#__simpleec_etype', 'id', $db);
    }

}
?>






whats' wrong???? i kill more than 12 hours to find the problem, but....

sanitar
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed Aug 27, 2014 3:42 pm

Re: making component,data not saving

Postby sanitar » Tue Nov 14, 2017 6:05 pm

actually that was easy.just it should be JToolBarHelper::apply('eventstype.apply'); ,not just JToolBarHelper::apply();


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: No registered users and 6 guests