11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 24 • INTRODUCING THE ZEND FRAMEWORKHowever, because the development section does not assign a value to the email.support directive(which is of my own creation; the Zend Framework supports a large set of predefined directive names, soyou’re free to add your own), the directive as defined within the production section will still be availablewhen the application is running in development mode.Although you won’t need to explicitly retrieve the database configuration parameters (which you’lladd in a moment), you will almost certainly need to retrieve certain parameters such as the support e-mail address from within your controller actions. You can do this by adding the following method to theBootstrap.php file:protected function _initConfig(){$config = new Zend_Config($this->getOptions());Zend_Registry::set('config', $config);return $config;}With this method added, you can then retrieve configuration directives from within any controlleraction like this:$config = Zend_Registry::get('config');$email = $config->email->support;Adding the Database Connection ParametersNow that you understand how the Zend Framework’s configuration management feature works, let’sadd the database connection parameters. Copy the following six parameters into your application.inifile:resources.db.adapter= PDO_MYSQLresources.db.params.host= localhostresources.db.params.username = rootresources.db.params.password = jasonresources.db.params.dbname = gitread_devresources.db.isDefaultTableAdapter = trueAs mentioned previously, the Zend Framework supports multiple databases, including <strong>MySQL</strong>. Theresources.db.adapter directive determines which database you’ll be using, in this case <strong>MySQL</strong> (via<strong>PHP</strong>’s PDO extension). The resources.db.params.host, resources.db.params.username,resources.db.params.password, and resources.db.params.dbname directives should all be selfexplanatory.Finally, the resources.db.isDefaultTableAdapter tells the Zend Framework whether youcan simply begin using the database features without having to first retrieve a database connectionadapter. I recommend setting this directive to true as it will save you a few extra lines of code down theroad.With the contacts table created and the database connection configured, you can implement theContact controller’s add action.Adding ContactsHopefully you’re starting to get the sense that building a web application using the Zend Framework iskind of like using an Erector Set or Legos; you just use the appropriate piece rather than building yourown from scratch. I’ll continue reinforcing that mindset in this section, using the Zend_Form471

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!