0

I am working on a project based on Zend 1.12. There is a new requirement in which we have to encode all of our files to prevent hacking. We used ioncube encoder which encode all of the .php file but not application.ini where it store db information username, password, secret key etc. There are two approach :

1) Have configuration reside in .php file such as config.php instead of application.ini

2) have ioncube encode application.ini

With the first approach I found Zend Config Introduction where you could have configuration store in array. I need a concrete example with setup in Bootstrap.php where it could utilize these configuration. Right now all of our model extends from Zend_Db_Table_Abstract. I really want when i migrate all the application.ini db configuration into config.php all the db operation works and there are several instance in front controller make use of $this->applicationOptions. I hope my putting configuration this will work as well. Please help

With second approach I did not found much resolution on ioncube be able to encode application.ini

This is my configuration file

return $configArray = array(

   'db' => array(
       'adapter' => 'pdo_mysql',
       'params'  => array(
           'host'     => 'localhost',
           'username' => 'root',
           'password' => 'root',
           'dbname'   => 'test'
       )
   )
);

When i do this in Bootstrap.php and it work

   $config = new Zend_Config(require APPLICATION_PATH  .'/configs/config.php');
   $db = Zend_Db::factory($config->db->adapter,
                          $config->dv->params->toArray());
   $db = Zend_Db::factory($config->db);        
   Zend_Db_Table::setDefaultAdapter($db);

but when i do

   protected function _initDatabase(){ 
     $config = new Zend_Config(require APPLICATION_PATH  .'/configs/config.php');
     $resource = $this->getPluginResource('db');
     var_dump($this->getPluginResource('db'));  // this will be null. 

My question is is should i do anything different in configuration so it will mimic resources.db.adapter, resources.db.params.host etc and it will be picking up by the pluginResources or getoptions

user332951
  • 359
  • 1
  • 3
  • 18

2 Answers2

2

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.

Basically, you first create a PHP file that contains the configuration :

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

And, then, from another file, use than configuration file :

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

In your Bootstrap.php try getting the configuration like this

protected function _initDb()
{
    $resource = $bootstrap->getPluginResource('db');

    $db = $resource->getDbAdapter();

    Zend_Registry::set("db", $db);
}

After registering the db variable in your Bootstrap.php you can access it like this

$dbAdapter = Zend_Registry::get("db");
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
  • i followed your approach and it seem to work. Well sort of. I did extends my question from the original post. Any help would be greatly appreciated. – user332951 Apr 15 '13 at 18:39
  • The suggested solution does not work. In bootstrap i did this but var_dump on $resource = null. protected function _initDatabase(){ $config = new Zend_Config(require APPLICATION_PATH .'/configs/config.php'); $resource = $this->getPluginResource('db'); var_dump($resource); – user332951 Apr 15 '13 at 22:39
1

You use getPluginResource() hence you need to have your configuration keys in the following way:

resources.db.adapter = ...
resources.db.params.host = ...
...

or your config.php should look like this:

// config.php
return array(
  'resources' => array(
    'db' => array(
       ...
    ),
  ),
  ...
);

This page could be helpful.

mys
  • 2,355
  • 18
  • 21
  • Yep i tried that too but it still does not work. On the page you gave me under example #13 I even mimic the xml configuration by having nested config and production array but still no luck. in bootstrap var_dump of $resource = $this->getPluginResource('db') still null – user332951 Apr 16 '13 at 17:35