Welcome Guest, Not a member yet? Register   Sign In
AjaxFw (CJAX) not functionning
#1

[eluser]brizoo[/eluser]
Hi everyone,

Firts of all I would like to thank everyone who is involved with codeigniter community.
I'm new with it, and I really like it.

Now I'm trying to set up a "starter codeigniter kit". So when I need to start a project I can use it and save time.

I already have the last version of CI (2.1.3) working with ion_auth 2 integrated.

So I can access my admin page once logged in.

Then I decided to integrate the Tempalte functionnality by philsturgeon (on GitHub).

Everything is working too.

My next step was to integrate CJAX and try to handle error/succes messages.

So, I haven't anymore a static message which is stucked on my page until I load a new page... for exemple "successfuly logged in" or "unable to access to this part of the website" etc...

If I can hadle messages with CJAX, I would be able to have a message appearing for 10 sec and then it would disappear. (basic javascript functionnality just to try CJAX).

Unfortunately I'm encountering an error with CJAX.

When I try this http://www.mydomain.com/ajax.php?test/test

Code:
ajax view...

Ajax Controllers work great.

View: test2

When I try to access to http://www.mydomain.com/ajax.php?test/test2
I got this error

Code:
A PHP Error was encountered

Severity: Warning

Message: Creating default object from empty value

Filename: classes/core.class.php

Line Number: 253

Once on the login page, everything is fine but once I've clicked on "login" I'm not properly redirect and I got this error.

Code:
Controller File: admin.php not found

If someone have experienced this error, that would be awesome to give a hand !

I'm quite new with CI and this is a bit too deep for me, I honnestly don't know where the problem is...
I think the compatibility with "Template" is maybe a starting point, but I'm not sure of it..

Thank you very much in advance.
#2

[eluser]brizoo[/eluser]
I almost forget to show how I have modified the "build()" function in Template.php librarie file so I can load CJAX each time I'm building a page.

Have a look where I have commented this -> //instaciate ajax

Code:
/**
  * Build the entire HTML output combining partials, layouts and views.
  *
  * @access public
  * @param string
  * @return void
  */
public function build($view, $data = array(), $return = FALSE)
{
  // Set whatever values are given. These will be available to all view files
  is_array($data) OR $data = (array) $data;

  // Merge in what we already have with the specific data
  $this->_data = array_merge($this->_data, $data);

  // We don't need you any more buddy
  unset($data);
  
  //instaciate ajax
  include_once(BASEPATH.'../ajax.php');
  $ajax = ajax();
  
  if (empty($this->_title))
  {
   $this->_title = $this->_guess_title();
  }

  // Output template variables to the template
  $template['ajax']    = $ajax->init();
  $template['location']          = $this->_location;
  $template['js']    = $this->_js;
  $template['css']   = $this->_css;
  $template['title']   = $this->_title;
  $template['breadcrumbs']  = $this->_breadcrumbs;
  $template['metadata']  = implode("\n\t\t", $this->_metadata);
  $template['partials']  = array();

  // Assign by reference, as all loaded views will need access to partials
  $this->_data['template'] =& $template;

  foreach ($this->_partials as $name => $partial)
  {
   // We can only work with data arrays
   is_array($partial['data']) OR $partial['data'] = (array) $partial['data'];

   // If it uses a view, load it
   if (isset($partial['view']))
   {
    $template['partials'][$name] = $this->_find_view($partial['view'], $partial['data']);
   }

   // Otherwise the partial must be a string
   else
   {
    if ($this->_parser_enabled === TRUE)
    {
     $partial['string'] = $this->_ci->parser->parse_string($partial['string'], $this->_data + $partial['data'], TRUE, TRUE);
    }

    $template['partials'][$name] = $partial['string'];
   }
  }

  // Disable sodding IE7's constant cacheing!!
  $this->_ci->output->set_header('Expires: Sat, 01 Jan 2000 00:00:01 GMT');
  $this->_ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
  $this->_ci->output->set_header('Cache-Control: post-check=0, pre-check=0, max-age=0');
  $this->_ci->output->set_header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
  $this->_ci->output->set_header('Pragma: no-cache');

  // Let CI do the caching instead of the browser
  $this->_ci->output->cache($this->cache_lifetime);

  // Test to see if this file
  $this->_body = $this->_find_view($view, array(), $this->_parser_body_enabled);

  // Want this file wrapped with a layout file?
  if ($this->_layout)
  {
   // Added to $this->_data['template'] by refference
   $template['body'] = $this->_body;

   // Find the main body and 3rd param means parse if its a theme view (only if parser is enabled)
   $this->_body =  self::_load_view('layouts/'.$this->_layout, $this->_data, TRUE, self::_find_view_folder());
  }

  // Want it returned or output to browser?
  if ( ! $return)
  {
   $this->_ci->output->set_output($this->_body);
  }

  return $this->_body;
}

