$app->getRecord() always get the last record

A place for users and developers of the Xataface to discuss and receive support.

$app->getRecord() always get the last record

Postby kevinwen » Tue May 04, 2010 3:25 pm

I did some testing and found that the following code would output the different message when creating a new record:

Code: Select all
    function field1__permissions(&$record){
        $app =& Dataface_Application::getInstance();
        $rec = $app->getRecord();
        vardump($record->val(primary_id'));
        echo "<br />";
        vardump($rec->val('primary_id'));
    }


The output would look like this:
Code: Select all
string(4) "1957"
NULL


Is it what xataface supposed to do? If it is, why?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: $app->getRecord() always get the last record

Postby shannah » Tue May 04, 2010 3:30 pm

$app->getRecord() returns the record that is matched by the current query. This corresponds exactly to the record that you would be editing in the edit action or viewing in the view action. In list view this would correspond with the record at -cursor position of the list.

The $record parameter of the permissions method refers to the record on which permissions are being checked. In any given request many calls are made to getPermissions() on different records. Hence these two values are not the same.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: $app->getRecord() always get the last record

Postby kevinwen » Wed May 05, 2010 9:52 am

I actually need to check the field value inside the widget function:

Code: Select all
function block__field01_widget(){
    $app =& Dataface_Application::getInstance();
    $rec = $app->getRecord();

    $field_value = $rec->val('field01');
    if ($field_value){
        //do something
    } else {
        // do something else
    }
}


and I found that with the edit action, $rec->val('field01') returns the value for the right record, but with the new action, it always returns the value in the last inserted record.

In my understanding, with the new action, it should return null or nothing rather than something else. Is it what the $app->getRecord() supposed to do for the new action?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: $app->getRecord() always get the last record

Postby shannah » Wed May 05, 2010 11:18 am

$app->getRecord() returns the record at the current cursor position. In the new action you can consider this value as undefined because it could be any record.

In the new action the record you're about to add doesn't exist yet.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 41 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved