1

So I have a query in the getlistquery method of my model, except that it relies on data in another table, that sometimes is not filled. This gives me an error when that other data is not available.

But it seems that the getlistquery must return a query, I tried to use the return false but that does not work. Do I need to move that code to another method? Like getItems?

protected function getListQuery()
{
    
    $user = Factory::getUser();
    $db = $this->getDbo();
    $query = $db
        ->getQuery(true)
        ->select('*')
        ->from($db->quoteName('#__table_profile'))
        ->where($db->quoteName('user_id') . " = " . $db->quote($user->id));

    $db->setQuery($query);
    $result = $db->loadAssoc();

    //no user profile available, return false
    if(!$result) return false;
}

But now I get the following error: u have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 20' at line 1

Probably because I don't return a query and now it is not complete.

6
0

I decided to skip the getListQuery and moved the code into a custom function and decided to use that to get my items. I couldn't get it to work with the getListQuery, and although it's cleaner code to use the standard methods of Joomla and overriding them, this worked for me a lot better, without headaches.

public function getProfiles()
{
    
    $user = Factory::getUser();
    $db = $this->getDbo();
    $query = $db
        ->getQuery(true)
        ->select('*')
        ->from($db->quoteName('#__table_profile'))
        ->where($db->quoteName('user_id') . " = " . $db->quote($user->id));

    $db->setQuery($query);
    $result = $db->loadAssoc();

    //no user profile available, return false
    if(!$result) return false;
}

In my view.html.php I use this line of code to get all the profiles:

$this->profiles = $this->get('Profiles');

And in my template I check if the profiles exists, and show code based on that value.

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.