⚠ 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

Redirect to another site after insert



kennethaa

kennethaa
  • profile picture
  • Member

Posted 19 December 2013 - 03:36 AM

Hi,

First of all: Grocery CRUD is amazing, and deserves every nice word.

I have a problem. When I click "Save" and something is selected in some ENUM attribute, I want to be redirected to another site than the standard route. How can I do that?

Here is my code:

public function live()
{	
		$crud = new grocery_CRUD();
		
		$crud->set_table('live')
			->set_subject('event')
			->columns('matchID', 'event', 'minute', 'description')
			->field_type('event', 'enum', array('Goal', 'Chance', 'Yellow Card', 'Red Card', 'Info'));
		
		$crud->required_fields('matchID', 'date', 'event', 'minute', 'description');
		
		$crud->set_relation('matchID','matches','{hometeam} - {awayteam}', null, 'id DESC');
		
		$crud->callback_after_insert(array($this, 'redirect_user'));
		
		$output = $crud->render();    
		
}

And here is my callback:

function redirect_user($row)
	{
		if ($row->event === 'Goal')
		{
			$crud->set_lang_string('insert_success_message',
				 'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
				 <script type="text/javascript">
				  window.location = base_url + "admin/goals/add";
				 </script>
				 <div style="display:none">
				 '
		   );
		}
	}

Am I on the track, or is there another way for doing this?


edramirez

edramirez
  • profile picture
  • Member

Posted 19 December 2013 - 13:44 PM

Hi, Kenneth -

 

First of all, I welcome you to the GC forum. When you do GroceryCRUD and expand your understanding of this library, it's like standing side by side with the giants of CodeIgniter.

 

Now let's get to your question.

 

GroceryCRUD callbacks were actually designed to perform an operation only and not to take the user anywhere. So, an appropriate use for the callback_after_insert is to perhaps add an audit trail record into another file, as shown in the documentation example. Another possible use for this function is to add or deduct the quantity value of a matching item code in an inventory system. That's the basic philosophy behind those callbacks.

 

In your case, you want to provide a confirmation message after a successful insert. This might not be necessary since GC already provides its own confirmation message which is displayed upon the user's return to the list.

 

I suggest that you try out the examples and learn the capabilities of GroceryCRUD on a deeper level in order to appreciate the power of the library. Perhaps there is no need to add additional code beyond the functionality that GC offers.

 

Regards,

 

Ed

 

P.S.

 

Don't forget to click the Like button.


kennethaa

kennethaa
  • profile picture
  • Member

Posted 19 December 2013 - 14:04 PM

Thank you edramirez!

I've been looking in the documentation for Grocery CRUD, and i can't find any solution for this problem. The solution I posted in the first post, was the nearest solution I have found via forum posts here. But this solution doesn't seem to work, so I wonder if there is someone who can see where this small problem is.