zend 模块特定 ini 与 phpSettings.display_errors

发布于 2024-11-06 08:59:23 字数 616 浏览 2 评论 0原文

一直在尝试覆盖我的 application/modules/module5/config/module.ini 中的 phpSettings.display_errors 。

我的 module5/Bootstrap.php 已

protected function _initModuleConfig()
{
    $iniOptions = new Zend_Config_Ini(dirname(__FILE__) . '/configs/module.ini');
    $this->getApplication()->setOptions($iniOptions->toArray());
}

正确解析文件,但 application.ini 中给出的 phpSettings 正在加载,而 module.ini 中给出的 phpSettings 则被忽略。

在我的应用程序/Bootstrap 上,我可以正确获取 $this->getAPplication() 。 php设置生效。当我在 application/modules/module5/Bootstrap.php 上时,我丢失了应用程序对象, getApplication() 返回 Bootstrap 而什么都不做,php 设置不会被激活。

Been trying to override the phpSettings.display_errors from my application/modules/module5/config/module.ini.

My module5/Bootstrap.php has

protected function _initModuleConfig()
{
    $iniOptions = new Zend_Config_Ini(dirname(__FILE__) . '/configs/module.ini');
    $this->getApplication()->setOptions($iniOptions->toArray());
}

so the file is parsing properly but the the phpSettings given in application.ini are getting loaded while those given in module.ini are getting ignored.

While on my application/Bootstrap I can get $this->getAPplication() properly. php settings take effect. while Im on application/modules/module5/Bootstrap.php I loose the application object, getApplication() returns Bootstrap while does nothing, php settings don't get activated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女七分熟 2024-11-13 08:59:23

查看文件系统,您的模块不应该.ini 文件位于模块的配置文件夹中,并称为 application.ini 吗?

Looking at the filesystem, shouldn't your module.ini file be in a config folder in your module and be called application.ini instead?

南城旧梦 2024-11-13 08:59:23

嗯,我对应用程序了解不多,但在我看来,它作为一个 Bootstrap 对象并没有什么问题。看看我的转储,似乎 Zend_Application 实际上与它相关联。它似乎也有您正在寻找的详细信息:

object(Bootstrap)[3]
  protected '_appNamespace' => string '' (length=0)
  protected '_resourceLoader' => 
    object(Zend_Application_Module_Autoloader)[7]
  protected '_application' => 
    object(Zend_Application)[1]
  protected '_classResources' => 
  protected '_container' => 
    object(Zend_Registry)[15]
  protected '_environment' => null
  protected '_optionKeys' => 
    array
  protected '_options' => 
    array
      'phpSettings' => 
        array
          'display_startup_errors' => string '1' (length=1)
          'display_errors' => string '1' (length=1)
          'date' => 
            array
              ...
      'bootstrap' => 
        array
          'path' => string 'C:\sites\mysite\application/Bootstrap.php' (length=39)
          'class' => string 'Bootstrap' (length=9)
      'resources' => 
        array
          'frontController' => 
            array
              ...
          'modules' => 
            array
              ...
          'layout' => 
            array
              ...
          'view' => 
            array
              ...
          'session' => 
            array
              ...
          'log' => 
            array
              ...
          'doctrine' => 
            array
              ...
      'appnamespace' => string '' (length=0)
      'autoloadernamespaces' => 
  protected '_pluginLoader' => 
    object(Zend_Loader_PluginLoader)[35]

我实际上不明白为什么您有问题,您将不得不给我们一些转储。

当我尝试它时它起作用了:

<?php

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initApp()
    {
        $app = $this->getApplication();
        echo '1:';
            // die(var_dump($app->getOptions()));
        var_dump($app->getOption('phpSettings'));
        $app->setOptions(array('phpSettings'=>array('date'=>array('timezone'=>'America/New York'))));
        echo '2:';
        var_dump($app->getOption('phpSettings'));
    }
}

这是在我的布局中:

<?php
echo 'in layout';
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
var_dump($bootstrap->getOptions());
?>

这是我的输出:

1:

array
  'display_startup_errors' => string '1' (length=1)
  'display_errors' => string '1' (length=1)
  'date' => 
    array
      'timezone' => string 'Africa/Johannesburg' (length=19)

2:

