Page 1 of 1

__filters__ manual page

PostPosted: Wed Jun 18, 2008 2:20 am
by Jean
Hi Steve,
Could you give me the URL of the __filters__ manual page ?
Thank you
Jean

PostPosted: Wed Jun 18, 2008 7:34 pm
by shannah
hmmm.. I can't seem to find it right now.

Practically speaking the __filters__ section is not all that useful because you can't include very much environment information into the filters.

Using the setSecurityFilter() method is usually more effective.

Here is a quick example:

In the fields.ini file for say the users table:
Code: Select all
[__filters__]
    group_id=10


This would effectively filter the users table to only show users with group_id=10.

You can see how this isn't all that helpful.

A more flexible solution involving the setSecurityFilter() method:

In the delegate class for the users table:
Code: Select all
<?php
class tables_users {
    function init(&$table){
        $table->setSecurityFilter(array('group_id'=>10));
    }
}


The above would be the equivalent to the __filters__ example.

More useful if we apply different filters for different users:
e.g.
Code: Select all
<?php
class tables_users {
    function init(&$table){
        if ( !isAdmin() ){
            $table->setSecurityFilter(array('group_id'=>10));
        }
    }
}


This will only set the filter on non-admin users (assuming that you have defined a function isAdmin() to tell you if the current user is an admin user.

Hope this helps.

-Steve

PostPosted: Wed Jun 18, 2008 7:36 pm
by shannah
Another thing used in my example that I realize may not have been well documented is the init() method. If you define a method in your delegate class as follows:
Code: Select all
function init(&$table){

   ....
}



This method will be call once just after the table is loaded for the first time. It allows you to do initialization stuff (like security filters) that you only want to happen once.

Note that it takes a single parameter: a Dataface_Table object of the table that is being initialized.

-Steve