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/

eZ debug

Timing: Jan 18 2025 20:48:58
Script start
Timing: Jan 18 2025 20:48:58
Module start 'content'
Timing: Jan 18 2025 20:48:59
Module end 'content'
Timing: Jan 18 2025 20:48:59
Script end

Main resources:

Total runtime1.6136 sec
Peak memory usage4,096.0000 KB
Database Queries197

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0082 587.9844180.7969
Module start 'content' 0.00821.4513 768.7813556.8203
Module end 'content' 1.45950.1540 1,325.6016336.7109
Script end 1.6135  1,662.3125 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.2627210.0002
Check MTime0.00140.0898210.0001
Mysql Total
Database connection0.00120.072710.0012
Mysqli_queries1.536995.24941970.0078
Looping result0.00210.12961950.0000
Template Total1.571997.420.7860
Template load0.00220.137820.0011
Template processing1.569797.281420.7849
Template load and register function0.00020.014610.0002
states
state_id_array0.00280.173610.0028
state_identifier_array0.00160.097920.0008
Override
Cache load0.00180.1108330.0001
Sytem overhead
Fetch class attribute can translate value0.00150.092630.0005
Fetch class attribute name0.00130.079650.0003
XML
Image XML parsing0.00100.059430.0003
class_abstraction
Instantiating content class attribute0.00000.001160.0000
General
dbfile0.00310.1935270.0001
String conversion0.00000.000330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs