Dataface actions

119 views
Skip to first unread message

Rudolph Matongo

unread,
Nov 9, 2015, 11:11:38 AM11/9/15
to Xataface
I am using xataface to build an application and I read about uisng actions from the xataface.com website.  I worked through the helloworld example in the link-> http://xataface.com/documentation/tutorial/getting_started/dataface_actions and I finished the earlier sections, when it came to the Accessing Application Information from your Action Controller section as I tried to  access current state of the application it gave a warning message 

  

These are the messages below.

Warning: array_keys() expects parameter 1 to be array, null given in C:\xampp\htdocs\school\xataface\Dataface\Record.php on line 4784
Warning: reset() expects parameter 1 to be array, null given in C:\xampp\htdocs\school\xataface\Dataface\Record.php on line 4800

I don't have much knowledge of php

Can anyone please help me with this


Here is a copy of the file I was trying.

<?php
class actions_hello {
function handle(&$params){
$app =& Dataface_Application::getInstance(); // reference to Dataface_Application object
$auth =& Dataface_AuthenticationTool::getInstance(); // reference to Dataface_Authentication object

$request =& $app->getQuery(); // Request vars: e.g. [-table]=>'Students', [-action]=>'hello'
$user =& $auth->getLoggedInUser(); // Dataface_Record object of currently logged in user.

$current_tablename =& $request['-table'];

$current_record =& $app->getRecord(); // Currently selected record (Dataface_Record object)
$results =& $app->getResultSet(); // Current found set (Dataface_QueryTool object).

// Iterating through the results
$it =& $results->iterator();
while ($it->hasNext() ){
$record =& $it->next(); // $record is a Dataface_Record object
print_r($record->strvals());
unset($record); // necessary so that PHP doesn't just keep overwriting the same object.
}

// Perform a custom SQL Query:
$res = mysql_query("select * from foo inner join bar on foo.x=bar.y", $app->db());
// .. etc ...

// Obtain parameters from the actions.ini file for this action:
$template_name = $params['action']['template']; // The value of the template parameter

df_display(array(), $template_name); // this form allows you to change the template to use by modifying the actions.ini file.

}
}
?>

Steve Hannah

unread,
Nov 9, 2015, 1:35:08 PM11/9/15
to xata...@googlegroups.com
This is very strange.  If you just display the same query but with -action=list, are there any results?  

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at http://groups.google.com/group/xataface.
To view this discussion on the web visit https://groups.google.com/d/msgid/xataface/5a7101bf-067c-4cd2-aea9-200166622854%40googlegroups.com.



--
Steve Hannah
Web Lite Solutions Corp.

Rudolph Matongo

unread,
Nov 9, 2015, 2:25:05 PM11/9/15
to Xataface
The same url with -action=list displays the list of items in the first table of the database...

Rudolph Matongo

unread,
Nov 9, 2015, 2:27:56 PM11/9/15
to Xataface
In short,yes there is a result after sending the request with -action=list

Steve Hannah

unread,
Nov 9, 2015, 2:29:29 PM11/9/15
to xata...@googlegroups.com
Is that original copy paste exactly what you have in your action file?  (I can tell from the styling that you pasted it from the tutorial and not from your text editor).
Some things like the mysql_query will obviously fail in your local version.

What happens if you just put a basic echo statement in your action instead of this whole thing.  Can you see the result of your echo statement?

On Mon, Nov 9, 2015 at 11:25 AM, Rudolph Matongo <mat...@gmail.com> wrote:
The same url with -action=list displays the list of items in the first table of the database...
--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at http://groups.google.com/group/xataface.

Rudolph Matongo

unread,
Nov 9, 2015, 3:07:03 PM11/9/15
to Xataface
Okay here is the code from my actual actions file 

<?php
class actions_hello {
    function handle(&$params){
        $app =& Dataface_Application::getInstance();  // reference to Dataface_Application object
        
        $auth =& Dataface_AuthenticationTool::getInstance(); // reference to Dataface_Authentication object
        
        $request =& $app->getQuery();  // Request vars:  e.g. [-table]=>'Students', [-action]=>'hello'
        //print_r($request);
        $user =& $auth->getLoggedInUser();  // Dataface_Record object of currently logged in user.
        print_r($user);
        $current_tablename =& $request['-table'];
        //print_r($current_tablename);

       $current_record =& $app->getRecord();  // Currently selected record (Dataface_Record object)
       print_r($current_record);
       $results =& $app->getResultSet();  // Current found set (Dataface_QueryTool object).
       //print_r($results);
       

        // Iterating through the results
        $it =& $results->iterator();
       while ($it->hasNext() ){
            $record =& $it->next(); // $record is a Dataface_Record object
            print_r($record->strvals());
            unset($record);  // necessary so that PHP doesn't just keep overwriting the same object.
        }
       
        // Perform a custom SQL Query:
       $res = mysql_query("select * from foo inner join bar on foo.x=bar.y", $app->db());
       // .. etc ...

       // Obtain parameters from the actions.ini file for this action:
       $template_name = $params['action']['template'];  // The value of the template parameter

       df_display(array(), $template_name);  // this form allows you to change the template to use by modifying the actions.ini file.

    }
}
?>

Now I just realised I forgot to change the mysql_query, I am sorry about that.Anyway I changed the query and the warning came up again
I tried the echo statement and I can see the result from it, though.
Below is the new code

<?php
class actions_hello {
    function handle(&$params){
        $app =& Dataface_Application::getInstance();  // reference to Dataface_Application object
        
        $auth =& Dataface_AuthenticationTool::getInstance(); // reference to Dataface_Authentication object
        
        $request =& $app->getQuery();  // Request vars:  e.g. [-table]=>'Students', [-action]=>'hello'
        //print_r($request);
        $user =& $auth->getLoggedInUser();  // Dataface_Record object of currently logged in user.
        print_r($user);
        $current_tablename =& $request['-table'];
        //print_r($current_tablename);

       $current_record =& $app->getRecord();  // Currently selected record (Dataface_Record object)
       print_r($current_record);
       $results =& $app->getResultSet();  // Current found set (Dataface_QueryTool object).
       //print_r($results);
       

        // Iterating through the results
        $it =& $results->iterator();
       while ($it->hasNext() ){
            $record =& $it->next(); // $record is a Dataface_Record object
            print_r($record->strvals());
            unset($record);  // necessary so that PHP doesn't just keep overwriting the same object.
        }
       
        // Perform a custom SQL Query:
       $res = mysql_query("SELECT * FROM `homework` inner join `payments` on `homework.username`=`payments.username` ", $app->db());
       // .. etc ...

       // Obtain parameters from the actions.ini file for this action:
       $template_name = $params['action']['template'];  // The value of the template parameter

       df_display(array(), $template_name);  // this form allows you to change the template to use by modifying the actions.ini file.

    }
}
?>

Rudolph Matongo

unread,
Nov 10, 2015, 10:20:02 PM11/10/15
to Xataface
Hello Steve
Did you get a chance to look at the code I posted?                  

Steve Hannah

unread,
Nov 11, 2015, 12:03:50 AM11/11/15
to xata...@googlegroups.com
If you add a call to 
$results->loadSet(); 
before the line  
$it =& $results->iterator();

Does it fix this issue for you?

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at http://groups.google.com/group/xataface.

Rudolph Matongo

unread,
Nov 11, 2015, 2:21:54 AM11/11/15
to Xataface
yes that fixed it, thanks comrade!
Reply all
Reply to author
Forward
0 new messages