Welcome Guest, Not a member yet? Register   Sign In
CJAX 'Can't find controller' error after install
#1

[eluser]jhob[/eluser]
I have just installed CJAX into a project that I am working on. The CJAX test pages and all the CJAX examples worked fine but any page from the actual site that worked ok previously gives an error like:

Code:
Controller File: item.php not found

This happens for many different controllers in the site. The controllers all exist in the controllers directory. None of them are doing anything at all to do with AJAX.

This is the only ajax related code in the site, which should just initialise CJAX:

Code:
require_once 'ajax.php';
$ajax = ajax();
<html>
<head>
echo $ajax->init();
</head>
<body>

If I comment it out the site works fine again (but with ajax disabled obviously).

I'm not actually using any AJAX on the site at the moment so a bit confused as to what is going on with it. I'm just trying to get CJAX installed so I can start adding some AJAX to the site.

I've been messing around with this for ages trying to get it to work and am now completely stumped. Any help would be greatly appreciated!

Many thanks,
John
#2

[eluser]jhob[/eluser]
Another thing is that sometimes the message comes up as a little alert like this:

http://hob.so/LyuE

This always happens on my site homepage.

But then any sub-page in the site the page totally fails to load and it's just plain text:

http://hob.so/Lyb7
#3

[eluser]Ajaxboy[/eluser]
Make sure the file, Application/response/item.php exists
#4

[eluser]jhob[/eluser]
But I already have item.php in Controllers directory:

Code:
class Item extends MY_Controller
{

which currently has non-AJAX methods.

Obviously I can't duplicate that class so not quite sure what I would put in response/item.php ?
#5

[eluser]Ajaxboy[/eluser]
[quote author="jhob" date="1357808087"]But I already have item.php in Controllers directory:

Code:
class Item extends MY_Controller
{

which currently has non-AJAX methods.

Obviously I can't duplicate that class so not quite sure what I would put in response/item.php ?[/quote
[/quote]

You can safefly replicate the class, due that when you run an ajax controller the other controller isn't running. Should you come to the unlikely situation when you need to load both controllers, you can start the ajax controller class with an undercore, "_".

Ajax controllers are separated from regular controllers for organization purposes so that you know where your ajax functionality is and it is not all mixed up. If you would like to change to and make it all mixed again, you need do the following:

Change file ajax.php line 22, to choose a the directory you want your ajax controllers in, in this case, "application/controllers"
#6

[eluser]jhob[/eluser]
Thanks very much for helping me with this, really appreciate your help.

It's still not working I'm afraid.

I got a PHP error with the repeated class name so I underscored the class in /response which got rid of the error but the site still does not work. The homepage loads fine but on viewing an item I get the error:

Code:
Controller Method/Function: item::16() was not found

Now I'm pretty sure this is because CJAX isn't looking at the routes where I have set:

Code:
$route['item/(:any)'] = 'item/view/$1';

However, that still begs the question as to why CJAX is trying to handle non-AJAX requests?

I tried changing AJAX_CD to application/controllers but the application behaved in the same way.

Still flummoxed by this issue, have you any more ideas?
#7

[eluser]Ajaxboy[/eluser]
It should not handle non-AJAX requests as far as I know. Just make sure you point to the right url path, cjax usually uses ajax.php or ajax/ path, I can't think of a situation where it would try to handle anything else.
#8

[eluser]jhob[/eluser]
I've done a bit more investigation and I think there may be some sort of conflict with ion_auth. However CJAX does still look like it is trying to handle non-AJAX methods Here's what I did:

Set up a really simple controller & view:

Controller
Code:
class Ajaxtest extends CI_Controller
{
    function __construct() {
        parent::__construct();
    }

    function index() {
        $this->load->view('ajaxtest');
    }
}

View
Code:
<?php
require_once "ajax.php";
$ajax = ajax();
?>

<html>
    <head>
        <?php echo $ajax->init(); ?>
    </head>
    <body>
       Hello hello
    </body>
</html>

Which gave the error:
Code:
Controller Method/Function: ajaxtest::ajaxtest() was not found

If comment out the ajax init in the view it works:

Code:
//require_once "ajax.php";
//$ajax = ajax();
?>

<html>
    <head>
        <?php //echo $ajax->init(); ?>
    </head>
    <body>
       Hello hello
    </body>
</html>

OR if I change the constructor to PHP4 style it works:

Code:
class Ajaxtest extends CI_Controller
{
    function Ajaxtest() {
        parent::__construct();
    }

    function index() {
        $this->load->view('ajaxtest');
    }
}

and then if I enable ion_auth in autoload:

Code:
$autoload['libraries'] = array('database','session','email','ion_auth');

I get the following error:

Code:
An Error Was Encountered

The model name you are loading is the name of a resource that is already being used: ion_auth_model

If it's relevant I am running PHP5.3.10 on Win7 x64.

So, any thoughts? I'm still none the wiser as to how I resolve this.

Cheers
John
#9

[eluser]Ajaxboy[/eluser]
Your php version looks fine.

The only scenario where Cjax would try to run your controller is if the word "controller" is defined some where in the url query string ($_GET or $_REQUEST method), or you some how start a new class of "ajax" - like " new ajax($controller);". As you can see in the last 3 lines of file ajaxfw.php, it would not start any other way, no way around that.

Or some how $_GET["controller"] gets defined in file cjax/cjax.php, which would only happen if $ajax->isAjaxRequest() return true or 'AJAX_VIEW' is defined which happens only in ajax.php line 34.

Try to debug and do (some where in your controller ):

Code:
echo "<pre>".print_r($_REQUEST,1))."</pre>";

And see if the controller shows up on the list.
#10

[eluser]jhob[/eluser]
I tried as you suggest but there's nothing in the request object that would be interfering, in fact the page I tried it with there was nothing at all.

Anyway I stripped this right back to see if I could work out where it was going wrong. Here's what I did

* Downloaded and installed a fresh CI 2.1.3.
* Downloaded and installed AJAXFW_4CI_5.3-Obama2012
* Modified views/welcome_message.php so that the start of the file looks like:

Code:
&lt;?php
require_once "ajax.php";
$ajax = ajax();
?&gt;
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;?php echo $ajax->init(); ?&gt;
&lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;

Now when I load the site at http://localhost/cjax/ the welcome message displays fine.

If I try to access the index method in the welcome controller at:

http://localhost/cjax/index.php?welcome/index

I get the error Controller File: welcome.php not found

Now I can't simplify any more than this and it's still not working. I can only think I'm doing something really dumb, am I?

I can send you the zip of the site if you want to take a look yourself.

Thanks again for your continued help.

John




Theme © iAndrew 2016 - Forum software by © MyBB