⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Passing parameter between functions



z.kerry
  • profile picture
  • Member

Posted 30 May 2018 - 07:25 AM

Hello Grocery Crud users~

 

Here I have 3 set of functions:-

 

on_Progress

public function on_progress()
	{	
		$this->grocery_crud->set_model('Custom_query_model');
		$this->grocery_crud->set_table('complaints');
		$this->grocery_crud->set_theme('flexigrid');
		$this->grocery_crud->basic_model->set_query_str("SELECT complaints.*, category.category_name,facilities_services. fs_name, trade.trade_name,
											problem_type.problem_type,level.level, users.name,contractor.name
											FROM complaints
											LEFT JOIN category ON complaints.category_id = category.id
											LEFT JOIN facilities_services ON complaints.fs_id = facilities_services.id
											LEFT JOIN users ON complaints.report_by = users.id
											LEFT JOIN trade ON complaints.trade_id = trade.id
											LEFT JOIN problem_type ON complaints.problem_type_id = problem_type.id
											LEFT JOIN level ON complaints.level_id = level.id
                                            LEFT JOIN contractor ON complaints.contractor_id = contractor.id
											WHERE category.id = facilities_services.category_id
											AND facilities_services.id = problem_type.fs_id AND 
											complaints.report_by = users.id	AND work_status = 'In Progress'		
											");
		$this->grocery_crud->columns('id','category_name','fs_name', 'trade_name', 
									'problem_type', 'level', 'users.name', 'event_datetime',
									'event_completed', 'name','work_status',
									'complaint_photo','completion_photo','overall_status'
									);
									
		
		
		$this->grocery_crud->display_as('id','Complaint Id');							
		$this->grocery_crud->display_as('category_name', 'Category');
		$this->grocery_crud->display_as('fs_name','Facilities/Services');
		$this->grocery_crud->display_as('trade_name','Problem Category');
		$this->grocery_crud->display_as('problem_type','Problem Type');
		$this->grocery_crud->display_as('level', 'Level');
		//$this->grocery_crud->display_as('users.name','Report By');
		//$this->grocery_crud->display_as('contractor.name','Craftsmen');
		
		$this->grocery_crud->unset_add();
		$this->grocery_crud->unset_edit();
		$this->grocery_crud->unset_delete();
		$this->grocery_crud->unset_read();
		$this->grocery_crud->add_action('Assign Craftsmen','#','Forms/craftsmen');
		
		$this->grocery_crud->callback_column('complaint_photo', array($this,'show_ComplaintImage'));
		$this->grocery_crud->callback_column('completion_photo', array($this,'show_CompleteImage'));
		
		
		
		function show_ComplaintImage($value)
		{
			return "<img src='".$value."' width='100px'>";
		}
		
		function show_CompleteImage($value)
		{
			return "<img src='".$value."' width='100px'>";
		}
		

		$output = $this->grocery_crud->render();
		
		$this->load->view('templates/header');
		$this->load->view('templates/header_grocery_crud');
		$this->load->view('templates/header_menu');
		$this->load->view('forms/updateForm', $output);
		$this->load->view('templates/footer_grocery_crud');
		$this->load->view('templates/footer');
	}

craftsmen()

public function craftsmen($primary_key)	
	//calls contractors based on complaint trade_id
	{		
			$sql = "SELECT id, trade_id FROM complaints WHERE id = '$primary_key'";
			$result = $this->db->query($sql);
			$row = $result->row();
			if (isset($result)){
			$complaint_id = $row->id;
			$trade_id = $row->trade_id;
			
			$this->grocery_crud->set_model('grocery_CRUD_model');
			$this->grocery_crud->set_table('contractor');
			$this->grocery_crud->set_theme('flexigrid');
			//$this->grocery_crud->basic_model->set_query_str('SELECT * FROM contractor WHERE trade_id = "$trade_id"');
			$this->grocery_crud->where('trade_id',$trade_id);
			$this->grocery_crud->unset_add();
			$this->grocery_crud->unset_edit();
			$this->grocery_crud->unset_delete();
			$this->grocery_crud->add_action('Assign Craftsmen','#','Forms/assign');			
			$output = $this->grocery_crud->render();
			
			$this->load->view('templates/header');
			$this->load->view('templates/header_grocery_crud');
			$this->load->view('templates/header_menu');
			$this->load->view('forms/assignCraftsmen', $output);
			$this->load->view('templates/footer_grocery_crud');
			$this->load->view('templates/footer');
			
			if ($complaint_id <> 0){
				return $complaint_id;
			}
			}
	}

and assign

function assign($primary_key)
{
				 $data['complaint_id'] = $this->craftsmen($data);
				$sql = "UPDATE complaints
						SET contractor_id = $primary_key
						WHERE id = '".$data['complaint_id']."'";
				$query = $this->db->query($sql);
				if ($query == true){
					redirect(base_url().'forms/on_progress');
				}
					redirect(base_url().'forms/on_progress');
			}

I tried to pass the data from function on_progress to function assign using standard Codeigniter method since GroceryCrud's add_action function allows only primary key of each table passed and some string array. Though the method returns "too few arguments" error or the SQL query does not run.

 

Is there any other way to pass the parameters between functions apart from what I used in the functions? Thanks a lot~


z.kerry
  • profile picture
  • Member

Posted 30 May 2018 - 07:35 AM

By the way, the passing method I used was in reference to this method https://www.cloudways.com/blog/pass-data-between-functions-in-codeigniter/