在if条件内调用函数

时间:2018-11-13 07:16:34

标签: php zend-framework

嗨,我正在尝试将if条件代码移到另一个新函数中,我想在另一个函数中调用它,我该怎么做

这是我的if条件:

if (self::GRID_LIST_STATUS_AGENDA === $gridType) {
            // Personal agenda sortation of statuses
            unset($finalFilters['statusId']['distinct']);
            $finalFilters['statusId']['values'] = [
                BAS_Shared_Model_Ticket::STATUS_REPLY_RELATION => 'relation reply',
                BAS_Shared_Model_Ticket::STATUS_REMINDER => 'followup',
                BAS_Shared_Model_Ticket::STATUS_NEW => 'new',
                BAS_Shared_Model_Ticket::STATUS_IN_PROGRESS => 'in progress',
                BAS_Shared_Model_Ticket::STATUS_REOPEN => 'reopened',
            ];
        }

这是我要移动的新功能

/**
     * Get personal agenda sortation statuses
     */
    public function personalAgendaSortationStatuses()
    {

    }

谁能帮助我该怎么做

1 个答案:

答案 0 :(得分:1)

您需要更改如下功能代码:-

public function personalAgendaSortationStatuses($gridType,$finalFilters) //pass parameter
    {
        if (self::GRID_LIST_STATUS_AGENDA === $gridType) {
            // Personal agenda sortation of statuses
            unset($finalFilters['statusId']['distinct']);
            $finalFilters['statusId']['values'] = [
                BAS_Shared_Model_Ticket::STATUS_REPLY_RELATION => 'relation reply',
                BAS_Shared_Model_Ticket::STATUS_REMINDER => 'followup',
                BAS_Shared_Model_Ticket::STATUS_NEW => 'new',
                BAS_Shared_Model_Ticket::STATUS_IN_PROGRESS => 'in progress',
                BAS_Shared_Model_Ticket::STATUS_REOPEN => 'reopened',
            ];
            return $finalFilters;
        }
    }

然后在另一个函数中调用它:-

$statuses = $this->personalAgendaSortationStatuses(self::GRID_LIST_STATUS_AGENDA,$finalFilters);//send second parameter too