Use the core ajax helper for that.
in your controller:
var $helpers = array('Ajax', 'Javascript')
var $components = array('RequestHandler')
in the view that is going to hold the link, create the link with the ajax helper instead of the html helper:
echo $ajax->link( 'Generate Password',
array( 'controller' => 'controllername', 'action' => 'generatePassword',
array( 'update' => 'id_of_div_to_be_updated', 'complete' => 'alert("Your password has been generated") ' ) );
then in your generatepassword controller function make sure you send the generated password to the view which you'll create in your views/controller folder
$this->set('password', $new_password);
so you can print out the password in your view with
echo $password;
hope this helps!
bryan
On Wed, May 27, 2009 at 8:39 AM, liaogz82 <liaogz82@gmail.com> wrote:
Hi all,
I need help on the cakePHP coding. I have a function called
generatePassword() in the controller. I want to create an ajax link in
such a way that user can click on the link and it will talk to the
method, take the password and display it on the textbox. Can this be
done?
Gangzheng
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment