Welcome Guest, Not a member yet? Register   Sign In
Alternative $this->config>set_item($item, $value)
#4

(12-01-2019, 09:16 PM)simonickalexs Wrote: Thanks for the reply. It seems that it didn't work to push array to my public $item = [...];. Here's my code:

app\config\Packages
PHP Code:
<?php namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Packages extends BaseConfig
{
  public $footer_js = ['nuxt.js''jquery.js''idk.js'];
  // ......


app\Controllers\Test
PHP Code:
<?php namespace App\Controllers;

class 
Test extends BaseController
{
    public function index()
    {
        $ci = new \Config\Packages();

        $ci->footer_js 'vue.js';

        foreach($ci->footer_js as $v)
        {
            echo $v;
            echo '<br/>';
        

The output should show nuxt.js, jquery.js, idk.js, and vue.js. But instead, it just show only vue.js. 

In real case, I really want to dynamically add Javascript files to footer page. I have this helper works on CI3, but I'm still confused how can I make it work on CI4-rc. Thank you!

At this point you have discovered the error, but I only make the comment for those of us who come to this post for one reason or another and we do not see a conclusion.

Obviously the error is that you are replacing the Scripts array with a single value, instead you can use array_push

PHP Code:
$ci = new \Config\Packages();
array_push($ci->footer_js'vue.js'); 
Reply


Messages In This Thread
RE: Alternative $this->config>set_item($item, $value) - by freddy.cruze - 02-02-2021, 09:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB