Prev | Current Page 241 | Next

Emilian Balanescu and Cristian Darie

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

The
final role of this class is to populate these members, which are required to build the output for the visitor:
// Deals with retrieving department details
class Department
{
// Public variables for the smarty template
public $mName;
public $mDescription;
There are also two private members that are used for internal purposes. $_mDepartmentId and $_mCategoryId
will store the values of the DepartmentId and CategoryId query string parameters:
// Private members
private $_mDepartmentId;
private $_mCategoryId;
Next comes the constructor. In any object-oriented language, the constructor of the class is executed when the class
is instantiated, and the constructor is used to perform various initialization procedures. In our case, the constructor
of Department reads the DepartmentId and CategoryId query string parameters into the $_mDepartmentId
and $_mCategoryId private class members. You need these because if CategoryId actually exists in the query
string, then you also need to display the name of the category and the category??™s description instead of the department??™s
description.
// 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'];
}
CHAPTER 5 ?–  CREATING THE PRODUCT CATALOG: PART 2 151
The real functionality of the class is hidden inside the init() method.


Pages:
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253