2014-09-22 169 views
0

我使用Joomla! 2.5,我試圖將一個公共函數的變量傳遞給同一個類中的受保護的函數,但是我做錯了。任何想法是什麼?將變量從一個函數傳遞到另一個函數php

public function getJobsType() {  

    $jobsquery = $db->getQuery(true); 
    // Select the records for the connected user 
    $jobsquery = "SELECT jobassigned FROM #__jobs_userac WHERE user =".$userId; 
    $db->setQuery($jobsquery); 
    $row = $db->loadRowList(); 
    // I have one row per user so it returns only one field 
    $job_id = $row['0']['0']; 
    return $job_id;} 


    protected function getListQuery() { 

    //If i set the variable values my self the query is working 
    // ex. $job_id ="1,2,3"; 

    $db = $this->getDbo(); 
    $query = $db->getQuery(true); 


    $query ->select($this->getState('list.select', 'DISTINCT a.*')); 
    $query->from('`#__jobs_data` AS a'); 

    // I want to pass the values from the getJobsType() here 
    $query->where('type IN ('.$job_id.')'); 


     ................ 

在此先感謝您提供的任何幫助。

+0

那麼你在哪裏試圖傳遞一個變量? – 2014-09-22 18:35:56

+0

from getJobsType()getListQuery()作爲變量$ job_id – Chris 2014-09-22 18:36:40

+1

它只是我,還是你沒有實際調用getJobsType? – WreithKassan 2014-09-22 18:37:21

回答

0

根據評論,你的問題是你實際上沒有傳遞任何東西給你的保護功能。所以,通過值傳遞JOB_ID如下:

return getListQuery($job_id); 

而且你的函數定義更改爲:

protected function getListQuery($job_id) { 

有多種方式來解決你的問題,但是這似乎是最直接的方式。

相關問題