Thank you for your reply, but that doesn't solve my problem. For the sake of the example I didn't post the complete helper but it's constructed as a class, not as a bunch of functions. Now if I implement it by including 'php2jquery' in the $helpers I can't call it. like this:
PHP Code:
$data['jqueryparam'] = $royalaudioparam->php_array_to_jquery_param($param,3,"new FWDRAP","FWDRAPUtils.onReady(function(){");
it gives me an Error: "Class 'App/Controllers/php2jquery' not found" So it seeks in the wrong namespace? (I can resolve the namespace by not using it as a helper, but it should be possible as a helper or am I missing something?
this works:
PHP Code:
<?php //BaseController
namespace App\Controllers;
use CodeIgniter\Controller;
class BaseController extends Controller
{
protected $helpers = ['php2jquery'];
// etc
}
?>
<?php //Controllers/Test.php
namespace App\Controllers;
use App\Helpers\php2jquery;
class Test extends BaseController
{
public function index()
{
//Variables should be inited by now.
$royalaudioparam=New php2jquery();
$data['jqueryparam'] = $royalaudioparam->php_array_to_jquery_param($param,3,"new FWDRAP","FWDRAPUtils.onReady(function(){");
//do something
}
}
?>
//
<?php //Helpers/php2jquery.php
namespace App\Helpers;
class php2jquery
{
if ( ! function_exists('phpArrayToJqueryParam')) {
function php_array_to_jquery_param($param,$indent=0, $object="", $wrapfunction=""){
$jquery_param="";
$close="";
if ($indent<3) $indent=3;
$myindent=$this->indent($indent);// Inspringdiepte zetten
// logic removed
return rtrim($jquery_param, ",".$mynewobjectindent).PHP_EOL.$close; //Laatste comma eraf halen en afsluiten
}
}
if ( ! function_exists('indent')) {
function indent($pos=0) {
$myindent="";
for ($times=0; $times<=$pos; ++$times){
//echo "pos=".$times.PHP_EOL;
$myindent .="\t";
}
return $myindent;
}
}
} //class php2jquery
but it should be possible as helper or not?