Database application in Zend Framework 1.12.3 in Netbeans 7.4 get data from several relational tables.

In last post You create Zend project: magazine. Lets open in Your project application.ini file( application/configs folder). In production part paste this code:

resources.db.adapter = "pdo_mysql"
resources.db.params.dbname = "magazine"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "dorota"
resources.db.params.charset = "utf8"

Save this file. Here create layout for Your website.
Right click on project node magazine and select from pop-up menu Zend->Run Command.

In Filter field write enable layout and click on Run button.
Open file: application/layouts/scripts/layout.phtml and paste in it code:




News


News




In this time You may create another action for index controller. You have only index action.
Add authors action.
Right click on magazine node and choose from pop-up menu Zend->Run Command. In Filter field write create action and in Parameters field write authors index.
Click on Run button.
In application/controllers/IndexController.php You see new method authorsAction.
And in application/views/scripts/index You see authors.phtml file as view for index controller.

Then You create 3 clasess for 3 tables from database: author, article, news.

Open Run Command Zend windows and in Filter field write:
create db-table
and in Parameters:
Author author
and click on Run button.
In the same way write command:
create db-table
Article article
and
create db-table
News news

In node models/DbTable You see new php files for tables.
For table author in node models/DbTable create Author folder. In it You create Row.php file.
For table article in node models/DbTable create Article folder.
So right click on DbTable node and choose New->Folder.

In New Folder window write in Folder Name: Author and click on Finish button.

Right click on Author folder and choose New->PHP Class.
In New PHP Class window write in File Name field Row and click on Finish button.
In Row.php in author catalogue paste this code:





    


Save this file.
Method findManyToManyRowset references to indirect table news and another related table with its key in this table news.
In next step in authors.phtml file paste this code:

Authors






    


And save this file.
In application.ini file ( application/configs node) write route for url for actions.

resources.router.routes.articles.route = "/index/index"
resources.router.routes.articles.defaultController = "index"
resources.router.routes.articles.defaultAction = "index"

resources.router.routes.authors.route = "/index/authors"
resources.router.routes.authors.defaultController = "index"
resources.router.routes.authors.defaultAction = "authors"

First 3 lines are for index action index controller. It’s name is articles.
Second 3 lines are for authors action index controller. It’s name is authors.

In layout.phtml file add code with links for authors and articles websites.