shrong> somefile.php
include('libs/Smarty.class.php');
require( "configs/config.php" );
// create object
$smarty = new Smarty;
function homepage($params, $smarty, $numRows=1000000, $order="publicationDate DESC" ) {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM articles
ORDER BY " . mysql_escape_string($order) . " LIMIT :numRows";
$st = $conn->prepare( $sql );
$st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
$st->execute();
$list = array();
while ( $row = $st->fetch() ) {
$article = new Article( $row );
$list[] = $article;
}
// Now get the total number of articles that matched the criteria
$sql = "SELECT FOUND_ROWS() AS totalRows";
$totalRows = $conn->query( $sql )->fetch();
$conn = null;
return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];
if ( isset( $data['publicationDate'] ) ) $this->publicationDate = (int) $data['publicationDate'];
if ( isset( $data['title'] ) ) $this->title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['title'] );
if ( isset( $data['summary'] ) ) $this->summary = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['summary'] );
if ( isset( $data['content'] ) ) $this->content = $data['content'];
$results = array();
$results['articles'] = $data['articles'];
$results['totalRows'] = $data['totalRows'];
$smarty->assign("articles", $data['articles']);
$smarty->assign("totalRows", $data['totalRows']);
$smarty->assign("id", $data['id']);
$smarty->assign("publicationDate", $data['publicationDate']);
$smarty->assign("title", 'kkkkkkkkkkkkkkkkkkkkk');
$smarty->assign("summary", 'lllllllllllllllllllllll');
$smarty->assign("content", 'øøøøøøøøøøøøøøøøøøøøøøøøøøøøøø');
}
// display it
$smarty->display('index2.tpl');
index2.tpl
{include file="header.tpl"}
{debug}
Article Archive
{assign var=results value={cycle values="totalRows,articles,title,publicationDate,id"}}
- {foreach $articles['articles'] as $article}
-
{$publicationDate}{$title}
{$summary}
{/foreach}
{include file="footer.tpl"}
< /code>
Ошибки, которые я получаю: < /p>
Notice: Undefined index: articles in /var/www/www.mypage.com/htdocs/smarty/templates_ ... x2.tpl.php on line 42
Notice: Trying to get property of non-object in /var/www/www.mypage.com/htdocs/smarty/templates_ ... x2.tpl.php on line 42
Подробнее здесь: https://stackoverflow.com/questions/222 ... -object-in