Prev | Current Page 345 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

Create a new template file in the presentation/templates directory named search_results.tpl,
and add the following code to it:
{* search_results.tpl *}

Search results


{include file="products_list.tpl"}
2. Modify the presentation/products_list.php file by adding the following lines at the beginning of the
ProductsList class constructor, __construct():
// Retrieve the search string and AllWords from the query string
if (isset ($_GET['SearchResults']))
{
$this->mSearchString = trim(str_replace('-', ' ', $_GET['SearchString']));
$this->mAllWords = isset ($_GET['AllWords']) ? $_GET['AllWords'] : 'off';
}
CHAPTER 8 ?–  SEARCHING THE CATALOG 242
3. Add the $mSearchDescription, $mAllWords, and $mSearchString members to the ProductsList
class, located in the same file:
class ProductsList
{
// Public variables to be read from Smarty template
public $mPage = 1;
public $mrTotalPages;
public $mLinkToNextPage;
public $mLinkToPreviousPage;
public $mProductListPages = array();
public $mProducts;
public $mSearchDescription;
public $mAllWords = 'off';
public $mSearchString;
// Private members
private $_mDepartmentId;
private $_mCategoryId;
4. Modify the init() method in ProductsList class like this:
public function init()
{
/* If searching the catalog, get the list of products by calling
the Search business tier method */
if (isset ($this->mSearchString))
{
// Get search results
$search_results = Catalog::Search($this->mSearchString,
$this->mAllWords,
$this->mPage,
$this->mrTotalPages);
// Get the list of products
$this->mProducts = $search_results['products'];
// Build the title for the list of products
if (count($search_results['accepted_words']) > 0)
$this->mSearchDescription =
'

Products containing '
.


Pages:
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357

kino azjatyckie bwin out of home advertising Bukmacher pinacle zakłady bukmacherskie