Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filter_fields on Joomla 3 Model

I bought "Learning Joomla! 3 Extension Development, Third Edition". This book is super ! As a newbie in Joomla! development, it help me much on my first job to build a new component. However, I still don't understand about Model construct function :

public function __construct($config = array())
{
    if (empty($config['filter_fields']))
    {
        $config['filter_fields'] = array(
            'id', 'a.id',
            'title', 'a.title',
            'state', 'a.state',
            'company', 'a.company',
            'image', 'a.image',
            'url', 'a.url',
            'phone', 'a.phone',
            'description', 'a.description',
            'ordering', 'a.ordering', 'a.catid'
        );
    }

parent::__construct($config);
}

What is the relation between 'id' and 'a.id' , 'title' and 'a.title' , 'phone' and 'a.phone' , etc ? Will joomla! automatically assign the value from database table or what ? When I change the 'phone' become 'telephone', I can't retrieve the data. Thanks before.

like image 463
Xanders Avatar asked Jan 31 '26 12:01

Xanders


1 Answers

I was also confused by this. I found an answer here (quoted below). Apparently, it's just a white list of allowable field names and nothing more.

The value of this setting is merely a white list of field names that are permitted for usage in queries. So, you can see we’ve got quite a few of the standard fields names. We’ve also added some variants of those names that are query specific, just in case someone else using this model wants to use them. That’s really all there is. When you click on one of the list headings, it sets the ordering column for the list in the request. We know that the populateState method in the model will pick this value up from the request and when it does, it checks it against this white list. If the requested ordering column is not in the white list, it reverts, safely, to the default ordering.

like image 95
Marc Bowman Avatar answered Feb 02 '26 14:02

Marc Bowman