Jump to content


Problem with States

State

  • Please log in to reply
3 replies to this topic

#1 iradave

iradave

    Newbie

  • Members
  • Pip
  • 4 posts

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); 
}


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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 :)



#3 iradave

iradave

    Newbie

  • Members
  • Pip
  • 4 posts

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



#4 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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 :)







Also tagged with one or more of these keywords: State

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users