CakeFest 2024: The Official CakePHP Conference

Yaconf::get

(PECL yaconf >= 1.0.0)

Yaconf::getRecuperar un elemento

Descripción

public static Yaconf::get(string $name, mixed $default_value = NULL): mixed

Parámetros

name

Clave de configuración, la clave se ve como "filename.key", o "filename.sectionName,key".

default_value

si la clave no existe, Yaconf::get devolverá esto como resultado.

Valores devueltos

Devuelve el resultado de configuración (string o array) si la clave existe, devuelve default_value si no.

Ejemplos

Ejemplo #1 Ejemplo de INI()

;filenmame foo.ini, colocado en el directorio que es yaconf.directoy
[SectionA]
;key value pair
key=val
;hash[a]=val
hash.a=val
;arr[0]=val
arr.0=val
;or
arr[]=val

;SectionB hereda SectionA
[SectionB:SectionA]
;reemplazar la clave de configuración en SectionA
key=new_val

El resultado del ejemplo sería algo similar a:

php7 -r 'var_dump(Yaconf::get("foo.SectionA.key"));'
//string(3) "val"

php7 -r 'var_dump(Yaconf::get("foo.SectionB.key"));'
//string(7) "new_val"

php7 -r 'var_dump(Yaconf::get("foo")["SectionA"]["hash"]);'
//array(1)
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top