Difference between __pullValue and __htmlValue
Archived from the Xataface Users forum.
kevinwen — Tue Jan 19, 2010 6:58 pm
I used __htmlValue function to display a field in browse mode but somehow the field is not showing up in the edit mode, and I tried __pullValue and it doesn’t work as well. The field to be displayed is in a relaitonship table like book_name (not the book_id I used to reference in the main table).
I looked at the definitions for those functions but really don’t know the difference and how they would apply based on a particular situation. Can somebody give me some examples showing the usages of these functions based on different situation?
shannah — Mon Jan 25, 2010 10:54 am
Xataface uses a few methods to retrieve values that operate in a sort of stack. Here’s how it works:
Dataface_Record::getValue($fieldname) : Gets the source value of a field.. this may or may not be a string (dates are stored as arrays).
aka Dataface_Record::val()
Dataface_Record::getValueAsString($fieldname) : Gets the source value of a field formatted as a string.
aka Dataface_Record::strval()
Dataface_Record::display($fieldname): Gets the source value of a field as it should be displayed. This method obeys permissions so if the user doesn’t have view permission, then this displays ‘NO ACCESS’. This can be overridden using the [fieldname]__display() delegate method.
Dataface_Record::htmlValue($fieldname): Gets the value of a field formatted as HTML. For most fields this will automatically escape special characters, but htmlarea fields will display html directly. This also obeys permissions.
Edit forms are a bit of a different animal so they work on a different stack. For them you would use the
[fieldname]__pullValue() and [fieldname]__pushValue() delegate methods.
[fieldname]__pullValue() : Takes a value for a field from a Dataface_Record object and prepares it for display on an edit form.
[fieldname]__pushValue(): Takes a value from an edit form widget and prepares it for saving in a Dataface_Record object.
They are inverses of each other.
-Steve
kevinwen — Mon Jan 25, 2010 5:06 pm
Let me show you the problem:
I have 3 tables: ta, tb, tc, and in table ta I defined a __sql__ as following:
- Code: Select all
- `sql “select ta.name_a, tb.name_b, tc.name_c as book_name where ta.a_id = tb.a_id and tb.b_id = tc.b_id”
[book_name]
widget:label = “Book Name”
widget:type = text
widget:atts:size=80
visibility:list = hidden
group = sources
order = 38`
in ta’s delegate class I defined both __htmlValue() and __pullValue() method:
- Code: Select all
- `function book_name_htmlValue(){
return ‘’ . $record->strval(‘book_name’) . ‘’;
}function book_name__pullValue(&$record, $element){
var_dump(‘debug code’);
//return ‘this is debug code’;
return strval(‘book_name’);
}`
I don’t see any problem here, but the view form can display book name with link, and edit form can’t show book_name for edit. __pullValue() can’t even get called since no debugging message printed out. Do you know what goes wrong? Thanks.
shannah — Mon Jan 25, 2010 7:46 pm
[code]
function book_name__pullValue($record, $element){
return $record->strval(‘book_name’);
}
kevinwen — Tue Jan 26, 2010 5:13 pm
My posting in the line of function was my mistake. It should be same as yours (return strval(‘book_name’);). But it really doesn’t work. This function even doesn’t get called. Do you know what’s going on?
shannah — Tue Jan 26, 2010 5:51 pm
What type of widget is that field using?
kevinwen — Mon Feb 01, 2010 11:24 am
Here’s the code again:
fields.ini:
- Code: Select all
- `sql “select ta.name_a, tb.name_b, tc.name_c as book_name where ta.a_id = tb.a_id and tb.b_id = tc.b_id”
[book_name]
widget:label = “Book Name”
widget:type = text
widget:atts:size=80
visibility:list = hidden
group = sources
order = 38`
delegate method:
- Code: Select all
function book_name__pullValue($record, $element){ return $record->val('book_name');
The problem here is the book_name is NOT in a table that has relationship with table ‘a’ that implements the delegate method __pullValue(). It’s just a field in a table (table ‘c’) that has relationship with table ‘b’ that has relationship with table ‘a’.
kevinwen — Mon Feb 01, 2010 11:28 am
Here’s the code again:
fields.ini in TABLE a:
- Code: Select all
- `sql “select ta.name_a, tb.name_b, tc.name_c as book_name where ta.a_id = tb.a_id and tb.b_id = tc.b_id”
[book_name]
widget:label = “Book Name”
widget:type = text
widget:atts:size=80
visibility:list = hidden
group = sources
order = 38`
delegate method for Table a:
- Code: Select all
function book_name__pullValue($record, $element){ return $record->val('book_name');
The problem here is the book_name is NOT in a table that has relationship with table ‘a’ that implements the delegate method __pullValue(). It’s just a field in a table (table ‘c’) that has relationship with table ‘b’ that has relationship with table ‘a’.
kevinwen — Mon Feb 01, 2010 6:45 pm
I did research here and found that there was a similar posting related this topic: http://xataface.com/forum/viewtopic.php?t=4404#21835
The ‘book_name’ here is actually a grafted field. Now the problem becomes: how do we display a grafted field in the edit form? I found that &formFields() at line 1946 in Table.php make no way to include the grafted fields displayed in the edit form. Is there any work-around?
- Code: Select all
function &formFields($byTab=false, $includeTransient=false){ if ( !isset($this->_cache[__FUNCTION__][intval($byTab)][intval($includeTransient)]) ){ $fields = $this->fields($byTab,false,$includeTransient); ............... }