and then in my "backend" template, I just did this to instanciate CJAX.
Do you think this is wrong ?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html  lang="fr"&gt;
  &lt;head&gt;
&lt;title&gt;&lt;?=$template['title'];?&gt;&lt;/title&gt;
&lt;?php echo $template['ajax']; ?&gt;
&lt;meta name="robots" c&gt;
&lt;meta name="robots" c&gt;
.......
#3

[eluser]Ajaxboy[/eluser]
Can you specify exactly what version of PHP you are using?, Please notice that Cjax won't currently work with the php5.4 and not guarantees with php 5.1 either, has far is on board with php5.2 and php5.3 and strict standards turned off.

That error you are getting kind of sounds like php 5.4, this might be the next big change in Cjax the support of php 5.4.
#4

[eluser]brizoo[/eluser]
Hi,

I'm using PHP 5.4 and I just realized that it is not compatible yet.

Fortunately this is not a problem for me.

I've already changed my PHP version and the second part of the test is working now Smile

I was so impatient to try CJAX I think, that I forget to read all of your recommandations.

This librarie looks awesome. I'll tell you if everything is fine !

Thanks again for your contribution, I can't believe that it is so easy to have some AJAX in a website.

I'll keep you all posted if everything is fine.
#5

[eluser]brizoo[/eluser]
Hi again,

Unfortunately I have the same error than before but this error appears into an Ajax message which means that CJAX is working at least.

Code:
Controller File: admin.php not found

The problem is that, when I remove CJAX, everything is working fine, but when I instanciate it, I got this error.

To make it simple to understand, I previously had subfolders in my "controllers" folder and particularly one called "admin". I thought this was the problem, but infact not because I have now moved every files and I have no more sub-folders in "controllers" folder.

So I actually have one file called admin.php in my folder "controllers" but I still have this error.

Do you know what this could be ?

Thanks

#6

[eluser]Ajaxboy[/eluser]
Make sure you put your Ajax Controllers in "Response" directory, not in "Controllers" directory.
#7

[eluser]brizoo[/eluser]
This is what I havn't understand I think.

For example, in my views I have a "partials" folder which contains my menus, footer, and my flashdatas.

What I mean by "flashdatas" is my returned messages.

For example in each pages, I include the view "flashdata" which read into the session to find if it exists any messages and display it.

This is the content of my view :

Code:
&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');

    $messages = $this->session->flashdata('message');
  
    if(isset($messages) and $messages != '')
    {
     if ( is_array($messages['text']))
     {
                foreach ($messages['text'] as $msg) {
      $ajax->warning($msg." Warning message...");
      //$this->firephp->warn($msg);
                }
     }
     else
     {
  $ajax->warning($messages['text']." Warning message...");
  //$this->firephp->warn($messages['text']);
     }

    }
?&gt;

So if I understand properly, I should create an Ajax controller to manipulate this, and call it into this view by calling the url http://www.mydomain.com/ajaxcontroller.p.../variable2 .....

Am I right ?

Thanks
#8

[eluser]Ajaxboy[/eluser]
Technically, the url should read as:

http://www.mydomain.com/ajax.php?control.../variable2 .....

(With mod-rewrite should be: http://www.mydomain.com/ajax/controller/.../variable2)

Your Ajax Controllers should be placed under:

Application/response/

If you want to change the directory just edit line 22 in ajax.php and change the directory where you'd like your Ajax Controllers to be placed.

Here are some more docs:

https://github.com/EllisLab/CodeIgniter/...odeIgniter
#9

[eluser]brizoo[/eluser]
All right, Thanks for all.

So it is a good practice to call ajaxcontrollers into views ?

Cheers
#10

[eluser]Ajaxboy[/eluser]
No Problem.

Can you give an example how you'd use it?




Theme © iAndrew 2016 - Forum software by © MyBB