Welcome Guest, Not a member yet? Register   Sign In
Class not found Error, problem with namespaces
#2

Because you are doing the helper wrong see below how to do it the helper is loaded in the BaseController.

PHP Code:
<?php namespace App\Controllers;

class 
Test extends BaseController
{

    public function index()
    {
        
        $param 
""//Doesn’t matter here ;
        
        $data
['jqueryobject'] = phpArrayToJqueryPparam($param4"new FWDRAP""FWDRAPUtils.onReady(function(){" );
        
        $data
['base'] = config('App')->baseURL;
        
        
return view('test_message'$data);
    }

    //--------------------------------------------------------------------

}

————
File
app/Helpers/php2jquery_helper.php  (Also tried App/Helpers/php2jquery_helper.php
__________
<?php

if ( ! function_exists('phpArrayToJqueryParam'))
{
    function phpArrayToJqueryParam($param$indent 0$object ""$wrapfunction "")
    {
        $tmp 'this is a test';
        return $tmp;
    }
}

// End of app/Helpers/php2jquery_helper.php

// ------------------------------------------------------------------------

// Start app/Controllers/BaseContoller.php

<?php

namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Services;
use 
Psr\Log\LoggerInterface;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 */

/**
 * Class BaseController
 *
 * @package App\Controllers
 */
class BaseController extends Controller
{
    /**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    protected $helpers = [
        'php2jquery',
    ];

    /**
     * @var \CodeIgniter\Session\Session
     */
    protected $session;

    /**
     * initController ()
     * -------------------------------------------------------------------
     *
     * @param RequestInterface  $request
     * @param ResponseInterface $response
     * @param LoggerInterface   $logger
     */
    public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        //--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();

        // Ensure that the session is started and running
        if (session_status() == PHP_SESSION_NONE)
        {
            $this->session Services::session();
        }

    }

}
   // -------------------------------------------------------------------

/**
 * -----------------------------------------------------------------------
 * Filename: BaseController.php
 * Location: ./app/Controllers/BaseController.php
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: Class not found Error, problem with namespaces - by InsiteFX - 11-30-2020, 10:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB