ajaxboy / cjax

Lightweight Ajax Framework built in PHP with no foot-print. Allows you to build ajax functionality with a single line of code & do so much more, right from the back-end!
http://cjax.sourceforge.net/
66 stars 27 forks source link

Inheriting CI_Controller #26

Open oniwo opened 8 years ago

oniwo commented 8 years ago

The controllers in Beta 1 release version 6.0 can not inherit the CI_Controller class of CodeIgniter.

I am developing an application using version 5.8, and this is possible there. Because the CJAX controllers in version 5.8 can inherit CI_Controller class of CodeIgniter, I can load my CodeIgniter models and libraries into the CJAX controllers and reuse the code in the models and libraries.

I have tried this in the Beta 1 release of version 6.0 and found it is not possible.

oniwo commented 8 years ago

This inheritance issue was with Beta 1. I have seen the workaround suggested at issue #19 but fast forward to Beta 3. There is no chance for testing the workaround because the 'ajax.php' which I believe launches the cjax controllers used to be 'the root of the site' but is now pushed ahead to the 'cjax/' directory.

The system is still looking for it at 'the root of the site' and and responding with

404 Not Found: The requested URL /ajax.php was not found on this server.

In Beta 3, the system is supposed to look for it in '/cjax/' not '/'. What do I do to correct this? Simply moving the file back to the root ends with the following

Error: The server encountered an unexpected Error with status 500.

HallofFamer commented 8 years ago

If the system is looking for ajax.php in the wrong path, this means that you need to change its include path. In case you've taken a look into the updated examples, the file check has been modified from this in CJAX 5.8:

if(!file_exists($f = '../ajaxfw.php') && !file_exists($f = '../ajax.php')) {
//throw a PHP fatal error
}

To this in CJAX 6.0:

if(!file_exists($f = '../cjax/ajax.php')){
    //throw CJAXException inside.
}

I am not sure how ajax.php is included in CI integration, so you need to search through the lines that checks ajax.php or ajaxfw.php, and replace it by cjax/ajax.php. It should solve the problem once you have changed the include path.

ajaxboy commented 8 years ago

without including ajaxfw.php the CI integration will not work, I don't think. This file should not be present by default, it would be present in the CI version of Cjax. However the less changes kept between version the better for maintenance purposes. There are no known changes to framework needed to integrate with CI, removing this inclusion would require this change for CI integration to work.

oniwo commented 8 years ago

Here start.php.pdf is the view I am using to test the cjax controllers. A click on the button ends with a search for 'ajax.php' in '/' instead of in 'cjax/'. So I cant reach the cjax controllers. Is there something I am not doing right? Remember I am taking about reaching cjax controllers not CI controllers; I am unable to reach cjax controllers.

HallofFamer commented 8 years ago

Well to my understanding CodeIgniter uses mod_rewrite in .htaccess, so maybe you need to edit that file and change ajax.php to cjax/ajax.php?

oniwo commented 8 years ago

I have edited 'ajax.php' to 'cjax/ajax.php' in the .htaccess but with my base directory as '/examsystem/' the AJAX request is still

http://127.0.0.1:8080/examsystem/ajax.php?test/test//

instead of

http://127.0.0.1:8080/examsystem/cjax/ajax.php?test/test//

And just as a by the way, why did 'ajax.php' move ahead from '/' to 'cjax/'?

HallofFamer commented 8 years ago

I see, so the .htaccess settings has nothing to do with this. If I may ask, are you using this integration patch CJ made several years ago? If so, did you change anything in ci_ajax.php file?

https://github.com/ajaxboy/ci_cjax

oniwo commented 8 years ago

I am simply using AJAXFW_4CI_5.8.zip. I did not make any changes to it. It has 'ajax.php' and 'ajaxfw.php' (ajaxfw.php.pdf) at the root. I was excited to read that "... its MVC design makes it quite easy to integrate into existing PHP-Frameworks (such as Zend, CodeIgnater, cakePHP, Yii, etc)". So I tested with CodeIgnitor and it worked so well, that I began to do very serious work with it. I never tested it with another PHP-Framework.

HallofFamer commented 8 years ago

