PHP action and template?

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

PHP action and template?

Postby fabien_ecl » Wed Nov 24, 2010 1:44 am

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
fabien_ecl
 
Posts: 9
Joined: Wed Nov 10, 2010 6:14 am

Re: PHP action and template?

Postby shannah » Wed Nov 24, 2010 10:32 am

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}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: PHP action and template?

Postby fabien_ecl » Wed Nov 24, 2010 1:59 pm

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 :-))
fabien_ecl
 
Posts: 9
Joined: Wed Nov 10, 2010 6:14 am

Re: PHP action and template?

Postby shannah » Wed Nov 24, 2010 2:29 pm

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 19 guests

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