Ajax implementation on CakePHP @ 3

Recently i have started another CakePHP project. i found that the example in Ajax implementation on CakePHP @ 2 should be changed as follow.

ajax_controller.php

<?php
Class AjaxController extends AppController {
	var $name = 'Ajax';
	var $helpers = array('Form','Html','Javascript', 'Ajax');
	var $components = array('RequestHandler');

	function afterAjaxAction () {
		// get the $this->data to collect the form information
		// save the object to database
		// render the after_ajax_call.ctp
		$this->render('/elements/layout/after_ajax_call');
	}
}


 

view.ctp

<div id='ajaxDiv'>
	<!-- create the form -->
	<?php echo $form->create(<object to be saved>); ?>
	<?php echo $form->input(...); ?>
	<?php echo $form->input(...); ?>
	<?php echo $form->input(...); ?>
	<?php echo $ajax->submit('Submit', array('url' => array('controller'=>'ajax', 'action'=>'afterAjaxAction'), 'update'=>'ajaxDiv', 'before' => <OPTIONAL - Ajax callback option for javascript>)); ?>
	<?php echo $form->end(); ?>
</div>

 

Done =)

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s