как мы можем получить доступ к элементам массива в торт php (взамен [элементы]) имя файла app.php - PullRequest
0 голосов
/ 22 сентября 2019

use Cake\Cache\Engine\FileEngine;
use Cake\Database\Connection;
use Cake\Database\Driver\Mysql;
use Cake\Error\ExceptionRenderer;
use Cake\Log\Engine\FileLog;
use Cake\Mailer\Transport\MailTransport;

return [

'App' => [
    'namespace' => 'App',
    'encoding' => env('APP_ENCODING', 'UTF-8'),
    'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
    'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
    'base' => false,
    'dir' => 'src',
    'webroot' => 'webroot',
    'wwwRoot' => WWW_ROOT,
    //'baseUrl' => env('SCRIPT_NAME'),
    'fullBaseUrl' => false,
    'imageBaseUrl' => 'img/',
    'cssBaseUrl' => 'css/',
    'jsBaseUrl' => 'js/',
    'paths' => [
        'plugins' => [ROOT . DS . 'plugins' . DS],
        'templates' => [APP . 'Template' . DS],
        'locales' => [APP . 'Locale' . DS],
    ],
],

]

как можно получить переменные в массиве возврата? это в версии cakephp3.8.Находится в торт / config / app.php

1 Ответ

2 голосов
/ 22 сентября 2019

Предполагая, что это ваш файл конфигурации по умолчанию, прежде всего вам нужно включить следующий файл вверху

use Cake\Core\Configure;

Затем вы можете просто прочитать следующее:

$appArray = Configure::read('App'); //This will return all values inside App as an array. You could print it.

$cssBaseUrl = Configure::read('App.cssBaseUrl'); //You can use dot notification to read the single value inside array.

$plugins = Configure::read('App.paths.plugins'); //You can even read deep level using multiple dots.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...