Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:28:46+00:00 2026-06-14T14:28:46+00:00

I have written two functions like below in my model class. public function fetchByUsername($username)

  • 0

I have written two functions like below in my model class.

 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;
        }

But I want to write the fetch function in my row table class and access those values from model class without writing the above two function.
Please help me in this regard.

Thanks

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;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:28:48+00:00Added an answer on June 14, 2026 at 2:28 pm
        public function fetchDetails($attr,$value)
            {
                $select=$this->select();
                if($attr == 'username'){
                $select->where('username = ?', $value) ;
                else if($attr == 'phone '){
                 $select->where('phone = ?', $value) ; 
                }
                $user = $this->fetchRow($select);
                return $user;
            }
    

    And call it like

     //user
        $details = $your_model->fetchDetails('username',$usernamedata);
    
        //phone
        $details = $your_model->fetchDetails('phone',$phonedata);
    

    OR
    With out the Model function

     $obj = new Yournamespace_Model_Yourfile();
     $where = $obj->getAdapter()->quoteInto('username = ?',$username);
     $result = $obj->fetchRow($where);
    

    With out Model and Using AND //for username and phone are equal

      $where = array();
         $obj = new Yournamespace_Model_Yourfile();
         $where[] = $obj->getAdapter()->quoteInto('username = ?',$username);
         $where[] = $obj->getAdapter()->quoteInto('phone = ?',$phone);
         $result = $obj->fetchRow($where);
        //if you have more than one row then use
        $result = $obj->fetchAll($where);
    

    update as per OP’s request

    After fetching like this $result = $obj->fetchRow($where);

    You can get the individual elements like these

    $result->phone;
    

    Or

    $result->username;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a program written in C++ in which one or two functions
I have written a module similar to the following: module One class Two def
I have a CI Model set up with this function and ActiveRecord: function get_open_competitions()
I have written two short tests and compiled both with g++ -S (gcc version
I have written two scripts where one script calls subprocess.Popen to run a terminal
I have written two pieces of code which I intended to have identical outputs,
I have written an app in C which expects two lines at input. First
I have written a Python module, and I have two versions: a pure Python
I have two window form applications written in C, one holds a struct consisting
I have two sites one is written in asp.net webforms and the other one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.