필자는 모델 클래스에 다음과 같은 두 가지 함수를 작성했습니다.젠드 프레임 워크에서 로우 테이블 클래스를 작성하는 방법은 무엇입니까?
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 함수를 작성하고 위의 두 함수를 작성하지 않고 모델 클래스에서 해당 값에 액세스하려고합니다. 도와주세요.
감사
User.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;
// }
}
Users.php
class Model_Users extends Model_DbTable_Abstract
{
protected $_name = 'users';
protected $_primary = 'userId';
protected $_rowClass = 'Model_User';
protected $_saveInsertDate = true;
protected $_saveUpdateDate = true;
}
UsersController.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;
}
}
공공 기능 가져 오기 ($ 사용자 ID) \t 같은 개별 요소를 얻을 수 있습니다 { \t \t $ select = $ this-> select(); \t \t $ select-> where ('userId =?', (int) $ userId); \t \t $ select-> where ('active =?', 'Y'); \t \t return $ this-> fetchRow ($ select); \t} 위의 가져 오기 기능을 쓰고 사용자 ID가 필요하면 전화 번호 또는 사용자 이름에 액세스하려고 시도합니다. – user1559230
@ user1559230 불량 업데이트 내 대답 – coolguy
업데이트 ... 대답 – coolguy