[Solved] CI + XAJAX Global Functions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [Solved] CI + XAJAX Global Functions (/showthread.php?tid=10659) Pages:
1
2
|
[Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]LifeSteala[/eluser] Hi I am developing an app for work. I have many controllers needing the same xajax function I wrote. I tried to put these functions in my MY_Controller.php file (gets extended on every controller), but I don't think these functions are accessible (cause it's not working). I register these functions in the controllers index(). Do I need to register them in My_Controller.php?? How can I globalize these AJAX functions I wrote. I want to be able to re-use them. Thanks [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]geckzilla[/eluser] I think what you want to do is put them in a library instead of extending the controller, say you call it "Ajax". Then in the autoload config add your library to the list and all your functions will be available via $this->ajax->some_function() [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]LifeSteala[/eluser] OK I could give that a go. What happens is I have a select list which a user chooses an option. On choosing that option, it auto populates the second select list like this. Code: onChange=\"xajax_get_tasks(this[this.selectedIndex].value); I tried putting into a library. It still seems like it cannot access those functions. Any ideas? [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]geckzilla[/eluser] Isn't that javascript? [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]LifeSteala[/eluser] Yeah, that is on the HTML side. If I put the function inside the actual controller, that JavaScript can access the function and do what I need it to do. I put that function in a library as you mentioned, and loaded it, however it still doesn't work. So I'm guessing that JavaScript cannot access the function inside the loaded library? [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]LifeSteala[/eluser] So is it possible to re-use a AJAX function across many controllers? [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]geckzilla[/eluser] You just need to include the javascript file in your template header... codeigniter is php only. [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]LifeSteala[/eluser] I've included the JavaScript. I register the functions in the controllers constructor. Here's my controller. Code: class Entertime extends MY_Controller Here's my library Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]Sumon[/eluser] Well as though you have [code] class Globalajax { /// Your codes..... function Globalajax() { log_message('debug', "Global Ajax Functions Class Initialized"); } function get_tasks($projectID) { //Generate List drop down } } [code] it's possible to call this function inside javascript function like yoursite.com/globalajax/get_tasks(5) [Solved] CI + XAJAX Global Functions - El Forum - 08-07-2008 [eluser]LifeSteala[/eluser] I have managed to solve this using MY_controller. I created a new function called load_ajax() inside MY_controller. In this function I register the ajax functions and process the request. The actual controller then calls load_ajax() and then loads the JavaScript. Thanks to those who helped. |