search function in smarty
How to include .php file in smarty, processing $_POST data from search
input in Smarty and display results in .tpl file? how to correctly define
search.php in smarty controller or configuration file? i'm currently
beginner in smarty engine and don't know many things and tricks about this
engine
index.php smarty core
<?php
//ob_start('ob_gzhandler');
$t1 = microtime ( 1 );
session_start ();
header ( "Content-Type: text/html; charset=utf-8" );
require_once ("inc/initf.php");
//require_once("/verjani/public_html/inc/search.php");//how to include ?
$smarty = new Smarty ();
// $smarty->debugging = true;
// $smarty->error_reporting = E_ALL & ~E_NOTICE;
$smarty->cache_dir = THEM_PATH . "/cache";
$smarty->template_dir = THEM_PATH . "/template";
$smarty->compile_dir = THEM_PATH . "/template_c";
Helper::register($smarty);
$frontEnd = new frontEnd ();
$module = $frontEnd->getModule ();
$module->viewHeaders ();
if ($module->displayTpl !== false) {
$smarty->assign ( 'COOKIE', $_COOKIE );
$smarty->assign ( 'this', $module );
$smarty->display ( $module->displayTpl, md5 ( $_SERVER ['REQUEST_URI']
) );
}
$t = microtime();
echo '<!--'.$t.'-->';
search.php from
http://www.smarty.net/docs/en/language.function.foreach.tpl#idp8696576
<?php
include('Smarty.class.php');
$smarty = new Smarty;
$dsn = 'mysql:host=localhost;dbname=test';
$login = 'test';
$passwd = 'test';
// setting PDO to use buffered queries in mysql is
// important if you plan on using multiple result cursors
// in the template.
$db = new PDO($dsn, $login, $passwd, array(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$res = $db->prepare("select * from users");
$res->execute();
$res->setFetchMode(PDO::FETCH_LAZY);
// assign to smarty
$smarty->assign('res',$res);
$smarty->display('index.tpl');?>
?>
header.tpl.html
<form method="post" action="../search.php" class="searchform cf">
<input type="text" placeholder="">
<button type="submit">Search</button>
</form>
No comments:
Post a Comment