将变量从一个函数传递到另一个函数php
问题描述:
我使用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.')');
................
在此先感谢您提供的任何帮助。
答
根据评论,你的问题是你实际上没有传递任何东西给你的保护功能。所以,通过值传递JOB_ID如下:
return getListQuery($job_id);
而且你的函数定义更改为:
protected function getListQuery($job_id) {
有多种方式来解决你的问题,但是这似乎是最直接的方式。
那么你在哪里试图传递一个变量? – 2014-09-22 18:35:56
from getJobsType()getListQuery()作为变量$ job_id – Chris 2014-09-22 18:36:40
它只是我,还是你没有实际调用getJobsType? – WreithKassan 2014-09-22 18:37:21