I met last time situation in that I run my application with error: No adapter found for Application_Model_DbTable. What’s wrong? – I thought. And finally I find solution that I perform You.
So, in last post You create database my_animals with only one table animals. You insert in it several animals. Lets create project animals. Choose from Netbeans menu File->New Project.
In Projects Name field write animals and click on Next button.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php echo $this->layout()->content; ?>
Right click on project node and choose Zend->Run Command, that create class file for table animals.
In application/models/DbTable node You see Animals.php with Application_Model_DbTable_Animals class.
$a = new Application_Model_DbTable_Animals();
$this->view->animals = $a->fetchAll();
In this method You run class of animals table and running its method fetchAll which get all records from this table. This records is giving to view of controller as array with animals name. So go to view index. Open in views/scripts/index index.phtml file and paste in it code:
<?php foreach ($this->animals as $animal): ?>
<?php echo $animal['name'] ?><br/>
<?php endforeach; ?>
In public node open .htaccess file and add on top two lines:
SetEnv APPLICATION_ENV development
Then open application.ini file in application/configs node and paste in it code to connect MySQL database:
resources.db.adapter = "pdo_mysql"
resources.db.params.dbname = "my_animals"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "dorota"
resources.db.params.charset = "utf8"
If You paste this code example after [staging : production] section