Prev | Current Page 179 | Next

Emilian Balanescu and Cristian Darie

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

Here??™s an example of such a link:
http://localhost/tshirtshop/index.php?DepartmentId=3
When clicking a department??™s link, the selected department will be displayed using a different CSS style in the list
(see Figure 4-15).
Figure 4-15. Selecting a department
It is important to understand how the Smarty template file (presentation/templates/departments_list.tpl)
and the plug-in file (presentation/smarty_plugins/function.load_presentation_object.php) work
together to generate the list of departments and to use the correct style for the currently selected one.
The processing starts at function.load_presentation_object.php, which is included in the store_
front.tpl file. The first line in departments_list.tpl loads the DepartmentList presentation object
through the Smarty plug-in:
{load_presentation_object filename="departments_list" assign="obj"}
The smarty_function_load_presentation_object() plug-in function creates and initializes
a DepartmentsList object (this class is included in presentation/departments_list.php), which is
then assigned to the obj variable accessible from the Smarty design template file:
// Plug-in functions inside plug-in files must be named: smarty_type_name
function smarty_function_load_presentation_object($params, $smarty)
{
require_once PRESENTATION_DIR . $params['filename'] . '.php';
$className = str_replace(' ', '',
ucfirst(str_replace('_', ' ',
$params['filename'])));
// Create presentation object
$obj = new $className();
CHAPTER 4 ?–  CREATING THE PRODUCT CATALOG: PART 1 106
if (method_exists($obj, 'init'))
{
$obj->init();
}
// Assign template variable
$smarty->assign($params['assign'], $obj);
}
The init() method in DepartmentsList populates a public member of the class ($mDepartments) with an
array containing the list of departments and another public member containing the index of the currently selected
department ($mSelectedDepartment).


Pages:
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
Wczasy nad morzem kasyno kino azjatyckie bwin out of home advertising