-
Notifications
You must be signed in to change notification settings - Fork 0
Ajax Framework For CodeIgniter
Cjax is a very basic but powerful Ajax Framework that complements Codeigniter.
[url=http://code.google.com/p/ajax-framework-for-codeigniter/downloads/list]Download From Google Code[/url]Cjax separates your ajax controllers from your regular controllers. While your normal controllers reside in application/controllers, your ajax controllers will reside in application/response.
Download and unzip the Ajax Framework package, then just overwrite everything from the zip into your CodeIgniter base installation (will not replace any of your files) just go to: http://yoursite.com/ajax.php?controller=test&function=test(replace http://yoursite.com with the base directory where your CodeIgniter installation resides)
To this point you are done, successfully installing and using Cjax, if the test above prints "Ajax View..". You can find this text inside file application/views/test.php, and its controller in application/response/test.php.
Full support for friendly URLS.
Friendly URLS are supported, but not required to use Cjax. You may access your controllers in any of the following ways; these examples make use of controller file application/response/test.php.
[code] //ajax.php?controller=$controller&function;=$function ajax.php?controller=test&function=test //ajax.php?$controller/$function ajax.php?test/test //ajax/$controller/$function #This one requires mod_rewrite ajax/test/test [/code]
The last url above, will require you to enable mod_rewrite in your server and rename the accompanied file htaccess.txt File:htaccess.txt to .htacccess
Creating controllers works the same way as your regular controllers, except the class name of ajax controller start with the keyword "controller_". For example, if you want to create a controller named test, then your class name would be "controller_test".
application/response/test.php [code]class controller_test extends CI_Controller {function test()
{
}
} [/code] You may use your ajax controller the same way you would use any other CI controller including the creation of any dependencies.
Cjax uses URL query string to pass parameters into the controller by using function parameters. You can pass alphabetic letters as parameter order to your methods inside the controllers. There is more than one way to pass parameters, depending on the way you are using the URL.
Example of passing parameters in followed order.
URL: [code] ajax.php?test/test/arg1/someID // this also applies to mod_rewrite urls such as: ajax/test/test/arg1/someID [/code] The above URL is passing two parameters arg2 and someID, test/test indicates the controller and the method. To access these parameters use function arguments:
application/response/test.php [code]class controller_test extends CI_Controller {function test($arg1, $arg2)
{
echo $arg1;
echo "<br />";
echo $arg2;
}
//prints arg1
// someID
} [/code]
You can pass unlimited number of parameters, and access them through function parameters in the same order they are passed.
A less Organized way to pass parameters that may accept any order within the URL:URL: [code]ajax.php?controller=test&function=test&a=Hello&b=World&c=Hello World[/code]
The previous URL, makes use of common URL, and passes three parameters to the controller.
This methods accepts any alphabetic letter in respective order to pass parameters. You may pass: a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, which will be accessible through function parameter. Using this method also allows you to pass any other parameters through outside of the function parameter scope.
application/response/test.php [code]class controller_test extends CI_Controller {function test($a, $b, $c)
{
echo $a;
echo "<br />";
echo $b;
echo "<br />";
echo $c;
}
//prints Hello
// World
// Hello World
} [/code]
- Original author: Derek Jones
- How to extend helpers: See User Guide
- Modified by: Thomas Stapleton (id, classes, selected country option and all option)
- Modified by: Bradley De-Lar (construct, setLayout example)