Jump to content


Redirect on callback_update

redirect callback

  • Please log in to reply
3 replies to this topic

#1 die_for_rock_vn

die_for_rock_vn

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 November 2014 - 08:17 AM

I use ion_auth as user management. If an user change his password, the site will redirect to logout controller. But if he is admin and he changes password for another user, it doesn't need logout.

My code:

$crud->callback_update ( array (
$this,
'edit_user_callback' 
) );

Function edit_user_callback

function edit_user_callback($post_array, $primary_key = null) {
$email = $post_array ['email'];
$groups = $post_array ['groups'];

if ($post_array ['change_password'] == 0) {
$data = array (
'email' => $email 
);
} else {
$password = $post_array ['password'];
$data = array (
'email' => $email,
'password' => $password 
);
}
$this->ion_auth->update ( $primary_key, $data, $groups );
if (($primary_key == $this->ion_auth->get_user_id ()) && (isset ( $post_array ['password'] ))) {
   //need redirect here
redirect ( 'auth/logout' );
}
return true;
}

It doesn't redirect and stuck at edit page.

I already read www.grocerycrud.com/forums/topic/324-workaround-redirect-to-the-list-after-insertupdate-without-changing-the-core-functionality-of-gc/

but it doesn't help, I only need redirect if condition is true.

Could you please help me?

Thank.

 



#2 Amit Shah

Amit Shah

    grocery CRUD Master

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

Posted 22 November 2014 - 09:34 AM

well.. u cannot do a url redirect from callback_update - because it rather is an ajax call and is supposed to return response string

rather - u can use something like this

$crud->set_lang_string('update_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(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
         </script>
         <div style="display:none">
         '
);

Now here - u can restrict the redirect based on the type of user who is acting for the same. Hope this helps you out.

 

Happhy GCing :)



#3 die_for_rock_vn

die_for_rock_vn

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 November 2014 - 04:53 PM

well.. u cannot do a url redirect from callback_update - because it rather is an ajax call and is supposed to return response string

rather - u can use something like this

$crud->set_lang_string('update_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(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
         </script>
         <div style="display:none">
         '
);

Now here - u can restrict the redirect based on the type of user who is acting for the same. Hope this helps you out.

 

Happhy GCing :)

I've already read this workaround, but it redirects every update.

How to use this code with the condition that get on callback_update? I've tried many times but it didn't work.

I'm not a web developer so it's hard for me.

Could you please make a sample code?

Have a nice weekend.

Thank you.



#4 Amit Shah

Amit Shah

    grocery CRUD Master

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

Posted 22 November 2014 - 06:57 PM

well.. in the controller - u will be able to retrieve the logged in user..

based on the user level .. set the workaround accordingly.. its that simple. it is all on the user levels if condition whether or not the user will be redirected or not







Also tagged with one or more of these keywords: redirect, callback

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users