我在我的模型类中编写了如下两个函数。
public function fetchByUsername($username)
{
$select=$this->select();
$select->where('username = ?', $username) ;
$user = $this->fetchRow($select);
return $user;
}
public function fetchByPhone($phone)
{
$select = $this->select();
$select->where('phone = ?', $phone) ;
$user = $this->fetchRow($select);
return $user;
}
但是我想在我的行表类中编写 fetch 函数并从模型类中访问这些值而不编写上述两个函数。请在这方面帮助我。
谢谢
用户.php
class Model_User extends Model_DbTable_Row
{
//here i need to write fetch function like below
// public function fetchPhone()
// {
// return $this->phone;
// }
// public function fetchUsername()
// {
// return $this->username;
// }
}
用户.php
class Model_Users extends Model_DbTable_Abstract
{
protected $_name = 'users';
protected $_primary = 'userId';
protected $_rowClass = 'Model_User';
protected $_saveInsertDate = true;
protected $_saveUpdateDate = true;
}
用户控制器.php
class Admin_UsersController extends BusinessForum_Admin_Controller
{
public function init()
{
/* Initialize action controller here */
$this->view->pageTitle = 'Users - ' . $this->view->pageTitle;
parent::init();
}
public function indexAction()
{
// get name of the director
$userId = $this->_getParam('directorId');
if ($userId) {
$modelUsers = new Model_Users();
$user = $modelUsers->fetch($userId);
$fullName = $user->firstName." ".$user->lastName;
$directorName = "Direcotor : ".$fullName;
$this->view->directorName = $directorName;
}
}