Forums / Developer / How do I get results from custom modules into $module_result.content

How do I get results from custom modules into $module_result.content

Author Message

Trond Åge Kvalø

Friday 12 March 2004 4:34:02 am

I've created a module that fetches data from a custom database table:

<?php
//get the current userid
$userid = &eZUser::currentUserID();

// Build module result array
// Why is this here???????
$Result = array();
$Result['userid'] = $userid;
$Result['path'] = array( array( 'url' => '/lisenser/vis',
                                'text' => "Vis lisenser") );

include_once( "lib/ezdb/classes/ezdb.php" );
$db =& eZDB::instance();
  // start a new transaction
  $db->begin();  //why use this when all tables are myISAM????

  // send the SQL SELECT command to the database
  $myquery="SELECT * from course_licenses WHERE userid='$userid'";
  $mycourseids =& $db->arrayQuery($myquery);
  foreach ($mycourseids as $courseid) {
	print( $courseid["courseid"] );
  }
  // commit the transaction
  $db->commit();  //why use this when all tables are myISAM????
?>

But the results are printed before the pagelayout.tpl. I.e. just before <!DOCTYPE HTML PUBLIC....>

Is there a way of getting the results into $module_result.content variable?

best regards
trondåge

trondåge

Eirik Alfstad Johansen

Friday 12 March 2004 6:55:39 am

Hi Trond Åge,

Store the content in $Result['content']

Sincerely,

Eirik Johansen

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Trond Åge Kvalø

Friday 12 March 2004 8:34:19 am

Thank you Eirik.

Now I have the following code:

include_once( "lib/ezdb/classes/ezdb.php" );
$db =& eZDB::instance();
  // start a new transaction
  $db->begin();  

  // send the SQL SELECT command to the database
  $myquery="SELECT * from course_licenses WHERE userid='$userid'";
  $Result['content'] =& $db->arrayQuery($myquery);

  // commit the transaction
  $db->commit();  

The result is now stored in $Result['content']. In my browser I now have a text that says Array where I expected the results.

It's progress, but I guess I need a template to display the content of this array correctly. The only problem is that I'm not sure how I would do that?

I see two possible solutions:

1) Create a node_view.full override and match it against my module and/or view.
2) Create templates for my module in the extension/mymodule/design/standard/templates/mymodule folder.

Anyone else got other solutions?

best regards
trondåge

trondåge

Eirik Alfstad Johansen

Friday 12 March 2004 2:40:54 pm

Hi Trond Åge,

As you might expect from the name, the arrayQuery method returns an array, meaning that you have to loop through it in the script to get the result you need to return.

Sincerely,

Eirik Johansen

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/