I understand. In fact CJAX 6.0 is still in beta, and I will begin targeting framework integration after CJAX 6.0 Beta 3, before the stable release of CJAX 6.0 Gold. I plan to have Symfony 3, Laravel 5 and Zend Framework 3 integration done by then, and these are the frameworks I recommend PHP developers to use nowadays. I may expand support to CakePHP 3, CodeIgniter 3 and Yii 2 if demand is high.

Right now, there is no guarantee that it works with frameworks such as CodeIgniter, but I can help you with your problem further since I know I will have to tackle the issue of framework integration myself sooner or later. If you still need help, I will try to set up CodeIgniter 3 on my local machine and see if I can reproduce the same error/issue from you. Then I can possibly offer a fix for your problem.

oniwo commented 8 years ago

Yes please I need help. Please install CodeIgniter 3 as you suggest to see if you can fix my problem. I would like to be with you step by step as you develop CJAX 6.0.

The Introduction section of https://github.com/ajaxboy/cjax says about cjax: "With its MVC design makes it quite easy to integrate into existing PHP-Frameworks (such as Zend, CodeIgnater, cakePHP, Yii, etc)."

But you say "I plan to have Symfony 3, Laravel 5 and Zend Framework 3 integration done..." leaving out CodeIgniter and the rest. Was CJAX originally designed to integrate with any PHP-Framework? If not, is it possible? I wish version CJAX 6.0 can be generic in its integration so that it can easily integrate with any PHP-Framework. I believe there are software design patterns out there for implementing such a generic integration. I would not like a situation where there is CJAX 6.0 for PHP-Framework X, CJAX 6.0 for PHP-Framework Y, and so on.

HallofFamer commented 8 years ago

Sure, I will install CodeIgniter 3 on my local PC tonight after I return home, I will see what error message I get. The error you get is very strange though, I guess the integration file needs to be tweaked a little, or to change completely.

In theory, yeah I want CJAX 6.0 to be generic as well, generic enough that you can use it easily with or without frameworks. I know that for CJAX 5.x this cannot be done without manual integration, I worked on a website in production that I ended up having to edit ajax.php file to get it to work. If you've seen the ajax.php file for CJAX 5.x's CodeIgniter Integration, you'd know that additional work was done to integrate CJAX 5.x with CI.

For CJAX 6.x though, I want that you can use it just by downloading it to a folder on your server, such as Vendor, and use it by including the autoloader file. Or even better, installing it through composer. You may wonder why I moved ajax.php to inside the cjax folder, this is exactly the reason. It will take time to happen though, as I also have other work to do for CJAX 6.0.

If CJAX 6.0 can be distributed as a library to be included, rather than a framework to be installed, it will make people's life easier. As you've seen from the beta versions of CJAX 6.0 that I've been working on a re-architecting CJAX, so the process has already begun. In future, CJAX will become a library, but for CJAX 6.0 or even 6.1 I cannot guarantee that. Hopefully now you understand the situation a little.

oniwo commented 8 years ago

Still waiting... have you tested CodeIgniter 3 integration with CJAX?

And by the way, just thinking... would I be worse or better off using jQuery instead of CJAX? I can see that CJAX is heading the library way which is a very good thing; no installation. that is why I like CodeIgniter, no installation.

HallofFamer commented 8 years ago

I did test it on my server, and yes you are right I have experienced the same issues as you had. I am trying to resolve it now, hopefully at the end of this week I can get some positive results. I was kept busy earlier since I needed to do some other work.

I think you'd be worse off using JQuery instead of CJAX. CJAX is a library designed for organizing PHP-AJAX application, while JQuery doesnt do anything on the server side and you will still need a way to process server side code. CJAX provides easier and convenient way to organize server side code sued for AJAX requests, which is its cutting edge feature. But of course, CJAX only works on PHP and we have no plan for porting it to other languages. I'd say use CJAX if you are on PHP, but JQuery is of course better on other platform such as Python and .NET, which CJAX doesnt work with.

ajaxboy commented 8 years ago

@oniwo note that Cjax 5.9 already has support for CodeIgniter 3.x. There are instructions on the CI forum also how to make Cjax 5.8 compatible with CI 3.x.