1

I'm overriding store method to add "created" and "created_by" column in database. modified column is getting inserted with current date properly. But, for a new request, created and created_by columns are not getting inserted with current date and current userid respectively.

I'm inserting a new row, hence this is new request. In that case, $this->id should should not be there. I tried to echo $this->id and it is indeed not set.

My code is:

public function store($updateNulls = false)
    {
        $date = JFactory::getDate();
        $user = JFactory::getUser();

        $this->modified = $date->toSql();

        if (isset($this->id))
        {
            // Existing item
            $this->modified_by = $user->get('id');
        }
        else
        {
            // New Request. Set "created" column to current date and "created_by" to current userid
            if (!(int) $this->created)
            {
                $this->created = $date->toSql();
            }

            if (empty($this->created_by))
            {
                $this->created_by = $user->get('id');
            }
        }

        return parent::store($updateNulls);
    }
0

To clarify, did you alter your component's view JTable wrapper class or the core Joomla JTable class? You should avoid the latter (core class) at all costs because the next Joomla CMS update could wipe any edits to core files out.

In these cases the answer is usually tied to a required field in the form XML definition file, the fields actually renders and the task parameter. I've run into this exact issue several times myself and its usually the result of one of the following things:

  1. Forgetting to include a hidden but required field
  2. Not setting id field value to 0 records
  3. Incorrect combination of hidden task input field and including in form action URL params

It's difficult to determine with any certainty what the exact issue with the information available, but I'm fairly confident one of these might be the issue.

Hope this helps.

  • Yeah I know. I did not altered core class. I had added those lines in extended class. And eventually issue gets resolved. Thanks for your help. – Sahil Purav Apr 24 '15 at 3:48
0

I figured it out:

I had added following variables in extended JTable class (MyComponentTableMyTableName class):

/**
     * Current date for created column in #__helpdesk
     * @var Current Date to SQL format 
     */
    protected $created;

    /**
     * User id for created_by column in #__helpdesk
     * @var integer
     */
    protected $created_by;

I just removed it. Gogglers, this will be useful. One should not add any custom variable if we are overriding JTable methods.

0

There is nothing wrong in having custom properties in the child classes based on JTable. I did it and it works. You just need to chose your property names wisely and make sure that they do not collide with the table's columns names or the reserved Joomla table names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.