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

(This post was last modified: 12-01-2019, 09:21 PM by simonickalexs.)

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!

-------

(12-01-2019, 06:38 PM)dave friend Wrote: All the config files are classes where all the properties are public. That means that once you create an instance of a config you can modify the properties however you see fit.

PHP Code:
<?php namespace App\Controllers;

use 
Config;

class 
Home extends BaseController
{
    public function index()
    {
       $viewConfig = new Config\View();
       $viewConfig->saveData false;
       // do stuff
      }


You can dynamically add properties to the class

PHP Code:
$config = new Config\App();
$config->adHoc = ["Hello ""World""!"];
foreach (
$viewConfig->adHoc as $value)
{
    echo $value;  // Hello World!

Reply


Messages In This Thread
RE: Alternative $this->config>set_item($item, $value) - by simonickalexs - 12-01-2019, 09:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB