Prev | Current Page 339 | Next

Emilian Balanescu and Cristian Darie

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


Creating the Search Box
Follow the steps in the exercise to build the search_box componentized template and integrate it
into TShirtShop.
Exercise: Creating the search_box Componentized Template
1. Create a new template file named search_box.tpl in the presentation/templates folder, and add
the following code to it:
{* search_box.tpl *}
{load_presentation_object filename="search_box" assign="obj"}
{* Start search box *}

Search the Catalog




value="{$obj->mSearchString}" size="19" />
CHAPTER 8 ?–  SEARCHING THE CATALOG 237




{if $obj->mAllWords == "on"} checked="checked" {/if}/>
Search for all words




{* End search box *}
2. Create the SearchBox presentation object in a file named search_box.php in the presentation folder,
with the following code:
// Manages the search box
class SearchBox
{
// Public variables for the smarty template
public $mSearchString = '';
public $mAllWords = 'off';
public $mLinkToSearch;
// Class constructor
public function __construct()
{
$this->mLinkToSearch = Link::ToSearch();
if (isset ($_GET['Search']))
{
$this->mSearchString = trim($_POST['search_string']);
$this->mAllWords = isset ($_POST['all_words']) ?
$_POST['all_words'] : 'off';
// Clean output buffer
ob_clean();
// Redirect 302
header('HTTP/1.


Pages:
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
traktorki ogrodowe terapia magnetyczna Pompy zatapialne mapa Niemiec Wnętrza Poznań