本文整理匯總了PHP中Tpl::getVar方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tpl::getVar方法的具體用法?PHP Tpl::getVar怎麽用?PHP Tpl::getVar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tpl
的用法示例。
在下文中一共展示了Tpl::getVar方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: smarty_function_newsList
/**
*
* 新聞列表調用函數
*
* @param array $params
* @param Tpl $tpl
* @param bool $repeat
*/
function smarty_function_newsList($params, &$tpl)
{
$values = array();
$types = array();
/* @var $acStr ZeActiveString */
$acStr = new ZeActiveString();
$acStr->putAll(array('select' => 'SELECT
`id`,`title`,`category`
,`detail`,`create_time`,`edit_time`
FROM news_e news ', 'count' => 'SELECT count(1) FROM news_e news ', 'where' => 'WHERE 1=1 ', 'where.category' => 'AND `category` = :category ', 'where.category.set' => 'AND FIELD(`category`,:categorys) > 0 ', 'where.search' => 'AND (`title` LIKE "%" || :search || "%"
OR `detail` LIKE "%" || :search || "%") ', 'order' => 'ORDER BY ', 'order.id.desc' => '`id` DESC ', 'order.id.asc' => '`id` ASC ', 'order.editTime.desc' => '`edit_time` DESC ', 'order.editTime.asc' => '`edit_time` ASC ', 'limit' => 'LIMIT :offset,:pageSize '));
$acStr->active('count');
$acStr->active('where');
/* @var $category Integer 分類編號 */
$category = $tpl->getArg($params, 'category', null);
$category = !is_null($category) ? $category : $tpl->getVar('info.category');
/* 默認分類選擇到的是 0 ,有時需要僅調用默認分類信息,所以將-1指定為所有分類 */
if ($category > -1) {
if (strpos($category, ',') === FALSE) {
$values['category'] = $category;
$types['category'] = PDO::PARAM_INT;
$acStr->active('where.category');
} else {
$values['categorys'] = $category;
$types['categorys'] = PDO::PARAM_STR;
$acStr->active('where.category.set');
}
}
/* @var $search string 搜索 標題,內容 */
$search = $tpl->getArg($params, 'search');
$search = $search = $search ? $search : $tpl->getVar('info.search');
if (!empty($search)) {
$values['search'] = $search;
$types['search'] = PDO::PARAM_STR;
$acStr->active('where.search');
}
/* @var $recorder ZeRecorder */
$recorder = new ZeRecorder(Conn::getConn());
/* @var $pageSet ZePageSet */
$pageSet = $tpl->getPageSet($params);
/* @var $pageAs String */
$pageAs = $tpl->getArg($params, 'pageAs', null);
if (!is_null($pageAs)) {
$sql = $acStr->toString();
$recordCount = $recorder->query($sql)->bind($values, $types)->getInt();
$pageSet->setRecordCount($recordCount);
$tpl->assign($pageAs, $pageSet);
}
$acStr->update('count', 'select');
/**
* order
*/
$order = $tpl->getArg($params, 'order');
$order = $order ? $order : $tpl->getVar('info.order', 'editTime.desc');
if (!empty($order) && in_array($order, array('id.desc', 'id.asc', 'editTime.desc', 'editTime.asc'))) {
$acStr->active('order');
$acStr->active('order.' . $order);
}
/**
* limit
*/
$acStr->active('limit');
$values['offset'] = $pageSet->getOffset();
$types['offset'] = PDO::PARAM_INT;
$values['pageSize'] = $pageSet->getPageSize();
$types['pageSize'] = PDO::PARAM_INT;
$sql = $acStr->toString();
$list = $recorder->query($sql)->bind($values, $types)->fetchAll();
$as = $tpl->getArg($params, 'as', 'news_list');
$tpl->assign($as, $list);
}