Download the PHP package nozzha/yii2-ajaxy without Composer
On this page you can find all versions of the php package nozzha/yii2-ajaxy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-ajaxy
Nozzha Ajaxy 2.0: Actions Dialog via Ajax for Yii 2
Nozzha Ajaxy is a Yii 2.0 extension that provides a simple API to show an action via a dialog box in the page using the Bootstrap plugin Bootbox.
Ajaxy was designed to display either a create or an update actions dialog box. In other words, an action that has a single form.
Note: Ajaxy was not tested with actions that does not have a form like a
view
orindex
action.
For license information check the LICENSE-file.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
Usage
There are two steps for using Ajaxy
1. Handle Ajaxy requests
1.1. Preparing the View
For Ajaxy to display the dialog box of the requested action, it will need to request for the view content first, and to retrieve the view at the proper time and request
You'll first use Ajaxy::isAjaxy()
to check if this is an Ajaxy request that
asks for the view content, and then return the content using [Controller::renderAjax()
](http://www.yiiframework.com/doc-2.0/yii-web-controller.html#renderAjax()-detail).
Example:
in the controller
and in the view (in our example create.php
) attach Ajaxy to the form using
Ajaxy::attachTo($view, $activeForm)
Note: You should set an id for the form to avoid duplicate ids when requesting the view via Ajax
Example:
1.2. Handle the submitted form and return the response
When the submits the form, Ajaxy will post it via ajax
to the specified action
,
and you may need to handle this request differently to return the proper response.
Ajaxy provides to methods to do so, Ajaxy::isSubmitted()
that checks whether
the Ajaxy form has submitted. And Ajaxy::response()
that prepares a response for
the Ajaxy request.
Example:
And now the action is ready to provide it's view and to handle the submitted form.
2. Display the Dialog Box
1. Register Ajaxy assets
To link the JavaScript api of Ajaxy register it's asset bundle
2. Show the Dialog
and then in your JavaScript code call $ajaxy.showModalForm(options)
to show a dialog box of a view that you want to display
Example: