We will keep the relevant user constants as class constants. We will write the implementation of the methods from the BaseDao
abstract class in this class. Simply, we will add the body of those abstract methods and our own methods required into the class. So, follow the steps listed here:
1. Create a new PHP file inside the
Dao
directory namedUserDao.php
, and type in the following code:<?php namespace My\Dao; class UserDao extends BaseDao { private $db = null; public function __construct() { $this->db = $this->getDb(); } } $userDao = new \My\Dao\UserDao; ?>
As you can see, the class is under the
My\Dao
namespace and extends to theBaseDao
class, so the class will have methods inherited from the parent. The Dao class has its own private$db
, which stores the PDO instance returned by the inheritedgetDb()
method; as you can see, this$db
variable is assigned to the class constructor.Also, you might have noticed that the
UserDao
class...