Page 1 of 1

PHP action and template?

PostPosted: Wed Nov 24, 2010 1:44 am
by fabien_ecl
I have in my action directory the following calculate function
Code: Select all
-<?
class actions_calculate_selected {
function handle(&$params){
--- beginning of the function cut for better viewing--
echo "<br>Temps total des sélections : ". sec_to_time($ElapsedTimeSeconds);
echo "<br>Coût forfaitaire total des sélections : ". $Money_forfait ."€";
echo "<br>Coût salarial des sélections : ". $Money_salaire ."€";
echo "<br>Frais d'hébergement total des sélections : ". $Money_sleeping ."€";
//Affichage des noms de chantiers des lignes choisies
echo "<br>Résumé sur les chantiers : ";
while($row = mysql_fetch_row($cout_global))
{
echo "<br> <tr>";

// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo " <td>$cell</td> ";

echo "</tr>\n";
}
while($row = mysql_fetch_row($materiel_global))
{
echo "<br> <tr>";

// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo " <td>$cell</td> ";

echo "</tr>\n";
}


It works but it displays on a blank page : I suppose I have to deal with df_display() to solve my problem because I would like to have my results displayed in the xataface standard template. I read that for doing that, we must retunr an array in the df_display but 1) I don't know how to handle by foreach loop with df_display and secondly I would like to shape my results in a table inserted in the xataface standard frame : anyone can help please?
Thanx :D

Re: PHP action and template?

PostPosted: Wed Nov 24, 2010 10:32 am
by shannah
Yes that's right.

Code: Select all
df_display(array(), 'my_template.html');


In templates/my_template.html:
Code: Select all
{use_macro file="Dataface_Main_Template.html"}
    {fill_slot name="main_section"}

          My content here
    {/fill_slot}
{/use_macro}

Re: PHP action and template?

PostPosted: Wed Nov 24, 2010 1:59 pm
by fabien_ecl
Well, I understand this part :
Code: Select all

  {use_macro file="Dataface_Main_Template.html"}
        {fill_slot name="main_section"}

              My content here
        {/fill_slot}
    {/use_macro}


The problem is about " My content here" because all I want to display is extracted from mysql query I use in my action application php with loops and so on.
For example, this part :
Code: Select all
while($row = mysql_fetch_row($materiel_global))
{
echo "<br> <tr>";

// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo " <td>$cell</td> ";

echo "</tr>\n";

can't be dissociated from the action application. In the example above, $cell does not exist outside of the loop so how do I transfer it to the template : use of parameters such as arrays to transfer them by df_display to the template?
By the way thanx for answering so often :-))

Re: PHP action and template?

PostPosted: Wed Nov 24, 2010 2:29 pm
by shannah
The first parameter of df_display() is an associative array that defines the variables that are to be made available to the template.
you can store the results of your mysql query in this parameter then use it in the template.

For more information about what is possible with smarty templates, see the smarty website:
http://www.smarty.net

-Steve