我已经尝试了很长一段时间才得到这个工作,但无法设法得到我真正想要的:)。PHP为什么我的父母在定义子女时没有设置
首先,我有一个“Scope”,其中包含“Projects”,其中包含“Tasks”,当我要显示范围的任务时,我想显示与该任务相关的项目。
这意味着当我启动:
$scope->get_Tasks();
它将检索项目,并为每个projets,检索任务,如果在这一点上我:
var_dump($scope);
我看到从范围到项目,再到任务。因此,当我接手任务时,如何在不重新读取数据库的情况下抓住此项目的项目。我试图扩展项目的类任务,但是项目的每个成员都会在帖子结尾处结束“null”。
我有一个具有“GET_Tasks”功能一样,我的项目类:
/**
* get_Tasks
*
* Returns the tasks associated with this project.
*/
public function get_Tasks()
{
// If the tasks aren't already set
if (!(isset($this->_tasks)))
{
// We get the super object
$CI =& get_instance();
// Build the conditions
$condition = array("ProjectID" => $this->get_ProjectID());
// Get the tasks
$this->_tasks = _TaskClass::fetch($condition);
}
return $this->_tasks;
}
这里是我的“_TaskClass”类取功能现在
/**
* fetch
*
* Fetch task(s) from the database.
*
* @param array The array of conditions we want.
* @return array The array of objects that meets all of the conditions.
*/
public static function fetch($conditions = NULL)
{
// If we have conditions and that they're not in array, we return false
if (!($conditions === NULL) && (!(is_array($conditions))))
return false;
// We get the super object
$CI =& get_instance();
// Load the models needed
$CI->load->model('task_mod','',TRUE);
// Get the records
$array = $CI->task_mod->fetch($conditions)->result();
// If we found records
if (count($array) > 0)
{
// Transform all of the records found as array
foreach ($array as $record)
$return_array[] = new _TaskClass($record);
// Return the list
return $return_array;
}
// We didnt find a record.
return false;
}
,在第一块码,如果不是
return $this->_tasks;
我做的:
var_dump($this->_tasks);
它给了我这个信息(注意,父根本没有设置):
array (size=2)
0 =>
object(_TaskClass)[28]
public '_taskid' => string '20' (length=2)
public '_projectid' => string '1' (length=1)
public '_userid' => null
public '_title' => string '' (length=0)
public '_description' => string '' (length=0)
public '_user' => null
private '_scopeid' (_ProjectClass) => null
private '_tasks' (_ProjectClass) => null
private '_localisations' (_ProjectClass) => null
private '_projectid' (_ProjectClass) => null
private '_userid' (_ProjectClass) => null
我想这是个具有构造去也许......也许是我”的东西试图达到这种方式并不是真的可以实现的吗?
非常感谢!
编辑1 这里的构造函数,它是最小的,我_TaskClass的
class _TaskClass extends _ProjectClass
{
var $_taskid;
var $_projectid;
var $_userid;
var $_title;
var $_description;
// Objects
var $_user;
public function __construct($params = NULL)
{
parent::__construct();
if (is_object($params))
$this->_init_object($params);
else
return;
}
/**
* _init_object
*
* Initialise the whole project.
*
* @param object the object containing all of the information of the project.
*/
private function _init_object($project)
{
// Save all of the informations
$this->set_TaskID($project->TaskID);
$this->set_ProjectID($project->ProjectID);
$this->set_UserID($project->UserID);
$this->set_Title($project->Title);
$this->set_Description($project->Description);
}
编辑2 下面是我的项目类的构造函数
class _ProjectClass
{
// Project variables
private $_projectid;
private $_scopeid;
private $_userid;
private $_tasks;
private $_localisations = NULL;
public function __construct($params = NULL)
{
if (is_object($params))
$this->_init_object($params);
else
return;
}
/**
* _init_object
*
* Initialise the whole project.
*
* @param object the object containing all of the information of the project.
*/
private function _init_object($project)
{
// Save all of the informations
$this->set_ProjectID($project->ProjectID);
$this->set_UserID($project->UserID);
$this->set_ScopeID($project->ScopeID);
}
你可以发布你的任务类的构造函数代码? –
@ ginovva320 - 发布我的构造函数 – SantaClauss
您还应该将$ params传递给父构造函数。 –