jaxon-php / jaxon-core

The Jaxon core library
https://www.jaxon-php.org
BSD 3-Clause "New" or "Revised" License
65 stars 28 forks source link

Upgrade Jaxon-PHP from 2.0-beta.24 to 2.2.6 #47

Closed tom-lp-at closed 5 years ago

tom-lp-at commented 5 years ago

Hello, i worked successful for years with xajax and afterwards with jaxon-php. The last version i worked with is Jaxon2.0-beta.24. In the meantime i changed to codeigniter as framework and could successful integrate jaxon-php (with jaxon-codeigniter). Now i tried to update with "composer update" to the current jaxon-php (2.2.6) but have no success. I changed the old

use Jaxon\Sentry\Classes\Base as JaxonClass; to use Jaxon\Sentry\Armada as JaxonClass; and the Classes registers successful. I can call from the Javascriptconsole the functions, but the response is empty. I inserted some checkpoints into the code (in the __constructer), but they are never past. It seams that the registered functions are not called:

Jaxon.App.auswertungen_austritt_ajax.hole_liste(); false

Parameter =>

jxncls | Jaxon.App.auswertungen_austritt_ajax jxnmthd | hole_liste jxnr | 1570315569596

Answer => {"jxnobj":[]} do you have a glue what i missed ?

Code:

