⚠ 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

clarification on redirect after insert



jpeake
  • profile picture
  • Member

Posted 26 September 2013 - 11:20 AM

First, thank you to the creators, this is incredibly useful and awesome!

 

Hello all, I am a newbie, learning Code Igniter and Grocery Crud, I apologize if this question is too simple, but I cannot get this to work. It seems simple, but I am stumped.

 

I am following this post:  /topic/324-workaround-redirect-to-the-list-after-insertupdate-without-changing-the-core-functionality-of-gc/

 

I would like to redirect the user to a different controller when they are in the "add" state and click the "save" button.

 

My controller is "controller_site", my function is "crud_daily_reports", and this function has a "callback_after_insert" that references a second function "redirect_to_month" that handles the redirect.

Here is my callback_after_insert:

$crud->callback_after_insert(array($this, 'redirect_to_month'));

The function "redirect_to_month" looks like this.

		function redirect_to_month()
		{
			$controller = "controller_site";
			$function = "my_monthly_reports";
		$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 = "'.site_url($controller.'/'.$function).'";
		</script>
		<div style="display:none">
		'
		);	
		}

The entire function is kind of long so I attached it as a file just in case more information is needed.

 

I think I am doing something wrong with array data that is passed from callback_after_insert, but am new enough to be unsure. Ok, thanks everyone.

 

Jason


chavamm
  • profile picture
  • Member

Posted 26 September 2013 - 19:13 PM

Hi,

I think that you should put the code in your controller function 'crud_daily_reports'.

And not at a callback function, because,  IMHO $crud object do not exists in callback function.

regards.


jpeake
  • profile picture
  • Member

Posted 27 September 2013 - 05:15 AM

Thank you so much... I was making this much more difficult than it needed to be. So, for any other newbies who find this I will post the completed controller. I was going to the wrong direction trying to use a callback_after_insert, there is no need for that. You only need to add:

			$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 = "'.site_url('controller_site/my_monthly_reports').'";
			</script>
			<div style="display:none">
			'
			);	

just before:

					
			$output = $crud->render();

Again, thank you.

 

Jason