Good work!!
Archived from the Xataface Users forum.
jvkranenburg — Mon Jul 17, 2006 7:28 pm
Hi Steve,
First of all, the new version of Dataface looks very good to me. Lot of new functions including the custom actions.
When I want to create a custom action that needs to do some query’s over the database an shows the results in a list, how do I start?
Kind regards,
Jerry
shannah — Mon Jul 17, 2006 11:53 pm
Hi Jerry,
Thanks for the compliments. I haven’t written this part of the tutorial (there are about 7 more sections that need to be written to cover the new features in this version), but here’s the gist.
In the tutorial I have only showed one half of the actions framework (using the actions.ini file and a template). For more complicated things, you will also need a custom action handler.
Continuing the hello world example:
Your actions.ini file has:
[hello]
template=HelloWorld.html
Add a folder to your application named “actions”.
Inside this folder, add a file named “hello.php” with the following contents:
- Code: Select all
<br /class actions_hello { function handle($params){ $res = mysql_query("SELECT Foo FROM Bar where Foo.bar='1'"); $records = array(); while ( $row = mysql_fetch_assoc($records) ){ $records[] = $row; } $context['records'] =& $records; df_display($context, 'HelloWorld.html'); } } ?>
Then in your HelloWorld.html file it would become something like:
- Code: Select all
- `{use_macro file=”Dataface_Main_Template.html”}
{fill_slot name=”main_section”}
{foreach from=$records item=record}Name: {$record.name} - Description: {$record.description}
{/foreach}
{/fill_slot}
{/use_macro}`
Note that you can also have your action show up along with other actions (e.g. the details, list, find tabs) by setting a category attribute.
e.g.
[hello]
category = “table_tabs” ; Causes it to show up in the details/find/list tabs
;category = “table_actions” ;; this would cause it to show in the actions menu (new record, show all, etc..)
;category = “result_list_actions” ;; Shows up in the top right of result lists (as an icon only).
url = “{$this->url(‘-action=>hello’)}”
label = “Hello World”
description = “Does the Hello world action”
icon = “myicon.gif”
For a good idea of the available options, look at the dataface/actions.ini file. A brief description of the options are:
url : the url that should be called when the action is clicked (this can be any url - php statements inside curly braces - $this is a reference to the application object. $this->url(‘-action=hello’) builds a url to the application but with -action =hello.
icon : The icon that is displayed next to the action (if applicable).
Hope this helps.. better tutorial coming soon
Best regards
Steve
jvkranenburg — Tue Jul 18, 2006 12:44 am
This is really great!! Exactly that I needed!!
Thinks for the quick reply!
Jerry
shannah — Tue Jul 18, 2006 1:40 am
Another thing to note is that since Dataface 0.6 has a “View” tab for each record, it may be appropriate to just override the contents of this tab to display certain reports - rather than making a whole new action.
That can be done in the delegate class as follows:
- Code: Select all
- `class tables_MyTable {
function block__view_tab_contents(){
echo “Now this text will be displayed in the “View” tab instead of the default content
But it would probably be better to use templates for output rather than
echo statements: use the df_display() function!”;
// If you need to access the current record do:
$app =& Dataface_Application::getInstance();
$currentRecord =& $app->getRecord(); // $currentRecord is a Dataface_Record object// If you need to access the current result set do:
$results =& $app->getResultSet(); // $results is a Dataface_QueryTool object// If you need to access query variables do:
$query =& $app->getQuery();
// e.g. $query[‘-table’] has name of current table
// $query[‘-relationship’] has name of current relationship if specified.
// Benefit of using this approach rather than using $_GET or $_REQUEST
// directly is that this contains more information as dataface fills in
// missing information from the request with default values – e.g. $query[‘-table’]
// is ALWAYS defined.}
}`
Best regards
Steve
belly — Thu Oct 19, 2006 9:26 am
Hi Steve.
belly — Thu Oct 19, 2006 9:27 am
whoops…
shannah — Thu Oct 19, 2006 9:30 am
Thanks for pointing this out.. i have corrected it now.
-Steve
belly — Thu Oct 19, 2006 10:10 am
now THAT’S service!
BTW I’m doing this dev work on my laptop in a hospital room while my wife convalesces from surgery earlier this week. Thanks to WiFi at the hospital and your quick response, I’m actually doing something productive rather than watching TV all week.
Thanks again.