Page 1 of 1

reference to current record

PostPosted: Fri Dec 07, 2007 5:29 pm
by kurisusan
Hi,

I would like to get a reference to the current record regardless of whether I'm in the 'view' page of a record or in of its related record 'list' pages. The $record parameter passed to the delegate class methods unfortunately changes to the first item of the related records table although the $_tablename stays the same.
Will I need to check the -action var and handle that myself?

Regards, Christian

PostPosted: Fri Dec 07, 2007 6:54 pm
by shannah
The current record should always be retrievable using:
Code: Select all
$app =& Dataface_Application::getInstance();
$record =& $app->getRecord();

PostPosted: Sat Dec 08, 2007 3:38 am
by kurisusan
Unfortunately not. $record still references the first item of the related tables when leaving the 'view' page of a record.

Christian
[/quote]

PostPosted: Sat Dec 08, 2007 4:09 am
by shannah
Can you elaborate on your situation. I'm no longer sure I understand what you mean.

e.g.

the $app->getRecord() will never return any records from a related table. It will only return a record from the current table.
If you are in the view tab it will return the record being viewed.
If you are in one of its relationship tabs, it will still return the record being viewed (which is the parent of the related records).

PostPosted: Sat Dec 08, 2007 5:27 am
by kurisusan
If you are in the view tab it will return the record being viewed.
If you are in one of its relationship tabs, it will still return the record being viewed (which is the parent of the related records).

Well, here it won't. I check that, e.g. by placing a
Code: Select all
echo $record->getID();

somewhere in the getParent() delegate class method and the id changes when switching from the 'view' tab to one of the related table views. This happens both when using the $record parameter of the getParent() method and using the app's getRecord() method.

I'll try to setup an online example.

Christian

PostPosted: Sat Dec 08, 2007 1:25 pm
by shannah
Are you referring to the situation after you have already clicked on one of the related records and are now viewing it?

If so, then it will show *that* record (i.e. the related record), which is now the current record.

PostPosted: Sat Dec 08, 2007 7:10 pm
by kurisusan
Are you referring to the situation after you have already clicked on one of the related records and are now viewing it?


No, this already happens when just clicking on the notebook tab of one of the related records.

Christian

working sample

PostPosted: Sat Dec 08, 2007 8:50 pm
by kurisusan
I made an online sample to demonstrate the problem: www.hoc.net/sandbox/test

From the countries tables select 'Japan', then switch between the view and the 'cities' tab and have a look at the information given just below the nav_menu. You'll see that the id of the record changes.

The status line is created like this:

class tables_countries {
function block__after_nav_menu(){
$app =& Dataface_Application::getInstance();
$record =& $app->getRecord();
echo "current record's id is: ".$record->val('id');
echo ", tablename: ".$record->_tablename;
}
}
?>


Tell me if you need more information.

Christian

PostPosted: Sun Dec 09, 2007 2:22 am
by shannah
Thanks. This problem appears to be specific to 0.7.1 as my development version doesn't exhibit this problem (but i can confirm it when running 0.7.1).

I have filed a bug report on this issue:
http://bugs.weblite.ca/view.php?id=51

I have uploaded a patch there to fix this issue for dataface 0.7.1.

PostPosted: Sun Dec 09, 2007 2:30 am
by kurisusan
Thanks!