Estou desenvolvendo uma aplicação de sistema de informação geográfica pra web , pra uma entidade ligada a universidade.
Resolvi utilizar o padrão MVC e para isso estou pensando em construir um mini-framework utilizando SMARTY + XAJAX + ADODB.
Já fiz alguns projetos com Smarty e Adodb e mais recentemente Xajax e Adodb, então parei e pensei, porque não usar os 3 juntos( Smarty, Xajax, Adodb )
Por enquanto ainda estou trabalhando no framework MVC que utilizará como base o trio acima, mas já vou adiantando como fazer o Xajax e o Smarty e o Adodb funcionarem juntos
Para este pequeno tutorial, fiz o seguinte
Criei uma pasta com o nome "teste" e dentro dela coloquei o Smarty2.6.18, Xajax0.5 e Adodb501
Criando a estrutura de diretórios abaixo
teste
| adodb
|
| xajax
| | xajax_core ...
|
| smarty
| | libs
| | templates ...
Agora o código:
Primeiro só Smarty + Xajax
Arquivo teste.php
<?phpdefine('SMARTY_DIR','smarty/libs/');require_once(SMARTY_DIR.'Smarty.class.php');require_once( 'xajax/xajax_core/xajax.inc.php' );$xajax = new xajax();function myFunction(){ $objResponse = new xajaxResponse(); $objResponse->assign("SomeElementId", "innerHTML", 'Xajax + Smarty'); return $objResponse;}$xajax->registerFunction("myFunction");$xajax->processRequest();$smarty = new Smarty;$smarty->template_dir = 'smarty/templates/';$smarty->compile_dir = 'smarty/templates_c/';$smarty->config_dir = 'smarty/configs/';$smarty->cache_dir = 'smarty/cache/';$smarty->caching = true;$smarty->assign('name','Smarty');$smarty->assign('xajax_javascript', $xajax->getJavascript('xajax/'));$smarty->display('index.tpl');?>
Arquivo index.tlp
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>{$name}</title>{$xajax_javascript}</head><body>{$name}<br /><br /><div id="SomeElementId"></div><br /><br /><input value="Xajax" type="button" onclick="xajax_myFunction();" /></body></html>
Agora é só colocar o Adodb pra funcionar, e para isso é só fazer o seguinte.
Arquivo teste.php
require_once( 'adodb/adodb.inc.php' );
$xajax = new xajax();
function myFunction()
{
$conn = &ADONewConnection( 'Oci8' );
$conn->PConnect( 192.0.0.1, 'user', 'pws', 'oraSID' );
$query = "select NOME from USUARIOS where ID = 0 ";
$recordSet = &$conn->Execute( $query );
if( !$recordSet->EOF ) {
$var = $recordSet->fields['NOMEUSU'];
} else {
$var = ''Usuario Inexistente;
}
$objResponse = new xajaxResponse();
$objResponse->assign("SomeElementId", "innerHTML", $var);
return $objResponse;
}
$xajax->registerFunction("myFunction");
$xajax->processRequest();
$smarty = new Smarty;
$smarty->template_dir = 'smarty/templates/';
$smarty->compile_dir = 'smarty/templates_c/';
$smarty->config_dir = 'smarty/configs/';
$smarty->cache_dir = 'smarty/cache/';
$smarty->caching = true;
$smarty->assign('name','Smarty');
$smarty->assign('xajax_javascript', $xajax->getJavascript('xajax/'));
$smarty->display('index.tpl');
?> _linenums:0'><?phpdefine('SMARTY_DIR','smarty/libs/');require_once(SMARTY_DIR.'Smarty.class.php');require_once( 'xajax/xajax_core/xajax.inc.php' );<strong class='bbc'>require_once( 'adodb/adodb.inc.php' );</strong>$xajax = new xajax();function myFunction(){ <strong class='bbc'>$conn = &ADONewConnection( 'Oci8' ); $conn->PConnect( 192.0.0.1, 'user', 'pws', 'oraSID' ); $query = "select NOME from USUARIOS where ID = 0 "; $recordSet = &$conn->Execute( $query ); if( !$recordSet->EOF ) { $var = $recordSet->fields['NOMEUSU']; } else { $var = ''Usuario Inexistente; }</strong> $objResponse = new xajaxResponse(); $objResponse->assign("SomeElementId", "innerHTML", <strong class='bbc'>$var</strong>); return $objResponse;}$xajax->registerFunction("myFunction");$xajax->processRequest();$smarty = new Smarty;$smarty->template_dir = 'smarty/templates/';$smarty->compile_dir = 'smarty/templates_c/';$smarty->config_dir = 'smarty/configs/';$smarty->cache_dir = 'smarty/cache/';$smarty->caching = true;$smarty->assign('name','Smarty');$smarty->assign('xajax_javascript', $xajax->getJavascript('xajax/'));$smarty->display('index.tpl');?>
Por enquanto é isso.
Assim que tiver avanço no framework, estarei postando mais.
Abraços