Good work!!

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

Postby 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
jvkranenburg
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby jvkranenburg » Tue Jul 18, 2006 12:44 am

This is really great!! Exactly that I needed!!

Thinks for the quick reply!

Jerry
jvkranenburg
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby belly » Thu Oct 19, 2006 9:26 am

>Hi Steve.



>First of all: Dataface is great! I'm trying to hack together a tracking system for

customers' units for our small electronics repair shop, and Dataface looks like

>just the thing to get it done.



>Right now, I'm trying to wrap my head around actions. Unfortunately, in my browser,

the 'hello.php' section in your example is missing. Here's what I see:

>


Inside this folder, add a file named "hello.php" with the following contents:

>




>


>



>

Could you please edit the post or repost this example, please?

>

Thanks!
belly
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby belly » Thu Oct 19, 2006 9:27 am

whoops...

some bad html there :)
belly
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Oct 19, 2006 9:30 am

Thanks for pointing this out.. i have corrected it now.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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.
belly
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 8 guests

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