1

This update query is not working and I've triple-checked the general syntax for the update queries in Joomla via the documentation..Here is the code from the controller-side:

public function approveAll() {
        $input = JFactory::getApplication()->input;
        $selectedEntries = $input->post->get('id', array(), 'array');

        JArrayHelper::toInteger($selectedEntries);

        $model = $this->getModel();
        $model->approveSelectedEntries($selectedEntries);
        $model->sendMeAnEmail('This is so broken');

        $this->setRedirect(JRoute::_('index.php?option=com_awardadmin', false));
    }

and here is the code from the model-side:

public function approveSelectedEntries($idsToApprove)
    {
        $db = JFactory::getDBO();

        foreach ($idsToApprove as $currentID) {
            $query = $db->getQuery(true);

            $query->update('#__chronoforms_data_nominationForm');
            $query->set('approved = 1');
            //$query->set('approved = true');
            $query->where('id = '.$currentID);
            $db->setQuery($query);
            //$db->loadRow();
            $result = $db->execute();

            $this->sendNotificationEmail($currentID);
            sendMeAnEmail('IDs: '.$idsToApprove.'<br>ID: '.$currentID.'<br>Query: '.$query.'<br>DB: '.$db);
        }
    }

My experience with Joomla is limited but neither of my sendMeAnEmail methods are firing so something is getting lost somewhere and I don't know enough about how Joomla works to figure it out. I only have a basic understanding of how it applies MVC as well.

Any help would be appreciated.

The override for getModel():

public function getModel($name = 'Submission', $prefix = 'AwardAdminModel') 
    {
        $model = parent::getModel($name, $prefix, array('ignore_request' => true));
        return $model;
    }

Tried changing the structure of the query as per this link to:

 $fields = $db->quoteName('approved').' = true';
    $conditions = $db->quoteName('id').' = 443';
$query->update($db->quoteName('#__chronoforms_data_nominationForm'))->set($fields)->where($conditions);
    $db->setQuery($query);
    $db->query();

But it did not work...even with hardcoded where clause.

  • Please escape your table name, columns and values – Lodder Nov 6 '15 at 21:41
0

As written in comments it was a problem of incorrect input variable names. When developing forms it's always a good idea to check that variables and values are correctly retrieved on server side.

I was able to solve this by examining the source in Chrome and discovering that the ids selected via checkbox were in an array called cid[], not id[]. The designation for this array is not even found in this particular component, which is odd. You are right in that it was not related to the query but to the input.


Try replacing $db->execute(); with $db->query(); if your using joomla 2.5.x, the execute method had been introduced in joomla 3.

The problem could be also related to how you're loading the model in the approveAll function, try to replace $model = $this->getModel(); adding the related model name that contains the other functions: $model = $this->getModel('ModelName');

  • 1
    I tried changing the execute to query and that did not work. The getModel() method is actually overridden and I'll add that to my post, please check and see if it's alright. As for the error reporting, this isn't actually on a server I have access to so I have to request the error.log in a support ticket (the last they sent only had PHP Strict notices) – Chase Nov 9 '15 at 14:32
  • I've tested the update query code and it works assuming table name and fields are correct, also the getModel override works fine, so it could be something related to the input data you retrieve, try to declare an array with some ids and call directly the controller function to see if the updates are executed. – Kitase88 Nov 9 '15 at 16:12
  • After managing to get a var_dump to work on the $selectedEntries variable just after it was taken from POST, it does appear that it is empty...This doesn't explain why the hardcoded value isn't working though. – Chase Nov 9 '15 at 19:54
  • some updates: add a third parameter to getModel override $options = array() just to avoid a strict standard and remove the notification mail functions until everything else works. The query works so must be something else. Is the query still in foreach? is it a subcontroller? add some temporary echo/print_r and call the controller to see actual values of $selectedEntries and $query – Kitase88 Nov 10 '15 at 9:18
  • I don't see changing the parameters as anything outright beneficial, would I not need to change the arg list passed to the parent::getModel call? The query is still in a foreach to process each ID in the array passed. I don't know what a subcontroller is in respect to Joomla. Where should I call this controller from? – Chase Nov 10 '15 at 16:07

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.