Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Smarty && Xajax

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
mellowonpsx
Smarty Rookie


Joined: 03 Jan 2008
Posts: 5

PostPosted: Fri Jan 04, 2008 1:48 pm    Post subject: Smarty && Xajax Reply with quote

[pre](my english suck, please take care of this)[/pre]
I've already work with smarty but not with ajax. Now i have some spare time and i want to build a template-engine based web application that use also ajax for transiction effect (suck as menus and so on).

I decide to use xajax and i start with this simple (crossover) code.

index.php
Code:
<?php

include_once("common_smarty.php");
include_once("common_xajax.php");

//--xajax--//
$xajax  =  inizializzaXajax();

$xajax->registerFunction("myFunction");

$xajax->processRequest();

//--smarty--//
$smarty = inizializzaSmarty();

$smarty->assign("title","Benvenuto");

$smarty->assign("xajax_javascript",$xajax->getJavascript("xajax/"));

$smarty->display("index.tpl");

?>


common_ajax.php
Code:

<?php

//my own function file
include_once("config.php");
include_once("auth.lib.php");
include_once("common_page.inc.php");
include_once("common_db.inc.php");

define("XAJAX_DIR", "./xajax/");
require(XAJAX_DIR."xajax.inc.php");

function inizializzaXajax()
{
 $xajax = new xajax();
 //debug mode on
 $xajax->debugOn();
 $xajax->statusMessagesOn();

 return $xajax;
}

function myFunction($arg)
{
 $newContent = "Value of \$arg: ".$arg;

 $objResponse = new xajaxResponse();

 $objResponse->assign("SomeElementId","innerHTML", $newContent);

 return $objResponse;
}

?>


common_smarty.php
Code:
<?php

include_once("config.php");
include_once("auth.lib.php");
include_once("common_page.inc.php");
include_once("common_db.inc.php");

define("SMARTY_DIR", "./Smarty/Libs/");
require(SMARTY_DIR."Smarty.class.php");

function inizializzaSmarty()
{
 $smarty = new Smarty();

 $smarty->template_dir = "templates/";
 $smarty->compile_dir = "templates_c/";
 $smarty->config_dir = "configs/";
 $smarty->cache_dir = "cache/";
 
  return $smarty;
}
?>


index.tlp
Code:
{* Smarty *}
{include file="header.tpl" title=$title xajax_javascript=$xajax_javascript}
<div id="SomeElementId">
</div>
<div id="Button">
 <button onclick="xajax_myFunction('It worked!');"> Clicca </button>
</div>
{include file="footer.tpl"}


header.tlp
Code:

{* Smarty Header *}
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
 <head>
  <title>AX.SY - AjaX SmartY (mellowonpsx project) / page {$title|nl2br} </title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="css/stilebase_ie.css" />
  <!--[if !IE]><!-->
   <link rel="stylesheet" type="text/css" href="css/stilebase.css" />
  <!--<![endif]-->
  {$xajax_javascript}
 </head>
 <body>
  <div id="testa">
   <p class="testo">
    {$title|nl2br}
   </p>
  </div>
{* End of Smarty Header *}


The proble is that the code generate this kind of error while i press te button.

Code:
Received: <br /> <b>Notice</b>: Undefined variable: sResponse in <b>c:\programmi\easyphp1-8\www\ax.sy\xajax\xajax.inc.php</b> on line <b>747</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at c:\programmi\easyphp1-8\www\ax.sy\xajax\xajax.inc.php:747) in <b>c:\programmi\easyphp1-8\www\ax.sy\xajax\xajax.inc.php</b> on line <b>763</b><br /> <?xml version="1.0" encoding="utf-8" ?><xjx><cmd n="as" t="SomeElementId" p="innerHTML">Value of $arg: It worked!</cmd></xjx>


Any idea?

[post]thanks all for help[/post]
Back to top
View user's profile Send private message
Manux
Smarty Rookie


Joined: 13 Nov 2007
Posts: 5

PostPosted: Fri Jan 04, 2008 8:52 pm    Post subject: Reply with quote

Undefined variable: sResponse

Is there anything you don't understand about this?
Back to top
View user's profile Send private message
mellowonpsx
Smarty Rookie


Joined: 03 Jan 2008
Posts: 5

PostPosted: Mon Jan 07, 2008 11:17 am    Post subject: Reply with quote

sResponse is in xajax.inc.php and i musn't define it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP