簡體   English   中英

將變量從一個函數傳遞到另一個php

[英]Pass variable from one function to another php

我正在使用Joomla! 2.5,並且我試圖將變量從公共函數傳遞到同一類中的受保護函數,但是我做錯了。 知道是什么嗎?

    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.')');


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

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

根據注釋,您的問題是您實際上沒有將任何內容傳遞給受保護的函數。 因此,按值傳遞job_id,如下所示:

return getListQuery($job_id);

並將您的函數定義更改為:

protected function getListQuery($job_id) {

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM