Welcome Guest, Not a member yet? Register   Sign In
CJAX and CI - responses vs controllers - accessing CI goodness
#1

[eluser]LordMatt[/eluser]
Please forgive me if I sound cross it is because I am feeling cross. I've spent a week trying to make CJAX work and it is a slow and painful process that seems to involve a lot of me yelling at the screen "what the hell is that even for?"

Am I labouring under the misunderstanding that CJAX is an AJAX framework for CI? So far all examples would work better and faster WITHOUT Codeigniter which mostly seems to exist as a massive amount of cruft. The lack of decent documentation is hurting my head so badly...

My understanding is as follows.

When I want CJAX to respond to requests and stuff I put classes in the responses folder. This seems to work for the does-not-in-any-way-appear-to-use-CI examples.

So far so fine but what is the point of hanging all that goodness on the power of CI and then isolating me from it?

Why are responses being used separate from controllers? Actually don't even answer that question just tell me how to get access to the same power I would have in a controller (the CI framework) so I can use models and plugins and all that and actually access my business logic and data layers and do something worthwhile with the AJAX other than trying to pretend I have an AJAX UI and proper separation of logics.

As far as I can see Codeigniter does not exist during responses which seems more than just a little bit pointless.

Please, please, please help me get CJAX doing something even halfway useful.
#2

[eluser]Ajaxboy[/eluser]
Hello Matt,

Thanks for your questions, I'll brake it down here for you.

First thing that comes to my mind is, did you download the right distribution of CJAX?. Please notice that there are 2 different distributions one that is specifically dedicated to codeigniter and a generic one that can be used with or without any other php framework.

The version that is distributed for codeigniter indeed has working examples for codeigniter - and they work out of box, so if you haven't seen them, I imagine you download the wrong distribution for codeigniter for how you described it.

So all the trouble you have been through might of been in-vain. There are specific instructions and two or three working examples that work out of the box, even in some of the most hostile hosts.

Please find the instructions here: https://github.com/EllisLab/CodeIgniter/...odeIgniter

Download here: http://sourceforge.net/projects/cjax/fil...p/download


The reason why there are confusions with the documentation, is because there used to be a wiki here where hosted all that info, but it was all moved over to github by ellislab, so that might have created some confusions.
#3

[eluser]Ajaxboy[/eluser]
In addition, It has been brought up before the difference between responses and controllers.

Cjax is designed to operate with Ajax controllers, for organization and other purposes. There are virtually no differences that you would notice if you run a ci controller or response. <b>Ajax Controllers also extend Codeignater so anything you use in codeigniter you can also use in Ajax Controllers</b>. Otherwise when you start developing alot of ajax functionality then you end up with tons of ajax mixed with normal controllers and other php, and controllers and it creates a messy workspace. That is what this design tries to avoid so that everything is organized and you can easily locate you ajax functionality.

However if you absolutely feel you don't need this, I imagine for whatever reason someone might want to just keep all together and messy, then you can always reverse this behavior by going into file ajax.php and on line 22, where it says "response", you may change that to "controllers", and it should route to your regular CI controllers.
#4

[eluser]LordMatt[/eluser]
Thank you.

I was pretty sure that I had the right version but I will [re]download the CI edition and add it to my project [again]. Having a response extend CI makes a whole heap of sense and was what I expected. That way I can have access to CI goodness and still use AJAX coolness which was what I wanted. I will let you know if the tears are ended after the weekend when I have a chance to apply what you have told me.
#5

[eluser]LordMatt[/eluser]
Check, check, check.

It looks like I was unfairly blaming CJAX which is working exactly as it should.

Do you have a best practice for getting at error reporting?
#6

[eluser]LordMatt[/eluser]
The debugging method I used was to put ajax messages throughout the code and then the last one to appear after that was the error, then that code I copied to my welcome controller and balm! Got the error message (a weird parse error I've not seen before. Fixed it anyway.

However for all other error levels I found this worked well.

Code:
&lt;?php
#Let's test our code line
                try {
                    $this->load->model('Users');
                } catch (Exception $e) {
                    $ajax->warning('Caught exception: '.  $e->getMessage() );
                }
#7

[eluser]Ajaxboy[/eluser]
As shown in the included ci samples, you must extend the CI_Controller in the response so that all the CI core is available to you, then preferably turn on errors on to see any errors if any.

Taken from application/response/test.php

class Test extends CI_Controller {

I also recommend firebug (for firefox) or chrome debugger (for chrome) to monitor the ajax responses. Regardless of anything else, you should always get a response back, and there is where these are used.




Theme © iAndrew 2016 - Forum software by © MyBB