⚠ 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

Problem with States



iradave
  • profile picture
  • Member

Posted 11 July 2016 - 06:46 AM

I can get the code to work for states 'edit' and 'delete".  However trying to trigger on an insert (wheb a new record is added) or when an update (to an existing record is made - presuming this is after you push "update" on an edit record), does not appear to work. I am unable to get into the state = insert or update clause.

 

What triggers these states or is something wrong with the construction of the code?

Thanks!

	$output = $this->grocery_crud->render();

	$state = $this->grocery_crud->getState();
	$state_info = $this->grocery_crud->getStateInfo();
	
	xdebug_break();
	if (($state == 'edit') || ($state == 'delete')) {

		$this->unsetChinaCompany($state_info->primary_key); //set to false
	}	
	
	elseif (($state == 'insert') || ($state == 'update')) {
		// even just putting a die in here doesn't work
		//die();

		$this->setChinaCompany($state_info->primary_key); //set to true
	}
	
	 $this->_example_output($output); 
}

Amit Shah
  • profile picture
  • Member

Posted 12 July 2016 - 08:00 AM

Check what is the output passed out by the getState function call.. print the state somewhere and see if what you desire is what you get. This should be helpful.

 

Happy GCing :)


iradave
  • profile picture
  • Member

Posted 15 July 2016 - 06:11 AM

Hi Amit -

 

This is why I have the debug to set a break point after getting the state info. I can never find it in insert or update state even when adding or editing a record (row).

 

Any thoughts?

 

Ira


Amit Shah
  • profile picture
  • Member

Posted 18 July 2016 - 06:02 AM

Hi Dave,

 

Sorry for a delayed response .. was a bit busy.

 

To my understanding looking at the scenario - what you trying to accomplish is to perform  some piece of code before the record is inserted / updated. In such a scenario, i will recommend doing the same in callback_before_insert / callback_before_update

 

for you to understand what exactly the state is .. in case of insert / update - what you can do is .. send the log to a txtfile.. not recommended to do it .... sending it to the response as it might disturb the output. There .. u may actually understand as when and where the state is set and to what.

 

Hope this solution helps..

 

Happy Gcing :)