ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ajax Framework (CJAX) for Codeigniter 2.x+

April 29, 2012 11:33am

Subscribe [24]
  • #76 / Jun 23, 2012 5:07pm

    Ajaxboy

    243 posts

    Update:

    All issues mentioned above have been fixed and are available after RC3:

    Proceed to download the updated version:

    <a href="http://sourceforge.net/projects/cjax/files/CodeIgnater/">http://sourceforge.net/projects/cjax/files/CodeIgnater/</a>


    After the conference call, here are the bugs identified, These are immediate fixes. These are patches you can apply yourself in the mean time, but these fixes will be included in the next release.

    3 bugs were identified, mainly small and innocent but deadly.

    #1


    Introduced in RC2:

    Forces controller to inherit a parent class when not needed.

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined property: empty__test::$load

    Filename: response/test.php

    Line Number: 8


    Fix:

    In file ajaxfw.php on line 113:

    Change:

    if(method_exists($class, $class) || method_exists($class, '__construct')) {

    To:

    if(method_exists($class, $class))  {

    #2

    Introduced in RC2:


    Bug when looking at the examples package, shows an errors when looking at the examples

    Your system folder path does not appear to be set correctly. Please open the following file and correct this: ajax.php

    Fix:

    inside file: examples/ajax.php on line 3:

    Change:

    if(!file_exists($f = '../ajax.php')) {

    To:

    if(!file_exists($f = '../ajaxfw.php') && !file_exists($f = '../ajax.php')) {

    That should fix that issue.

    #3

    Introduced in RC2:

    Error: "( ! )

    Warning: defined() expects exactly 1 parameter, 2 given in C:\wamp\www2\ajax.php on line 34

    ";

    Fix:

    Follow the instructions specified here:
    http://ellislab.com/forums/viewthread/216298/P40/#1012750

     

  • #77 / Jun 23, 2012 11:52pm

    MonsterTKE

    27 posts

    Found this one in the example page.

    Call to undefined method validate::rule() in /var/www/examples/plugin_validate.php on line 53

    Using validate plugin cjax.validate_1.3.zip

  • #78 / Jun 23, 2012 11:54pm

    Ajaxboy

    243 posts

    Download the latest validate plugin:  (cjax.validate_1.3.zip) you are probably using the older version.

    http://sourceforge.net/projects/cjax/files/Plugins/

  • #79 / Jun 23, 2012 11:56pm

    MonsterTKE

    27 posts

    Nope, that is the one I have. All the .zip contents go in the plugin directory right?

  • #80 / Jun 23, 2012 11:57pm

    Ajaxboy

    243 posts

    the directory itself goes in the plugin’s directory

  • #81 / Jun 23, 2012 11:59pm

    MonsterTKE

    27 posts

    <_< Well that would make more sense. Working now.

  • #82 / Jun 24, 2012 4:01am

    MonsterTKE

    27 posts

    Ok I am 2-3 hours into learning this Librarys API, and so far it is awesome, I have pretty much reimplemented most of the examples to learn from.

    This may be a general AJAX question but consider the scenario I have.

    1. url. /rating/add/28/up . This is all server side, no post data, I grab some session info and user_id from tank_auth. The /28/up part is sanitized by hand with some if statements.

    2. The controller redirects to the base_url on success (ahem, AJAX), or to one of two error pages, a general error, and a “sorry you cant vote twice” page. If they arent logged in it redirects to /auth/login.

    So my question is… Can I run that function via AJAX, load the views for the errors if necessary(in an overlay) and here is the kicker, on success, open a comment form in an overlay to submit a comment using all of the validation data I collected when the link was first clicked?

    I can probably hack this together using a few different functions and a new form view, Im just hoping there is some easy way to do this.

    (I should mention all of the /rating/add/#/up|down links are presented in the view with a foreach, Im assuming I would have to add the $ajax-> methods using a foreach to setup the div ids?)

  • #83 / Jun 24, 2012 4:34am

    Ajaxboy

    243 posts

    1. These broad questions, and there are many ways of accomplishing the objective you are after.

    Generally speaking, instead of redirecting to an error page, generally in the ajax framework you may display error messages on the screen eg: $ajax->error(“Error Message Here”) or warnings; $ajax->warning(“Warning Message Here”) ;

    2.  If you actually wish to redirect to the base url you can do:  $ajax->location(base_url());

    So my question is… Can I run that function via AJAX, load the views for the errors if necessary(in an overlay) and here is the kicker, on success, open a comment form in an overlay to submit a comment using all of the validation data I collected when the link was first clicked?

    Yes, you can load a view in an overlay.

    Just do:

    $ajax->overlayContent($this->load->view(‘your_template_view_here’, null, true));

    So now your question relates to the validation plugin…

    Since the form doesn’t exist on page load, You would need to trigger the validate plugin from the ajax response and add validation to that form just after you run the $ajax->overlayContent() command which displays the form.

    just make sure you run the validate plugin command after the overlayContent that displays the form and not before to avoid retroactive action.

     

     

  • #84 / Jun 24, 2012 4:47am

    MonsterTKE

    27 posts

    Cool, I spent a few minutes thinking about a code flow for this. Mainly I am trying to keep the backend behavior and the comment/whatever part of the same series of actions.

    foreach ($result as $row)
    <a href="#">id;}">clicky</a>
    
    $ajax->call('/ajax/class/function/{$row->var1}/{$row->var2}')
    
    $this->load->view(FORM)
    
    submit
    
    function do_some_things($var1, $var2) {
    //run some other stuff here with the data supplied
    }
    function handle_the_form() { }

    Thats about it I think, and probably as hard as I have had to think about implementing something so far.

    Thanks again for your help 😊

  • #85 / Jun 24, 2012 5:07am

    Ajaxboy

    243 posts

    that’s your pseudo code..

    first separate your view from your from your ajax controller..

    Lets say this is your view..

    <?php 
    
    foreach ($result as $row):
     echo "<a href="#">id}'>clicky</a>";
    
    //adds click event to the link above
    $ajax->Exec("thing_{$row->id}",$ajax->call("/ajax/x_class/do_some_things/{$row->var1}/{$row->var2}"));
    
    endforeach;
    ?>

    Then handle the ajax controller

    // controller handler..
    in your ajax   application/response/x_class.php - x_class::do_some_things()

    class x_class extends CI_Controller {
    
     function do_some_things($var1, $var2) {
      $ajax = ajax();
        
      $vars['var1' = $var1;
      $vars['var2' = $var2;
    
      $ajax->overlayContent($this->load->view('your_form', $vars, true));
    
      //your validation rules
      $rules = array();
    
      //assuming your button id is 'btn_frm' 
      $ajax->validate('btn_frm', '/ajax/x_class/handle_the_form',$rules);
     }
    
     function handle_the_form()
     {
      $ajax = ajax();
      //debug to see the data posted..
      $ajax->dialog('<pre>'.print_r($_POST,1)).'</pre><p>‘,‘Form Data’);<br />
     }</p>
    
    <p>}
    </pre>

     

  • #86 / Jun 24, 2012 7:56am

    Ajaxboy

    243 posts

    You may need a small change in the plugin

    in plugin file cjax/plugins/validate/validate.php

    add this function, in plugin class validate:

    function onAjaxLoad($button_id, $post_url, $rules = array())
     {
       return $this->onLoad($button_id, $post_url, $rules);
     }

    This is because the plugin in its current state was not setup to trigger validation while in an ajax request, but by adding the function above, you will add the trigger.

  • #87 / Jun 25, 2012 4:41am

    MonsterTKE

    27 posts

    You may need a small change in the plugin

    in plugin file

    I have all of the stuff discussed yesterday implemented, but with a slight problem.

    The ajax calls dont seem to be surviving the foreach loop I am using to build the page.

    It works just fine on the base url page, but when I click on a pagination link to go to page 2 or greater, the links Im using to call the ajax with just turn into regular anchors.

    What else is surprising is if I call the page with the controller and method in the url it also doesnt work.

  • #88 / Jun 25, 2012 4:46am

    Ajaxboy

    243 posts

    Try doing it in your CI controller instead of on the view. It is possible that the JavaScript lib is being loaded before the statement in the view, so it won’t pick these commands retroactively.

    Eg:
    In your Controller

    foreach ($result as $row) {
     $ajax->Exec("thing_{$row->id}",$ajax->call("/ajax/x_class/do_some_things/{$row->var1}/{$row->var2}"));
    }


    Then in your view do your anchors:

    foreach ($result as $row):
     echo "<a href="#">id}'>clicky</a>";
    endforeach;

     

  • #89 / Jun 25, 2012 5:02am

    MonsterTKE

    27 posts

    Try doing it in your CI controller instead of on the view. It is possible that the JavaScript lib is being loaded before the statement in the view, so it won’t pick these commands retroactively.

    It behaved the same with the $ajax->Exec forloop in the controller. Works Just fine for the first 5 links. http://monstertke.zapto.org (red and green vote counters)

    calling the controller and function directly http://monstertke.zapto.org/vendors/index doesnt work, nor does calling it with the pagination links at the bottom of the page.

    Im assuming you meant to loop them in the “vendors” controller, not the ajax controller I am calling?

  • #90 / Jun 25, 2012 5:35am

    Ajaxboy

    243 posts

    It is recommended to use firebug (https://getfirebug.com/) for quick error debugging, it appears the path for the js lib is incorrect,So the js lib is not being loaded.

    This is the error I saw on your page:

    “NetworkError: 404 Not Found - http://monstertke.zapto.org/vendors/cjax/core/js/cjax-5.0-RC2.min.js”

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases