Welcome Guest, Not a member yet? Register   Sign In
configuration files as array?
#1

I am passing some environment settings to a view template but how do I pass it as an Array to avoid below error?

TypeError
Argument 2 passed to view() must be of the type array, object given





PHP Code:
<?php namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
TestConfig extends BaseConfig
{
    /*
    |--------------------------------------------------------------------------
    | CAPTCHA
    |--------------------------------------------------------------------------
    |
     */
    public $captcha 1


PHP Code:
// Access config class with namespace
$config config'Config\\TestConfig' );

echo 
view('login'$config); 
Reply
#2

(This post was last modified: 10-22-2020, 07:55 AM by T.O.M..)

config('Config\TestConfig') returns instance of Config class. You cannot convert it to array as you want.

You may make your own array variable with needed keys and pass it to view call:
PHP Code:
$config config('Config\TestConfig');

$data = [
   'captcha' => $config->captcha
];

echo 
view('login'$data); 
Reply
#3

use get_object_vars();

echo view('login', get_object_vars($config));
Reply




Theme © iAndrew 2016 - Forum software by © MyBB