简体   繁体   中英

How to return a value using Doctrine in symfony 1.4?

I want to return Leave Type of an employee in a particular date using the following function

public static function getLeaveTypeInDate($date, $empId) {
    $leaveType = Doctrine_Query::create()
            ->select('leave_type')
            ->from('EmployeeLeave')
            ->where('employee_id = ?', $empId)
            ->andWhere('applied_from = ?', $date)
            ->execute();

    return $leaveType[0];

But it returns Employee Name which is not directly stored in "employee_leave" table.

In this moment you're returning an entire EmployeeLeave object by doing ->execute() and then return $leaveType[0]

My advice is to change your query statement by replacing ->execute() with ->fetchOne()

Then, instead of doing return $leaveType[0] you could simply do return $leaveType->getLeaveType()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM