In our solution, the init() method is
always executed immediately after the constructor, because it??™s called immediately after the object is created, in
the load_presentation_object Smarty plug-in function (as you know from Chapter 4, this plug-in function is
used by all Smarty templates to load their presentation objects).
The init() method populates the $mName and $mDescription public members with information from the
business tier. The GetDepartmentDetails() method of the business tier Catalog class is used to retrieve the
details of the department; if necessary, the GetCategoryDetails() method is also called to retrieve the details
of the category (the details of the department need to be retrieved even when visiting a category, because in that
case, we display both the department name and the category name).
public function init()
{
// If visiting a department ...
$department_details =
Catalog::GetDepartmentDetails($this->_mDepartmentId);
$this->mName = $department_details['name'];
$this->mDescription = $department_details['description'];
// If visiting a category ...
if (isset ($this->_mCategoryId))
{
$category_details =
Catalog::GetCategoryDetails($this->_mCategoryId);
$this->mName = $this->mName . ' » ' .
$category_details['name'];
$this->mDescription = $category_details['description'];
}
}
Displaying the List of Categories
When a visitor selects a department, the categories that belong to that department must appear.
Pages:
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254