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

[eluser]jhob[/eluser]
I just tried downgrading to 5.2 but that behaves in exactly the same way.

I just can't get past this issue, I'm going to have to start looking at alternative ajax solutions.

#12

[eluser]Ajaxboy[/eluser]
What version of CI are you using? I have been busy at work so have not had time to look deep into the matter but this weekend hopefully I can reproduce issue.
#13

[eluser]jhob[/eluser]
Hi there,

Thanks for offering to take a look. It's CodeIgniter 2.1.3 that I'm using.

You can download the zip of my test install with just CI2.1.3 and CJAX here http://hob.so/MIiq . Just do as I described in last post to reproduce.

Be interested to see what you come up with. I'm sure it must be me doing something really dumb, just can't see the wood for the trees now!

Thanks
John
#14

[eluser]Ajaxboy[/eluser]
I see.

After running a test, i can see that in fact you are correct, it does shows an error for 2.1.3.

This is how I got rid of the error, instead of requiring "ajax.php" do, "ajaxfw.php".

After you do that if you still see a red message in the middle of the screen, go ahead and clear your browser's cookies, that seemed to get rid of the error.
#15

[eluser]Ajaxboy[/eluser]
So in conclusion, as it is apparent when you include ajax.php - then in line 46 it handles over the job to ajaxfw.php, but it seems that it wasn't doing that and was passing that point hence producing that behavior, so that is why using 'ajaxfw.php' fixes the issue. In previous versions of Cjax you would of always use 'ajaxfw.php' but then to make it easier use was added the ability to use 'ajax.php' and here is where this originates, if you included 'ajax.php' in previous versions of cjax, you would of gotten that issue anyways. I'll see if more checks can be added to prevent this behavior.
#16

[eluser]jhob[/eluser]
Thanks for that, I pretty much have it working now! I really appreciate your help with it.

However, and I'm not sure if this is by design, I can't use any codeigniter functions in the response controllers.

For instance I have the response controller:

Code:
class Item
{
    function favourite($item_id) {
        $ajax = ajax();
        $ajax->append('#favourite_button', 'favourited');
    }
}

But what I actually wanted to do was:

Code:
class Item
{
    function favourite($item_id) {
        $ajax = ajax();
        $user_id = $this->session->userdata('user_id');
        $this->load->model('favourite_model');
        $this->favourite_model->set_favourite($user_id, $item_id);
        $ajax->append('#favourite_button', 'favourited');
    }
}

But I can't do that as I get an undefined property error:

Code:
Notice: Undefined property: Item::$session

I did try passing a reference to the CI instance like you would do a library object:

Code:
$ci =& get_instance();

But that didn't work either.

Any ideas? I'm pretty sure there is a simple solution to this one. I hope so at least!
#17

[eluser]Ajaxboy[/eluser]
Should be:

Code:
class Item extends CI_Controller
#18

[eluser]jhob[/eluser]
I had tried that but got the error:

Code:
Fatal error: Class 'CI_Controller' not found

See full error output here: http://hob.so/MNJL

Is this something to do with including ajaxfw.php instead of ajax.php? I also tried copy pasting the code above the call to ajaxfw.php in ajax.php into the top of ajaxfw.php but that didn't make a difference.

Any ideas?
#19

[eluser]Ajaxboy[/eluser]
You are not supposed to access a controller directly. In fact you should add this on top:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

You should access it like this:

ajax.php?item/favourite

#20

[eluser]jhob[/eluser]
Right, I have it sorted at last!

I wasn't calling it directly but I was calling it incorrectly. I had wrongly assumed that because I was including ajaxfw.php I should also call ajaxfw.php?item/favourite. When I change it to ajax.php?item/favourite it works.

Many thanks for your help with this. I really appreciate it.

Hopefully that's the last you should hear from me for a bit! :p




Theme © iAndrew 2016 - Forum software by © MyBB