问题
Severity: Notice --> Trying to get property of non-object is showing for the line $this->data['tasks'] = $workpackages->tasks;
public function view($id) {
//get list of projects
$project = $this->Projects_model->get_project($id);
$rate = $this->ion_auth->get_project_rate($project->id)->row();
if ($project) {
//get list of beneficiaries
$benificiaries = $this->Beneficiaries_model->get_beneficiaries($project->id);
if ($benificiaries) {
$project->benificiaries = $benificiaries;
} else {
$project->benificiaries = array();
}
//get budget list
$budgets = $this->Budgets_model->get_project_budgets($project->id);
if ($budgets) {
$project->budgets = $budgets;
} else {
$project->budgets = array();
}
//get work packages
$workpackages = $this->Workpackages_model->get_workpackages($project->id);
$project->tasks = array();
$tasks_count = 0;
$subtasks_count = 0;
if ($workpackages) {
for ($i=0; $i<count($workpackages); $i++) {
//get tasks of work package
$tasks = $this->Tasks_model->get_wp_tasks($workpackages[$i]->id);
if ($tasks) {
for($j=0; $j<count($tasks); $j++) {
//get sub task of parent task
$subtasks = $this->Tasks_model->get_wp_subtasks($tasks[$j]->id);
if ($subtasks) {
foreach($subtasks as $key => $subtask){
for($k=0;$k<count($subtask->task_leader);$k++){
$subtasks[$key]->beneficiary_short_name[$k] = $this->Beneficiaries_model->get_beneficiary_by_id($subtask->task_leader[$k]->participant_id)->short_name;
}
}
$tasks[$j]->subtasks = $subtasks;
$subtasks_count += count($subtasks);
} else {
$tasks[$j]->subtasks = array();
}
$tasks[$j]->wp_number = $workpackages[$i]->number;
if(count($tasks[$j]->task_leader) > 0){
for($k=0;$k<count($tasks[$j]->task_leader);$k++){
$tasks[$j]->beneficiary_short_name[$k] = $this->Beneficiaries_model->get_beneficiary_by_id($tasks[$j]->task_leader[$k]->participant_id)->short_name;
}
}
$tasks_count++;
}
$workpackages[$i]->tasks = $tasks;
$project->tasks[] = $tasks;
} else {
$workpackages[$i]->tasks = array();
}
}
$project->workpackages = $workpackages;
} else {
$project->workpackages = array();
}
//get list of deliverables
$deliverables = $this->Deliverables_model->get_deliverables($project->id);
if ($deliverables) {
//get workpackage number
for($cnt=0; $cnt<count($deliverables);$cnt++) {
$wp_number = $this->Workpackages_model->get_workpackage($deliverables[$cnt]->wp_id, 'number');
if ($wp_number) {
$deliverables[$cnt]->wp_number = $wp_number->number;
} else {
$deliverables[$cnt]->wp_number = '';
}
}
//add deliverables to projects array
$project->deliverables = $deliverables;
} else {
$project->deliverables = array();
}
$this->data['project'] = $project;
$this->data['rate'] = $rate;
$this->data['tasks_count'] = $tasks_count;
$this->data['tasks'] = $workpackages->tasks;
$this->data['subtasks_count'] = $subtasks_count;
$this->data['subtasks'] = $subtasks ;
$this->data['project_monthly_salary'] = array(
'name' => 'project_monthly_salary',
'type' => 'text',
'value' => $this->form_validation->set_value('project_monthly_salary'),
'class' => 'input-xlarge'
);
$this->data['project_hours_of_contract'] = array(
'name' => 'project_hours_of_contract',
'type' => 'text',
'value' => $this->form_validation->set_value('project_hours_of_contract'),
'class' => 'input-xlarge'
);
$this->data['project_daily_hours_limit'] = array(
'name' => 'project_daily_hours_limit',
'type' => 'text',
'value' => $this->form_validation->set_value('project_daily_hours_limit'),
'class' => 'input-xlarge'
);
$this->data['show_editprojects'] =
$this->auth_manager->get_authorization('projects','edit');
$this->data['show_editworkpackages'] =
$this->auth_manager->get_authorization('workpackages','edit');
$this->data['show_setbudgets'] =
$this->auth_manager->get_authorization('budgets','set');
$this->data['show_editbudgets'] =
$this->auth_manager->get_authorization('budgets','edit');
$this->data['show_deletebudgets'] =
$this->auth_manager->get_authorization('budgets','delete');
$this->data['show_settingworkpackages'] =
$this->auth_manager->get_authorization('workpackages','set');
$this->data['show_editworkpackages'] =
$this->auth_manager->get_authorization('workpackages','edit');
$this->data['show_deleteworkpackages'] =
$this->auth_manager->get_authorization('workpackages','delete');
$this->data['show_addtasks'] =
$this->auth_manager->get_authorization('tasks','add');
$this->data['show_edittasks'] =
$this->auth_manager->get_authorization('tasks','edit');
$this->data['show_deletetasks'] =
$this->auth_manager->get_authorization('tasks','delete');
$this->data['show_addsubtasks'] =
$this->auth_manager->get_authorization('subtasks','add');
$this->data['show_editsubtasks'] =
$this->auth_manager->get_authorization('subtasks','edit');
$this->data['show_deletesubtasks'] =
$this->auth_manager->get_authorization('subtasks','delete');
$this->data['show_editdeliverables'] =
$this->auth_manager->get_authorization('deliverables','edit');
$this->data['show_deletedeliverables'] =
$this->auth_manager->get_authorization('deliverables','delete');
$this->data['display_listofmilestones'] =
$this->auth_manager->get_authorization('List of Milestones','display');
$this->data['set_beneficiaries'] =
$this->auth_manager->get_authorization('beneficiaries','set');
$this->data['show_editbeneficiaries'] =
$this->auth_manager->get_authorization('beneficiaries','edit');
$this->data['show_deletebeneficiaries'] =
$this->auth_manager->get_authorization('beneficiaries','delete');
//initial view partshow_deleteworkpackages
$this->data['content'] = $this->load->view('projects/show', $this->data, TRUE);
//Render the page with the Helper function
layout($this->data);
} else {
$this->session->set_flashdata('message', 'Project not found.');
redirect('projects', 'refresh');
}
}
how can i get rid of this error.is there any effect of this error
来源:https://stackoverflow.com/questions/21232026/why-trying-to-get-property-of-non-object-error-raised