Saludos,
Aunque han pasado algunos meses desde el último mensaje publicado en este hilo, como al final no se dió ninguna solución pues lo retomo.
Ayer me surgió el mismo problema: página que hace uso de ajax, pero que sólo funciona sin templates. Al parecer es un bug de D4PHP, pero en este enlace dan una solución:
http://forums.delphi-php.net/showthread.php?t=730
Resumiendo:
En el archivo
vcl\forms.inc.php hay que sustituir las funciones
dumpUsingTemplate() y
dumpHeaderJavascript() por estas:
Código:
function dumpUsingTemplate()
{
$this->processAjax();
//Check here for templateengine and templatefilename
if (($this->ControlState & csDesigning) != csDesigning)
{
$tclassname=$this->_templateengine;
$template=new $tclassname($this);
$template->FileName=$this->_templatefilename;
$template->initialize();
// I added the smarty object to the OnTemplate event params
// so you can do $params["smarty"]->assign("ITEM","Value")
$this->callEvent(
"ontemplate",
array("template"=>$template,"smarty"=>$template->_smarty)
);
$template->assignComponents();
$template->dumpTemplate();
}
}
Código:
function dumpHeaderJavascript($return_contents=false)
{
global $output_enabled;
if ($output_enabled)
{
ob_start();
$this->dumpChildrenJavascript();
$js=ob_get_contents();
ob_end_clean();
$sp='';
if (trim($js)!="" || trim($ajax_js)!="")
{
$sp="<script type=\"text/javascript\">\n";
$sp.="<!--\n";
$sp.=$js;
$sp.="-->\n";
$sp.="</script>\n";
}
// ajax js
if ($this->_useajax){
global $xajax;
$sp=$xajax->getJavascript(
"",VCL_HTTP_PATH."/xajax/xajax_js/xajax.js"
).$sp;
}
if ($return_contents)
{
return($sp);
} else {
echo $sp;
}
}
}
y añadir esta otra:
Código:
function processAjax(){
// do ajax stuff, this was after:
// if ($this->_ismaster) return;
// in dumpContents, you could replace the code
// there for
// $this->processAjax();
if ($this->_useajax)
{
if (($this->ControlState & csDesigning) != csDesigning)
{
use_unit("xajax/xajax.inc.php");
//AJAX support
global $xajax;
// Instantiate the xajax object. No parameters defaults
//requestURI to this page, method to POST, and debug to
// off
$xajax = new xajax();
// Uncomment next line to turn debugging on
// $xajax->debugOn();
// Specify the PHP functions to wrap. The JavaScript
//wrappers will be named xajax_functionname
$xajax->registerFunction("ajaxProcess");
// Process any requests. Because our requestURI is the
// same as our html page,
// this must be called before any headers or HTML output
// have been sent
$xajax->processRequests();
//AJAX support
}
}
}
Después, en el archivo
vcl\smartytemplate.inc.php, sustituir la función
assignComponents() por esta:
Código:
function assignComponents()
{
$form=$this->owner;
$this->_smarty->assign('HeaderCode',
$form->dumpChildrenHeaderCode(true).$form->dumpHeaderJavascript(true));
$this->_smarty->assign('StartForm',
$form->readStartForm());
$this->_smarty->assign('EndForm', $form->readEndForm());
reset($form->controls->items);
while (list($k,$v)=each($form->controls->items))
{
if ($v->Visible)
{
$temp="<SPAN
id='{$v->Name}_outer'>".$v->show(true)."</SPAN>";
$this->_smarty->assign($v->Name, $temp);
}
}
}
Por supuesto, antes de modificar nada, haced copia de seguridad de ambos ficheros.
Saludos.