class Auswertungen extends MY_Controller {

public function construct() { parent::construct(); // Load the Jaxon library $this->load->library('jaxon'); } public function Austritt() { $this->jaxon->register(); $this->smarty->view('benutzer-listenAustritt2-index.tpl', array( "jaxonCss" => $this->jaxon->css(), "jaxonJs" => $this->jaxon->js(), "jaxonScript" => $this->jaxon->script(), )); }`

auswertungen_austritt_ajax.php

namespace Jaxon\App;

use Jaxon\Sentry\Armada as JaxonClass; // use Jaxon\Sentry\Classes\Base as JaxonClass;

class auswertungen_austritt_ajax extends JaxonClass { protected $ci=0; public function __construct() { log_message("info","construct"); echo "HIER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; parent::construct(); }

tom-lp-at commented 5 years ago

Hello again, i go back until Version 2.0-beta.28 (i had 2.0-beta24 before) and there it works. With the update to 2.0.0 all the responses are empty. I followed the examples (btw: the online example show´s an error) with no success. I cant find a document where is described what is to do by changing from 2.0-beta to stable :( I checked the commit from the 2.0.0-Verison of jaxon-core and realize that there is the step to Armanda. Could it be that the jaxon-codeigniter is outdated ? The last version is after the commit of jaxon-core 2.0.0, but i can not find a glue to bring it back to work >= 2.0.0.... kR Tom

tom-lp-at commented 5 years ago

Hello again, i recognized that only some functions are working. Only the functions with a return $this->response are working. With 2.0-beta.24 all response methods are working and give responses - also without a explicit return $this->response. It seams that i stuck on this beta release :( kr Tom

feuzeu commented 5 years ago

Hi, In the case you have some classes which do not return the jaxon response, you have to add your response to the returned reponse by yourself. You will then need to edit the the jaxon controller provided in the CodeIgniter plugin. https://github.com/jaxon-php/jaxon-codeigniter/blob/master/app/controllers/jaxon/Process.php

    /**
     * Callback after processing a Jaxon request.
     *
     * @param object            $instance               The Jaxon class instance called
     * @param string            $method                 The Jaxon class method called
     *
     * @return void
     */
    public function afterRequest($instance, $method)
    {
        $xResponseManager = jaxon()->getResponseManager();
        $xResponseManager->clear();
        $xResponseManager->append(jaxon()->getResponse());
    }
tom-lp-at commented 5 years ago

Dear feuzeu, thx for your response. It seams that my problem is a little bit deeper :( i wrote this sample code:

<?php

 namespace Jaxon\App;
 use Jaxon\Sentry\Armada as JaxonClass;

 class welcome_ajax extends JaxonClass { 

         public function index() {
            log_message('info','Bin hier');
            $this->response->assign('testtom','innerHTML','HALLLO');
            return $this->response;
        }
 }

 ?\> 

The Method index() will is not called, but i get a (empty) response, if i entered in the JavaScript-Console of the browser :

Jaxon.App.welcome_ajax.index();
false

so - in my opinion, that JS-Callback-function is build, but it call not the index()-method on the php-side :( In the Developertools i see the request to process.php with the right parameter:

jxncls      | Jaxon.App.welcome_ajax
jxnmthd     | index
jxnr        | 1570964591097

but the logs show no entry of my message, so it seams that the PHP-Function is not called....

(it´s a complete new build up installation of CI 3 with all defaults and last stable versions....) i implement your suggestion (not needed in the test, but may be later) :

<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Process extends CI_Controller
{
    /**
     * Load the Jaxon and Session libraries.
     */
    public function __construct()
    {
        parent::__construct();
        // Load the Jaxon library
        $this->load->library('jaxon');
        // Load the session library
        $this->load->library('session');
    }

    /**
     * Callback for initializing a Jaxon class instance.
     *
     * This function is called anytime a Jaxon class is instanciated.
     *
     * @param object            $instance               The Jaxon class instance
     *
     * @return void
     */
    public function initInstance($instance)
    {
    }

    /**
     * Callback before processing a Jaxon request.
     *
     * @param object            $instance               The Jaxon class instance to call
     * @param string            $method                 The Jaxon class method to call
     * @param boolean           $bEndRequest            Whether to end the request or not
     *
     * @return void
     */
    public function beforeRequest($instance, $method, &$bEndRequest)
    {
    }

    /**
     * Callback after processing a Jaxon request.
     *
     * @param object            $instance               The Jaxon class instance called
     * @param string            $method                 The Jaxon class method called
     *
     * @return void
     */
    public function afterRequest($instance, $method)
    {
        $xResponseManager = jaxon()->getResponseManager();
        $xResponseManager->clear();
        $xResponseManager->append(jaxon()->getResponse());
    }

    /**
     * Process a Jaxon request.
     *
     * The HTTP response is automatically sent back to the browser
     *
     * @return void
     */
    public function index()
    {
        $this->jaxon->onInit(function ($instance) {
            $this->initInstance($instance);
        });
        $this->jaxon->onBefore(function ($instance, $method, &$bEndRequest) {
            $this->beforeRequest($instance, $method, $bEndRequest);
        });
        $this->jaxon->onAfter(function ($instance, $method) {
            $this->afterRequest($instance, $method);
        });

        // Process the Jaxon request
        if($this->jaxon->canProcessRequest())
        {
            $this->jaxon->processRequest();
            // $this->jaxon->httpResponse();
        }
    }
}

here is the Welcome.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {
        public function __construct() {
                parent::__construct();

                $this->load->library('jaxon');
        }

        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *              http://example.com/index.php/welcome
         *      - or -
         *              http://example.com/index.php/welcome/index
         *      - or -
         * Since this controller is set as the default controller in
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see https://codeigniter.com/user_guide/general/urls.html
         */
        public function index()
        {
                $retour = $this->jaxon->register();
//              log_message("info","Retour = ".var_export($retour,true));

                $this->load->view('welcome_message', array(
            'JaxonCss' => $this->jaxon->css(),
            'JaxonJs' => $this->jaxon->js(),
            'JaxonScript' => $this->jaxon->script())
            );
        }
}

kr Tom

feuzeu commented 5 years ago

Hi Tom,

I suggest first to use the beforeRequest() to make sure the right method is called.

    public function beforeRequest($instance, $method, &$bEndRequest)
    {
        log_message('info', "Jaxon class name is " . get_class($instance) . " and method is $method");
    }

You can then make sure the response and response manager return the same output.

    public function afterRequest($instance, $method)
    {
        log_message('info', "Jaxon response output is " . jaxon()->getResponse()->getOutput());
        log_message('info', "Jaxon response manager output is " . jaxon()->getResponseManager()->getOutput());
    }

The outputs must contain the instructions you added in your Jaxon class.

tom-lp-at commented 5 years ago

Dear Feuzeu, thanks for your response. Jaxon-php didn´t :) the 'BeforeRequest' is not passed:

INFO - 2019-10-16 10:39:00 --> Config Class Initialized
INFO - 2019-10-16 10:39:00 --> Hooks Class Initialized
DEBUG - 2019-10-16 10:39:00 --> UTF-8 Support Enabled
INFO - 2019-10-16 10:39:00 --> Utf8 Class Initialized
INFO - 2019-10-16 10:39:00 --> URI Class Initialized
INFO - 2019-10-16 10:39:00 --> Router Class Initialized
INFO - 2019-10-16 10:39:00 --> Output Class Initialized
INFO - 2019-10-16 10:39:00 --> Security Class Initialized
DEBUG - 2019-10-16 10:39:00 --> Global POST, GET and COOKIE data sanitized
INFO - 2019-10-16 10:39:00 --> Input Class Initialized
INFO - 2019-10-16 10:39:00 --> Language Class Initialized
INFO - 2019-10-16 10:39:00 --> Loader Class Initialized
INFO - 2019-10-16 10:39:00 --> Controller Class Initialized
DEBUG - 2019-10-16 10:39:00 --> Config file loaded: /home/tom/entwicklung/CI-Test-Jaxon/application/config/jaxon.php
DEBUG - 2019-10-16 10:39:00 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
INFO - 2019-10-16 10:39:00 --> Session: Class initialized using 'files' driver.
INFO - 2019-10-16 10:39:00 --> Jaxon response output is {"jxnobj":[]}
INFO - 2019-10-16 10:39:00 --> Jaxon response manager output is {"jxnobj":[]}

the index() in Process.php show´s now:

/**
     * Process a Jaxon request.
     *
     * The HTTP response is automatically sent back to the browser
     *
     * @return void
     */
    public function index()
    {
            $this->jaxon->onInit(function ($instance) {
            $this->initInstance($instance);
        });
        $this->jaxon->onBefore(function ($instance, $method, &$bEndRequest) {
            $this->beforeRequest($instance, $method, $bEndRequest);
        });
        $this->jaxon->onAfter(function ($instance, $method) {
            $this->afterRequest($instance, $method);
        });

        // Process the Jaxon request
        if($this->jaxon->canProcessRequest())
        {
            $this->jaxon->processRequest();
           // $this->jaxon->httpResponse();
        }
    }

i double checked the checked out version from 'composer info' :

composer info
Deprecation warning: require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead. Make sure you fix this as Composer 2.0 will error.
doctrine/instantiator              1.2.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
jaxon-php/jaxon-codeigniter        v2.0.2  Jaxon library integration for the CodeIgniter framework
jaxon-php/jaxon-core               v2.2.10 Jaxon is an open source PHP library for easily creating Ajax web applications
jaxon-php/jaxon-sentry             v2.0.7  Common classes providing advanced features to the Jaxon library
lemonphp/event                     v1.0.0  Simple event dispatcher
matthiasmullie/minify              1.3.61  CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shor...
matthiasmullie/path-converter      1.1.2   Relative path converter
mikey179/vfsstream                 v1.1.0 
myclabs/deep-copy                  1.9.3   Create deep copies (clones) of your objects
phpdocumentor/reflection-common    2.0.0   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  4.3.2   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver        1.0.1   A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/prophecy                   1.9.0   Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          4.0.8   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          1.4.5   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1   Simple template engine.
phpunit/php-timer                  1.0.9   Utility class for timing
phpunit/php-token-stream           2.0.2   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    5.7.27  The PHP Unit Testing framework.
phpunit/phpunit-mock-objects       3.4.4   Mock Object library for PHPUnit
pimple/pimple                      v3.0.2  Pimple, a simple Dependency Injection Container
sebastian/code-unit-reverse-lookup 1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator               1.2.4   Provides the functionality to compare PHP values for equality
sebastian/diff                     1.4.3   Diff implementation
sebastian/environment              2.0.0   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 2.0.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state             1.1.1   Snapshotting of global state
sebastian/object-enumerator        2.0.1   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/recursion-context        2.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations      1.0.0   Provides a list of PHP built-in functions that operate on resources
sebastian/version                  2.0.1   Library that helps with managing the version number of Git-hosted PHP projects
symfony/polyfill-ctype             v1.12.0 Symfony polyfill for ctype functions
symfony/yaml                       v4.3.5  Symfony Yaml Component
webmozart/assert                   1.5.0   Assertions to validate method input/output with nice error messages.

From the point of version, i don´t see any wrong here btw. i´m working on Fedora 30 - currently with PHP 7.3.10. kr Tom

tom-lp-at commented 5 years ago

the Debug Output:

jaxon debug output
Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

JAXON CALL (Response Complete, {"debugging":true})

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

DONE [109ms]

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

RECEIVED [status: 200, size: 13 bytes, time: 108ms]:
{"jxnobj":[]}

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

<-- jaxon.request( { jxncls: "Jaxon.App.welcome_ajax", jxnmthd: "index" } , { parameters: [Object] } ); returns "false"

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

SENT [62 bytes]

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

SENDING REQUEST

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

CALLING: 
jxncls: Jaxon.App.welcome_ajax
jxnmthd: index

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

POST: jaxon/process
jxncls=Jaxon.App.welcome_ajax
&jxnmthd=index
&jxnr=1571215140304

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

INITIALIZING REQUEST OBJECT

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

PREPARING REQUEST

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

PROCESSING PARAMETERS [0]

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

INITIALIZING REQUEST

Wed Oct 16 2019 10:39:00 GMT+0200 (Mitteleuropäische Sommerzeit)

--> jaxon.request( { jxncls: "Jaxon.App.welcome_ajax", jxnmthd: "index" } , { parameters: [Object] } );
feuzeu commented 5 years ago

Hi,

Seems like the library is not able to find the invoked Jaxon class. Have you setup the autoloading?

tom-lp-at commented 5 years ago

Dear Feuzeu, before i recocnized that CI-3 has its implementation of autoloading, i put this lines into index.php (=> the old stil ).

/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 * 
 * And away we go...
 */
require_once BASEPATH.'../vendor/autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';

The direction seams to be the right one, but the javascript functions are build up, so i can call in the console the Jaxon.App.welcome_ajax.index() ?!?! So in the initialization he found the *.php-files in the /jaxon/classes directory. But if he likes to call them, they seams to be ignored/not found.... There is the point i am lost :(

The access-log from nginx :

[16/Oct/2019:11:56:55 +0200] "POST /jaxon/process HTTP/1.1" 200 23

no error is logged on the call... the config.php

$config['app'] = array(
    'classes' => array(
        array(
            'directory' => rtrim(APPPATH, '/') . '/jaxon/classes',
            'namespace' => '\\Jaxon\\App',
            // 'separator' => '', // '.' or '_'
            // 'protected.' => array(),
        ),
    ),
);
$config['lib'] = array(
    'core' => array(
        'language' => 'en',
        'encoding' => 'UTF-8',
        'request' => array(
            'uri' => 'jaxon/process',
        ),
        'prefix' => array(
            'class' => '',
        ),
        'debug' => array(
            'on' => true,
            'verbose' => true,
        ),
        'error' => array(
            'handle' => false,
        ),
    ),
    'js' => array(
        'lib' => array(
            // 'uri' => '',
        ),
        'app' => array(
            // 'uri' => '',
            // 'dir' => '',
            'extern' => false,
            'minify' => false,
            'options' => '',
        ),
    ),
);

i added a log_message in the process.php and it will be passed:

INFO - 2019-10-16 12:03:28 --> Config Class Initialized
INFO - 2019-10-16 12:03:28 --> Hooks Class Initialized
DEBUG - 2019-10-16 12:03:28 --> UTF-8 Support Enabled
INFO - 2019-10-16 12:03:28 --> Utf8 Class Initialized
INFO - 2019-10-16 12:03:28 --> URI Class Initialized
INFO - 2019-10-16 12:03:28 --> Router Class Initialized
INFO - 2019-10-16 12:03:28 --> Output Class Initialized
INFO - 2019-10-16 12:03:28 --> Security Class Initialized
DEBUG - 2019-10-16 12:03:28 --> Global POST, GET and COOKIE data sanitized
INFO - 2019-10-16 12:03:28 --> Input Class Initialized
INFO - 2019-10-16 12:03:28 --> Language Class Initialized
INFO - 2019-10-16 12:03:28 --> Loader Class Initialized
INFO - 2019-10-16 12:03:28 --> Controller Class Initialized
DEBUG - 2019-10-16 12:03:28 --> Config file loaded: /home/tom/entwicklung/CI-Test-Jaxon/application/config/jaxon.php
DEBUG - 2019-10-16 12:03:28 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
INFO - 2019-10-16 12:03:28 --> Session: Class initialized using 'files' driver.
INFO - 2019-10-16 12:03:28 --> Process.php constructer ....
INFO - 2019-10-16 12:03:28 --> Jaxon response output is {"jxnobj":[]}
INFO - 2019-10-16 12:03:28 --> Jaxon response manager output is {"jxnobj":[]}

also in the initInstance() BUT this will not be passed !!!

/**
     * Callback for initializing a Jaxon class instance.
     *
     * This function is called anytime a Jaxon class is instanciated.
     *
     * @param object            $instance               The Jaxon class instance
     *
     * @return void
     */
    public function initInstance($instance)
    {
        log_message('info', "Init Jaxon class  " . get_class($instance));
    }

missing initialization ? kr Thomas

feuzeu commented 5 years ago

I don't know how to include Jaxon classes in the CI-3 autoloading config. Try to ask Jaxon to use the composer autoloader.

    public function index()
    {
        ∕∕ Use the composer autoloader
        jaxon()->useComposerAutoloader();

        $this->jaxon->onInit(function ($instance) {
            $this->initInstance($instance);
        });
        $this->jaxon->onBefore(function ($instance, $method, &$bEndRequest) {
            $this->beforeRequest($instance, $method, $bEndRequest);
        });
        $this->jaxon->onAfter(function ($instance, $method) {
            $this->afterRequest($instance, $method);
        });

        // Process the Jaxon request
        if($this->jaxon->canProcessRequest())
        {
            $this->jaxon->processRequest();
            // $this->jaxon->httpResponse();
        }
    }
tom-lp-at commented 5 years ago

it seams to be passed and loaded:

DEBUG - 2019-10-16 13:40:07 --> Config file loaded: /home/tom/entwicklung/CI-Test-Jaxon/application/config/jaxon.php
DEBUG - 2019-10-16 13:40:07 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
INFO - 2019-10-16 13:40:07 --> Session: Class initialized using 'files' driver.
INFO - 2019-10-16 13:40:07 --> Process.php constructer ....
INFO - 2019-10-16 13:40:07 --> in index() of Process.php
INFO - 2019-10-16 13:40:07 --> Jaxon response output is {"jxnobj":[]}
INFO - 2019-10-16 13:40:07 --> Jaxon response manager output is {"jxnobj":[]}

the complete code of Process.php

<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Process extends CI_Controller
{
    /**
     * Load the Jaxon and Session libraries.
     */
    public function __construct()
    {
        parent::__construct();
        // Load the Jaxon library
        $this->load->library('jaxon');
        // Load the session library
        $this->load->library('session');
        log_message("info","Process.php constructer ....");

    }

    /**
     * Callback for initializing a Jaxon class instance.
     *
     * This function is called anytime a Jaxon class is instanciated.
     *
     * @param object            $instance               The Jaxon class instance
     *
     * @return void
     */
    public function initInstance($instance)
    {
    log_message('info', "Init Jaxon class  " . get_class($instance));
    }

    /**
     * Callback before processing a Jaxon request.
     *
     * @param object            $instance               The Jaxon class instance to call
     * @param string            $method                 The Jaxon class method to call
     * @param boolean           $bEndRequest            Whether to end the request or not
     *
     * @return void
     */
    public function beforeRequest($instance, $method, &$bEndRequest)
    {
    log_message('info', "Jaxon class name is " . get_class($instance) . " and method is $method");
    }

    /**
     * Callback after processing a Jaxon request.
     *
     * @param object            $instance               The Jaxon class instance called
     * @param string            $method                 The Jaxon class method called
     *
     * @return void
     */
    public function afterRequest($instance, $method)
    {
        log_message('info', "Jaxon response output is " . jaxon()->getResponse()->getOutput());
        log_message('info', "Jaxon response manager output is " . jaxon()->getResponseManager()->getOutput());
        $xResponseManager = jaxon()->getResponseManager();
        $xResponseManager->clear();
        $xResponseManager->append(jaxon()->getResponse());
    }

    /**
     * Process a Jaxon request.
     *
     * The HTTP response is automatically sent back to the browser
     *
     * @return void
     */
    public function index()
    {
    log_message("info","in index() of Process.php");
    jaxon()->useComposerAutoloader();
    $this->jaxon->onInit(function ($instance) {
             $this->initInstance($instance);
        });
        $this->jaxon->onBefore(function ($instance, $method, &$bEndRequest) {
            $this->beforeRequest($instance, $method, $bEndRequest);
        });
        $this->jaxon->onAfter(function ($instance, $method) {
            $this->afterRequest($instance, $method);
        });

        // Process the Jaxon request
        if($this->jaxon->canProcessRequest())
        {
            $this->jaxon->processRequest();
            // $this->jaxon->httpResponse();
        }
    }
}
tom-lp-at commented 5 years ago

i insert a log_message in "onInit" - but it dosn´t enter it ....

$this->jaxon->onInit(function ($instance) {
    log_message("info","in onInit() of Process.php");
        $this->initInstance($instance);
});
tom-lp-at commented 5 years ago

i don´t know if this is important: onInit will not be passed onBefore will not be passed onAfter will be passed canProcess will be passed

kr Tom

tom-lp-at commented 5 years ago

the Order is : Constructor - Index() - canProcessRequest - on After kr Tom

feuzeu commented 5 years ago

It most likely means Jaxon is not able to create an instance of the invoked class. It is the case if following code returns null in the index() method.

$instance = $this->Jaxon->instance($_POST['jxncls']);

Are you able to instantiate the Jaxon\App\welcome_ajax class in index()?

tom-lp-at commented 5 years ago

not with "Jaxon" but with "jaxon" :

    {
        log_message("info","in index() of Process.php");
        jaxon()->useComposerAutoloader();

        $instance = $this->jaxon->instance($_POST['jxncls']);
        log_message("info","Instance = ".var_export($instance,true));
    ....

the result is NULL - you are right...

so i inserted the creation of a instance

$welcome = new Jaxon\App\welcome_ajax;
        log_message("info","Welcome = ".var_export($welcome,true));

and it comes something back:

INFO - 2019-10-16 15:07:41 --> Welcome = Jaxon\App\welcome_ajax::__set_state(array(
   'response' => NULL,
   'rqFactory' =>
  Jaxon\Sentry\Factory\Request::__set_state(array(
     'instance' => NULL,
  )),
   'pgFactory' =>
  Jaxon\Sentry\Factory\Paginator::__set_state(array(
     'instance' => NULL,
     'nItemsTotal' => 0,
     'nItemsPerPage' => 0,
     'nCurrentPage' => 0,
  )),
   'xJaxonCallable' => NULL,
))

the NULL´s are OK ?

with a uppercase "J" it comes to this error :

<p>Severity: Notice</p>
<p>Message:  Undefined property: Process::$Jaxon</p>
<p>Filename: jaxon/Process.php</p>
<p>Line Number: 77</p>

I double check now the library Jaxon.php:

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

class Jaxon
{
    use \Jaxon\Sentry\Traits\Armada;

    public function __construct()
    {
        // Initialize the Jaxon plugin
        $this->_jaxonSetup();
    }

    /**
     * Set the module specific options for the Jaxon library.
     *
     * @return void
     */
    protected function jaxonSetup()
    {
        // Load Jaxon config settings
        $ci = get_instance();
        $ci->config->load('jaxon', true);
        $libConfig = $ci->config->item('lib', 'jaxon');
        $appConfig = $ci->config->item('app', 'jaxon');

        // Jaxon library settings
        $jaxon = jaxon();
        $sentry = $jaxon->sentry();
        $jaxon->setOptions($libConfig);

        // Jaxon application settings
        $this->appConfig = $jaxon->newConfig();
        $this->appConfig->setOptions($appConfig);

        // Jaxon library default settings
        $isDebug = $ci->config->item('debug');
        $baseUrl = rtrim($ci->config->item('base_url'), '/') ;
        $baseDir = rtrim(FCPATH, '/');
        $sentry->setLibraryOptions(!$isDebug, !$isDebug, $baseUrl . '/jaxon/js', $baseDir . '/jaxon/js');

        // Set the default view namespace
        $sentry->addViewNamespace('default', '', '', 'codeigniter');
        $this->appConfig->setOption('options.views.default', 'default');

        // Add the view renderer
        $sentry->addViewRenderer('codeigniter', function () {
            return new \Jaxon\CI\View();
        });

        // Set the session manager
        $sentry->setSessionManager(function () {
            return new Jaxon\CI\Session();
        });
    }

    /**
     * Set the module specific options for the Jaxon library.
     *
     * This method needs to set at least the Jaxon request URI.
     *
     * @return void
     */
    protected function jaxonCheck()
    {
        // Todo: check the mandatory options
    }

    /**
     * Wrap the Jaxon response into an HTTP response.
     *
     * @param  $code        The HTTP Response code
     *
     * @return HTTP Response
     */
    public function httpResponse($code = '200')
    {
        // Create and return a CodeIgniter HTTP response
        get_instance()->output
            ->set_status_header($code)
            ->set_content_type($this->ajaxResponse()->getContentType(), $this->ajaxResponse()->getCharacterEncoding())
            ->set_output($this->ajaxResponse()->getOutput())
            ->_display();
    }
}

thx for your time and kr Tom

feuzeu commented 5 years ago

Hi, You're right, there's a typo in my previous comment. It's $this->jaxon->instance($_POST['jxncls']);, sorry. The first reason I can see why Jaxon cannot find your classes is they are not located where expected. Check if the Jaxon library is able to export your PHP classes to Js.

tom-lp-at commented 5 years ago

hello, it seams so - i can call in the Javascript-Console the "Jaxon.App.welcome_ajax.index()". All my tests depends on the "knowledge" that this JS-Functions are build and i can call them. But the Functions are not entered/called and the response from the call is empty.... My question is: why the get not called ? The Process.php seams to be passed (except the init ?!). As i understand, the Process.php calls the Jaxon-Classes, isn´t it ? I placed two log_message into Jaxon.php in library:

if (! defined('BASEPATH')) exit('No direct script access allowed');

class Jaxon
{
    use \Jaxon\Sentry\Traits\Armada;

    public function __construct()
    {
        // Initialize the Jaxon plugin
        $this->_jaxonSetup();
    }

    /**
     * Set the module specific options for the Jaxon library.
     *
     * @return void
     */
    protected function jaxonSetup()
    {
        // Load Jaxon config settings
        $ci = get_instance();
        $ci->config->load('jaxon', true);
        $libConfig = $ci->config->item('lib', 'jaxon');
        $appConfig = $ci->config->item('app', 'jaxon');
        log_message("info","JaxonSetup()");

        // Jaxon library settings
        $jaxon = jaxon();
        $sentry = $jaxon->sentry();
        $jaxon->setOptions($libConfig);

        // Jaxon application settings
        $this->appConfig = $jaxon->newConfig();
        $this->appConfig->setOptions($appConfig);

        // Jaxon library default settings
        $isDebug = $ci->config->item('debug');
        $baseUrl = rtrim($ci->config->item('base_url'), '/') ;
        $baseDir = rtrim(FCPATH, '/');
        $sentry->setLibraryOptions(!$isDebug, !$isDebug, $baseUrl . '/jaxon/js', $baseDir . '/jaxon/js');

        // Set the default view namespace
        $sentry->addViewNamespace('default', '', '', 'codeigniter');
        $this->appConfig->setOption('options.views.default', 'default');

        // Add the view renderer
        $sentry->addViewRenderer('codeigniter', function () {
            return new \Jaxon\CI\View();
        });

        // Set the session manager
        $sentry->setSessionManager(function () {
            return new Jaxon\CI\Session();
        });
    }

    /**
     * Set the module specific options for the Jaxon library.
     *
     * This method needs to set at least the Jaxon request URI.
     *
     * @return void
     */
    protected function jaxonCheck()
    {
        // Todo: check the mandatory options
    }

    /**
     * Wrap the Jaxon response into an HTTP response.
     *
     * @param  $code        The HTTP Response code
     *
     * @return HTTP Response
     */
    public function httpResponse($code = '200')
    {
        log_message("info","httpResponse in Jaxon.lib");
        // Create and return a CodeIgniter HTTP response
        get_instance()->output
            ->set_status_header($code)
            ->set_content_type($this->ajaxResponse()->getContentType(), $this->ajaxResponse()->getCharacterEncoding())
            ->set_output($this->ajaxResponse()->getOutput())
            ->_display();
    }
}

and the result is :

DEBUG - 2019-10-17 16:21:02 --> Config file loaded: /home/tom/entwicklung/CI-Test-Jaxon/application/config/jaxon.php
INFO - 2019-10-17 16:21:02 --> JaxonSetup()
DEBUG - 2019-10-17 16:21:02 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
INFO - 2019-10-17 16:21:02 --> Session: Class initialized using 'files' driver.
INFO - 2019-10-17 16:21:02 --> Process.php constructer ....
INFO - 2019-10-17 16:21:02 --> in index() of Process.php
INFO - 2019-10-17 16:21:02 --> Instance = NULL
INFO - 2019-10-17 16:21:02 --> in canProcess() of Process.php
INFO - 2019-10-17 16:21:02 --> in onAfter() of Process.php
INFO - 2019-10-17 16:21:02 --> Jaxon response output is {"jxnobj":[]}
INFO - 2019-10-17 16:21:02 --> Jaxon response manager output is {"jxnobj":[]}

it seams that the function httpResponse in the Library Jaxon.php is not called .... kr Tom

tom-lp-at commented 5 years ago

Hello, regarding your comment "is not located where expected" i log the entrys in jaxonSetup()

INFO - 2019-10-17 16:28:16 --> BaseURL = http://ci-test.linuxprofi.at / BaseDir = /home/tom/entwicklung/CI-Test-Jaxon

I recognised that the Library tells $sentry that the Jaxon-JS-Librarys are stored in '/home/tom/entwicklung/CI-Test-Jaxon/jaxon/js' - but there is no files. In the documentation is written that the jaxon-libraries are taken from a cdn (what is right - i see it in the Javascript-Developer-tools). I placed the jaxon.core.js & jaxon.debug.js in this directory, but it has no effect.... Wrong way ? kr Tom

feuzeu commented 5 years ago

Hi, For example, your welcome_ajax PHP class should be located in the APPPATH/jaxon/classes/ dir, which in this case is /home/tom/entwicklung/CI-Test-Jaxon/application/jaxon/classes/. The corresponding js class should also be declared in the generated js code.

Jaxon = {};
Jaxon.App = {};
Jaxon.App.welcome_ajax = {};
Jaxon.App.welcome_ajax.index = function() {
    return jaxon.request(
        { jxncls: 'Jaxon.App.welcome_ajax', jxnmthd: 'index' },
        { parameters: arguments }
    );
};

The /home/tom/entwicklung/CI-Test-Jaxon/jaxon/js/ dir contains the generated js files.

tom-lp-at commented 5 years ago

Dear Feuzeu, ok - it seams we come closer to the problem. The Directory .../CI-Test-Jaxon/jaxon/js exists and has the right permissions. SeLinux is disabled - no errors in nginx-logs, but : there are no generated files. I checked my running project with jaxon-php-v2.0-beta24 and there are also no generated files.... Could it be that this "feature" of cached JS-Files comes after the V2.0-beta24 ? That could be the point why the project didnt run with newer versions.... :( Could you give me a glue where i can investigate the generation of the JS-Files ? (to be honest - i thought that the JS-Code is only send out with the browsercode, so i don´t miss the generated JS-Files :( ) One further question to understand something more : If the code is not generated, why can i call the function in the JS-Console and have a (empty) jxnobj-response to it ? Are this two different parts ? thx for your time & kr Tom

tom-lp-at commented 5 years ago

Dear Feuzeu, in the transmitted code to the browser, i found the part you mentioned :


/* <![CDATA[ */
try {
    if(typeof jaxon.config == undefined)
        jaxon.config = {};
}
catch(e) {
    jaxon = {};
    jaxon.config = {};
};

jaxon.config.requestURI = "jaxon/process";
jaxon.config.statusMessages = false;
jaxon.config.waitCursor = true;
jaxon.config.version = "Jaxon 2.2.6";
jaxon.config.defaultMode = "asynchronous";
jaxon.config.defaultMethod = "POST";
jaxon.config.responseType = "JSON";
jaxon.debug.verbose.active = true;

jaxon.confirm = {
    skip: function(command) {
        numberOfCommands = command.id;
        while (0 < numberOfCommands) {
            jaxon.tools.queue.pop(command.response);
            --numberOfCommands;
        }
    }
};
/*
    Function: jaxon.confirm.commands

    A rewrite of the jaxon.confirm.commands function which uses the user configured confirm library.

    Parameters:
        command (object) - jaxon response object

    Returns:
        true - The operation completed successfully.
*/
jaxon.confirm.commands = function(command) {
    command.fullName = 'confirmCommands';
    var msg = command.data;
    /*
     * Unlike javascript confirm(), third party confirm() functions are not blocking.
     * Therefore, to prevent the next commands to run while the library is waiting for the user confirmation,
     * the remaining commands are moved to a new queue in the command object.
     * They will be processed in the confirm callbacks.
     * Note that only one confirm command will be allowed in a Jaxon response.
     */
    command.response = jaxon.tools.queue.create(jaxon.config.responseQueueSize);
    while((obj = jaxon.tools.queue.pop(jaxon.response)) != null)
    {
        jaxon.tools.queue.push(command.response, obj);
        delete obj;
    }
    if(confirm(msg)){jaxon.ajax.response.process(command.response);}else{jaxon.confirm.skip(command);jaxon.ajax.response.process(command.response);};
    return true;
};

jaxon.dom.ready(function() {
    jaxon.command.handler.register('cc', jaxon.confirm.commands);

jaxon.command.handler.register("jquery", function(args) {
    jaxon.cmd.script.execute(args);
});});

Jaxon = {};
Jaxon.App = {};
Jaxon.App.welcome_ajax = {};
Jaxon.App.welcome_ajax.index = function() {
    return jaxon.request(
        { jxncls: 'Jaxon.App.welcome_ajax', jxnmthd: 'index' },
        { parameters: arguments }
    );
};

/* ]]> */

so the code is send, but not stored in the /jaxon/js-directory .... kR Tom

feuzeu commented 5 years ago

Hi Tom, I finally found what's going wrong. Since a few versions now, dots and underscores can be used as separators in javascript class names. As an unforeseen drawback of this feature, underscores can no more be used in Jaxon class or directory names. That's the cause of this issue. When processing your request, the Jaxon library looks for the Jaxon\App\welcome\ajax class, instead of Jaxon\App\welcome_ajax.

So you need to rename your classes and remove underscores. Unfortunatelly, there's no simple way for me to fix this issue now.

I should have been able to find this earlier. Sorry.

feuzeu commented 5 years ago

Regarding the generated js code, it is inserted into the HTML code because you have this in your configuration.

    'js' => array(
        'lib' => array(
            // 'uri' => '',
        ),
        'app' => array(
            // 'uri' => '',
            // 'dir' => '',
            'extern' => false,
            'minify' => false,
            'options' => '',
        ),
    ),

Change the extern and minify options to true, and set the dir and uri options with a directory path on your server and the corresponding url. Make sure the directory is writable. The js code will then be exported to a file in this dir, which will then be loaded from the main page.

tom-lp-at commented 5 years ago

Dear Feuzeu, sensationell - with the changing of "welcomeajax.php" to "welcomeajax.php" (the classname in it too). The Response is working !!!! :+1: In the other project's it would be a heavy change to the code to remove all the "" .... Stupid question : Is there a other option to allow the underscore in method-names ? Let´s say every method of my code had a "_" in it :( Of course, i can change to upper-/lowercase names, but there are thousands of method´s :(

kr Thomas

tom-lp-at commented 5 years ago

I searched a little bit around and the issue with "_" seams to be a new one. But, as i understand its for functions and variables that starts with a underscore. I could not find a proposal for functions or variables with a "_" in the name.... Could it be that the method/class names are replaced/use the "_" in the whole string as separator and not only on the starting position ? Could it be a way to replace/use only the starting "_" ? kr Thomas

tom-lp-at commented 5 years ago

I test it with methods with a "_" in the name and they works ! :+1: So the only job will be the change of the Classnames - that should be possible with the usage of KDE´s KFileReplace.... Thank you for your time !!! And last but not least - i love Jaxon-php again :D kr Thomas

tom-lp-at commented 5 years ago

One further question before i close. Is it useful to generate the Jaxon-JS-Files on the filestore ? Bring it some performance benefits or something else ? kr Thomas

feuzeu commented 5 years ago

One further question before i close. Is it useful to generate the Jaxon-JS-Files on the filestore ? Bring it some performance benefits or something else ? kr Thomas

Yes, it has many benefits. Browsers can cache the file allowing pages to load faster, and the library does not parse the classes to generate the js code when the file already exists.

tom-lp-at commented 5 years ago

Thank you again - i give it a try :) best wishes - issue closed....