array
  'display_startup_errors' => string '1' (length=1)
  'display_errors' => string '1' (length=1)
  'date' => 
    array
      'timezone' => string 'America/New York' (length=16)

in layout

array
  'phpSettings' => 
    array
      'display_startup_errors' => string '1' (length=1)
      'display_errors' => string '1' (length=1)
      'date' => 
        array
          'timezone' => string 'America/New York' (length=16)

对我来说效果很好。

Meh, I don't know much about application, but there's nothing wrong with it being a Bootstrap object in my opinion. Looking at my dump it seems the Zend_Application is actually associated with it. It also seem to have the details you are looking for:

object(Bootstrap)[3]
  protected '_appNamespace' => string '' (length=0)
  protected '_resourceLoader' => 
    object(Zend_Application_Module_Autoloader)[7]
  protected '_application' => 
    object(Zend_Application)[1]
  protected '_classResources' => 
  protected '_container' => 
    object(Zend_Registry)[15]
  protected '_environment' => null
  protected '_optionKeys' => 
    array
  protected '_options' => 
    array
      'phpSettings' => 
        array
          'display_startup_errors' => string '1' (length=1)
          'display_errors' => string '1' (length=1)
          'date' => 
            array
              ...
      'bootstrap' => 
        array
          'path' => string 'C:\sites\mysite\application/Bootstrap.php' (length=39)
          'class' => string 'Bootstrap' (length=9)
      'resources' => 
        array
          'frontController' => 
            array
              ...
          'modules' => 
            array
              ...
          'layout' => 
            array
              ...
          'view' => 
            array
              ...
          'session' => 
            array
              ...
          'log' => 
            array
              ...
          'doctrine' => 
            array
              ...
      'appnamespace' => string '' (length=0)
      'autoloadernamespaces' => 
  protected '_pluginLoader' => 
    object(Zend_Loader_PluginLoader)[35]

I actually don't get why you have a problem, you are going to have to give us some dumps.

It works when I try it:

<?php

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initApp()
    {
        $app = $this->getApplication();
        echo '1:';
            // die(var_dump($app->getOptions()));
        var_dump($app->getOption('phpSettings'));
        $app->setOptions(array('phpSettings'=>array('date'=>array('timezone'=>'America/New York'))));
        echo '2:';
        var_dump($app->getOption('phpSettings'));
    }
}

This is in my layout:

<?php
echo 'in layout';
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
var_dump($bootstrap->getOptions());
?>

This is my output:

1:

array
  'display_startup_errors' => string '1' (length=1)
  'display_errors' => string '1' (length=1)
  'date' => 
    array
      'timezone' => string 'Africa/Johannesburg' (length=19)

2:

array
  'display_startup_errors' => string '1' (length=1)
  'display_errors' => string '1' (length=1)
  'date' => 
    array
      'timezone' => string 'America/New York' (length=16)

in layout

array
  'phpSettings' => 
    array
      'display_startup_errors' => string '1' (length=1)
      'display_errors' => string '1' (length=1)
      'date' => 
        array
          'timezone' => string 'America/New York' (length=16)

Works fine for me.

仅冇旳回忆 2024-11-13 08:59:23

假设您真正关心的是打开/关闭 php display_error 设置,您可能只想这样做:

$iniOptions = new Zend_Config_Ini(dirname(__FILE__) . '/configs/module.ini');
$iniOptions = $iniOptions->toArray();
ini_set ('display_errors',$iniOptions['display_errors']));

因此,如果这对您不起作用,请从该命名的额外 ini 文件中删除 display_errors 设置中的所有行并在上述代码后添加以下行,然后在此处发布结果。

var_dump($iniOptions);
echo'<hr>';
var_dump(ini_get('display_errors'));
die();

Assuming the thing you really care for is switching on/off the php display_error setting, you might just want to do this:

$iniOptions = new Zend_Config_Ini(dirname(__FILE__) . '/configs/module.ini');
$iniOptions = $iniOptions->toArray();
ini_set ('display_errors',$iniOptions['display_errors']));

So if this doesn't work for you, delete all lines appart from your display_errors setting from that named, extra ini file and add the following lines after the code mentioned above and post the result here.

var_dump($iniOptions);
echo'<hr>';
var_dump(ini_get('display_errors'));
die();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文