. Ini veya. Xml config kullanılarak nasıl önlenir (Zend Framework> Zend_Config)?

3 Cevap php

Her sayfa yükleme config.ini ya. Xml dosyasını ayrıştırma neden çünkü. Ini veya. Xml dosyasını kullanarak yüksek trafik projeleri ile iyi bir fikir olduğunu sanmıyorum.

Is there any way to replace using .ini/.xml with regular php array as config? Now php ini looks like that...

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "Europe/London"
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = rob
resources.db.params.password = 123456
resources.db.params.dbname = zf-tutorial
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view.doctype = "XHTML1_STRICT"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Ben böyle bir şey istiyorum ...

<?php

$config = array(
    'production' => array(
        ['phpSettings.display_startup_errors'] => 0,
        ['phpSettings.display_errors'] => 0,
    ),
);

Bu mümkün mü? Ben ne yapmalıyım ve nasıl benim kendi config.php kullanmak için uygulamayı söylemeliyim?

Benim İngilizce için teşekkür ve özür ederiz.

UPD: Ben Zend_Application kurucusuna dizisi geçirerek doğru bir yolu olduğunu düşünüyorum?

3 Cevap

Evet, bir Zend_Config nesnesi için veri başlatmak için bir dizi kullanabilirsiniz; bakmak this page of the Zend Framework manual (quoting what's arround Example #1) :

Normally it is expected that users would use one of the adapter classes such as Zend_Config_Ini or Zend_Config_Xml, but if configuration data are available in a PHP array, one may simply pass the data to the Zend_Config constructor in order to utilize a simple object-oriented interface


You should also take a look at Example #2 on the same page (quoting what's arround it) :

It is often desirable to use a pure PHP-based configuration file. The following code illustrates how easily this can be accomplished

Temelde, ilk yapılandırmasını içeren bir PHP dosyası oluşturun:

// config.php
return array(
  ...
  ...
);

Ve sonra, başka bir dosyadan, yapılandırma dosyasına daha kullanmak:

$config = new Zend_Config(require 'config.php');


But note that doing that, you'll lose the ability to easily modify the configuration, writing it back to the .ini file -- which, depending on your situation, might eventually (or not) be a problem.

Kullanılabilecek bir çözeltisi Zend_Config verileri önbelleğe için:

  • .ini dosyadan oku
  • Bazı önbelleğe alma mekanizmasından Mağaza
  • Ve, sonraki sayfalar için, yerine .ini dosyası yeniden ayrıştırma, önbellekten yükleyin.

Daha iyi bir yöntem ayrıştırma php.ini sonucunu önbelleğe olacaktır. Ama bu aslında herhangi bir soruna neden olacak sanmıyorum.

Bu en azından, APC veya bir opcode önbellek ile önbelleğe en iyisidir, Zend_Config ile işleme. Ini yapılandırma dosyası ToArray () kullanırken özellikle çok işlemci kapsamlıdır.