Prev | Current Page 237 | Next

Emilian Balanescu and Cristian Darie

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

load_presentation_object.php plug-in.
4. Let??™s now create the Department presentation object for department.tpl. Create the presentation/
department.php file, and add the following code to it:
// Deals with retrieving department details
class Department
{
// Public variables for the smarty template
public $mName;
public $mDescription;
// Private members
private $_mDepartmentId;
private $_mCategoryId;
// Class constructor
public function __construct()
{
// We need to have DepartmentId in the query string
if (isset ($_GET['DepartmentId']))
$this->_mDepartmentId = (int)$_GET['DepartmentId'];
else
trigger_error('DepartmentId not set');
/* If CategoryId is in the query string we save it
(casting it to integer to protect against invalid values) */
if (isset ($_GET['CategoryId']))
$this->_mCategoryId = (int)$_GET['CategoryId'];
}
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);
CHAPTER 5 ?–  CREATING THE PRODUCT CATALOG: PART 2 148
$this->mName = $this->mName . ' » ' .
$category_details['name'];
$this->mDescription = $category_details['description'];
}
}
}
?>
5.


Pages:
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249