Trying to write a Library for the new Xajax |
Hello All,
I'm trying to write a library for the newly resurrected Xajax project (from Thierry Feuzeu)... and I'm coming up short due to my inexperience in writing CodeIgniter Libraries and with PHP namespacing. Could anyone offer some thoughts on how to make this work? (see's Thierry's example code: https://github.com/lagdo/xajax-examples/.../hello.php) Here's what I've got so far, and it definitely instantiates an xajax object, of which I can access at least the getVersion() method from inside a CodeIgniter controller method, but I can't figure out how to write the Library to access other basics (see errors in __construct() ): ( output: http://triv.ath.cx/ci3/ ) So, I'm at a loss as to what to do next... any advice? CodeIgniter 3 Library: PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); CodeIgniter 3 Welcome Controller: PHP Code: <?php (Using CodeIgniter since 1.x)
Hi, I used it with CI 2.X the link below may help you figure it out:
Xajax CodeIgniter I will play around with it later I used it alot with CI 2.X and see if I can get it to work. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(04-26-2016, 03:16 AM)InsiteFX Wrote: Hi, I used it with CI 2.X the link below may elp you figure it out: Thanks for your reply InsiteFX! I've already got the older version of Xajax working with CI3, it's the new one that I'm working on. The new author of Xajax, Thierry Feuzeu, is suggesting that we implement it not as a library, but as a Controller that we extend. I know the CI tradition is to implement such things as libraries (that's how I implemented old xajax+CI3) ... how do you feel about Thierry's implement-in-base-controller-instead-of-library suggestion? Thanks! (Using CodeIgniter since 1.x)
If he says to implement it as a Controller then I would add it to a MY_Controller and extend all your other Controllers from it.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Try loading the library using CI's loader.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Hi, jasonzig
I've been using xajax last years by a very easy way using as a library. I think library is more convenient and clear. I did it according to my own thoughts and codes. But the links below show something similar to my code: http://www.jerictan.com/live/how-install...er-2-0-988 Here, forget this fix and keep the focus on how to make Xajax work: http://www.gen.newrandom.com/2011/07/21/...-csrf-fix/ If need any help, do not hesitate to ask. PHP Code: // $this->ci_xajax->xajax->register(Xajax::USER_FUNCTION, 'hello'); In this case, Xajax is defined in the context of your library, but not in the context of your controller. The error is specifically the use of Xajax::USER_FUNCTION as the first argument to $this->ci_ajax_xajax->register(). PHP Code: // $this->ci_xajax->xajax->register(CI_Xajax::USER_FUNCTION, 'hello'); Here you've bypassed the previous error by referring to the class name of your library (though you would normally refer to this via $this->ci_xajax), but your library doesn't define the USER_FUNCTION constant. This would be defined by doing something like this: PHP Code: class CI_Xajax { Then your controller's constructor could do something like this: PHP Code: $this->ci_xajax->xajax->register($this->ci_xajax::USER_FUNCTION, 'hello'); Some of this may be PHP-version-dependant, and I haven't tried it (and the syntax I've used looks questionable in the second example, you may need to use $this->ci_xajax->USER_FUNCTION).
I've never understood the appeal of doing this. A server is a data store the client is a presentation layer. Trying to merge client concepts with a server creates an unmanageable mess for no perceivable gain.
How are you going to manage exceptions? What if the DOM element you target server side has been removed from the client? Why would you ever want to mix business logic between two systems when it only applies to one? |
Welcome Guest, Not a member yet? Register Sign In |