Different 'view' templates per table?

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

Postby dwe » Mon Sep 04, 2006 5:34 am

Hi,
first of all - it`s an awsome tool :)
I`ve been able to convert most of our small but helpfull sheets that contained much to many redundant
(and often wrong data) into an nicely structured nomalized database in one afternoon :))

A question (ok, several ones, in fact, but this ones my most pressing) popped up:
- is it possible to have a different template for the read-only 'view' of recorddata on a per-table basis?
I`ve thought about overriding Dataface_Record_Template.html and making it 'redirect' to a template based
on the tablename passed if a view_tablename.tpl exists.

This would making formatting of record-data (eg. format the content of a cell as link) and adding export funtions easy.

Many thanks,
dwe
dwe
 
Posts: 8
Joined: Wed Dec 31, 1969 5:00 pm

Postby dwe » Mon Sep 04, 2006 6:32 am

Addendum:
Regarding: 'Error References -> Fatal error: Allowed memory size of 4194304 bytes exhausted (tried to allocate 46080 bytes)'

While working on the approach mentioned above, i found that the smarty debug function is still broken - it will abort with
'memory exhausted', regardless how much memory is aviable and with very small tables (~100 records, 512Mb Ram in php.ini,
and the latest dataface version).

An easy workaround to get a dump of all variables and values of a running app is to use


{php}
print_r("
");
print_r($this->_tpl_vars)
{/php}

on top of the template.
dwe
 
Posts: 8
Joined: Wed Dec 31, 1969 5:00 pm

Postby Aoirthoir » Mon Sep 04, 2006 11:30 am

DWE,

Dataface has a really easy way to change the look and feel of every part of the application. You need to create two folders in your application, or, to change a template for a specific table you need to create those same two folders in the folder for the table thusly:

yourdatafaceappdir/templates
yourdatafaceappdir/templates_c

yourdatafaceappdir/tables/tablename/templates
yourdatafaceappdir/tables/tablename/tempaltes_c

In both cases, templates_c must be writable by the web browser. Usually on linux that means world writable (chmod 777).

To find out more details please click this link:

http://framework.weblite.ca/documentation/tutorial/getting_started/changing-look-and-feel
Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby Aoirthoir » Mon Sep 04, 2006 11:31 am

Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby dwe » Mon Sep 04, 2006 12:11 pm

Aoirthoir,
many thanks for the fast reply.
The documentation didn`t make it clear (or i`ve not seen it) that the method mentioned above is also working on per-table level, i thought it was just a way to overide the default templates on per-application level.

So, to change the 'view' of table 'somename', i create the templates and templates_c folders and just put the customized Dataface_Record_Template.html in the template folder?

(I`ll try it tomorrow, nevertheless: wading through the raw data was very interesting... :)

greetings,
dwe
dwe
 
Posts: 8
Joined: Wed Dec 31, 1969 5:00 pm

Postby Aoirthoir » Mon Sep 04, 2006 1:30 pm

Your welcome. I've not modified the dataface specs yet using templates, other than the Samples Mr. Steve has provided. But I believe you have the correct template in mind.

If you are on unix or linux (and probably mac since it runs unix in the back end) you can SSH in any time and make changes. If not, you can use a linux distro or hosting service for testing when you are away, and then just tar up the entire dataface application directory structure and move it to your real server. It is what I do.
Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby zopemgr » Mon Sep 04, 2006 11:58 pm

Hi Dwe,

The best way to achieve this is to implement the block__view_tab_content() method in the delegate class of the table you wish to customize.

See http://framework.weblite.ca/documentation/tutorial/customizing-the-dataface-look-and-feel/customizing

Specifically the section on "Overriding blocks". The block name that you will override is "view_tab_content".

Hope this helps a little.

Best regards

Steve
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm

Postby zopemgr » Tue Sep 05, 2006 12:00 am

The reason why the smarty debug doesn't work is because dataface makes extensive use of variable references between objects of the system. This causes infinite recursion when you try to just to a smarty variable dump.
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm

Postby dwe » Tue Sep 05, 2006 7:21 am

Hi Steve,
Thanks a lot for the answer.
Yes, this helps - a little :)
With the delegate class i ran into the problem that i don`t know how to access the resultset of the already run query.
My hope was that a simple '{include file="sometemplate"}' as output/return from block__view_tab_content_off()
would be sufficient, but (of course?) the output is handled literally and not parsed by smarty.
I`ve looked at the api-documentation wiki at the Dataface_SkinTool functions but to no avail.

As a quick (and very dirty) hack I`m now overring the Dataface_View_Record.html with a new one that basicaly contains:

{if $ENV.table eq "contact_table"}
{include file="NmsDb_View_Contact_Record.html"}
{else}
{include file="Dataface_View_Record_Default.html"}
{/if}

The 'default' is the original Dataface_view_Record.html template.
Though this works very fine, I`m still very interested in doing it the 'proper' way :)

Best regards,
dwe

btw: using dataface is fun!
dwe
 
Posts: 8
Joined: Wed Dec 31, 1969 5:00 pm

Postby zopemgr » Tue Sep 05, 2006 8:17 am

Accessing the result set:

Code: Select all
$app =& Dataface_Application::getInstance();
$resultSet =& $app->getResultSet();
$record =& $app->getRecord();   // the current record


-Steve
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm

Postby dwe » Tue Sep 05, 2006 8:30 am

Hi Steve,
great! That was the missing link!
I tried Dataface_SkinTool::getInstance()...

Best regards,
dwe
dwe
 
Posts: 8
Joined: Wed Dec 31, 1969 5:00 pm

Postby zopemgr » Tue Sep 05, 2006 9:42 am

This SkinTool just manages templates. You will seldom have to call it directly.

To display a template use the df_display() method.
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 34 guests

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