Contribution:
zend
Headline
Web programming in Language:PHP with the Technology:Zend framework
Motivation
Language:PHP is one of the most commonly used languages for web programming. To get a more structured and valuable implementation, it is reasonable to choose a PHP based web-application framework. The Technology:Zend framework provides a good infrastructure and a large amount of pre-assembled components and supports form-based web development. The use of PHP suggests an Language:SQL DBMS like Technology:MySQL, to allow persistence. The connection to the DBMS is provided by the database adapter included in the Zend framework.
Illustration
This section is divided into three parts. The first part describes the mapping of the entities, the second part describes the implementation of Feature:Total and Feature:Cut and the third part describes the development of the GUI.
Object-Relational mapping
Feature:Persistence is provided by a Technology:MySQL DBMS (see Contribution:mySqlMany) and the zend adapter for this specific database. The adapter is generated automatically according to the corresponding entries in the file application.ini:
<source lang="php"> resources.db.adapter = "PDO MYSQL" resources.db.params.host = "localhost" resources.db.params.username = "root" resources.db.params.password = "" resources.db.params.dbname = "test" </source>
The entities of the company are mapped by specific classes, which are extended by the class Zend Db Table Abstract. They create simple associative arrays out of the declared tables. If we assume, that associative arrays are objects, we can call this process Object-Relational mapping. To map a table, it is only necessary to specify the name of the designated table within the corresponding class. The class <source lang="php" enclose="none">Application Model DbTable Employee</source> in Employee.php illustrates the mapping of the employee table:
<source lang="php" source="zend/application/models/DbTable/Employee.php"> class Application Model DbTable Employee extends Zend Db Table Abstract { protected $ name = 'employee'; ... } </source>Feature implementation
The features Feature:Total and Feature:Cut are both implemented in the model Employee.php in the sense of MVC. The reason is, that these methods affect only employees, depend on the corresponding company or department. The following example shows the calculation of the Feature:Total value for a company with a given $id.
<source lang="php" source="zend/application/models/DbTable/Employee.php"> class Application Model DbTable Employee extends Zend Db Table Abstract { ... public function getTotalForCompany($id) { // cast the id to integer $id = (int)$id; // get all employees from the database // - with the given company cid // - as an array composed of associative arrays for each employee $rows = $this->fetchAll('cid = ' . $id); $total = 0; // walk through the array and add every salary foreach ($rows as $row) { $total += $row->salary; } return $total; } } </source>GUI
It is possible to create the GUI using a native Language:HTML-Language:PHP web page. The other way is to create simple forms by using the extension
Zend Form
If the controller wants to fill in some data into the total (
$total
populate
total
Architecture
- The entry point for the application is the generated index.php in the this!!zend/public folder. This folder contains the style sheets, too.
- All relevant code for the functionality is located in the this!!zend/application folder.
- The architecture is strictly based on the MVC-pattern. There are different folders for the models (this!!zend/application/models), the views (this!!zend/application/views) and the controllers (this!!zend/application/controllers). This is required, because the framework automatically identifies the classes and its concerns with the help of these namespaces.
- The forms are located in the this!!zend/application/forms folder.
Usage
This project needs a running Technology:MySQL-database. We recommend Technology:XAMPP. It also needs a Web browser. You can use the company.sql and sampleCompany.sql of Contribution:mySqlMany for this project.
- Download and install Technology:XAMPP.
- Open the "XAMPP Control Panel" and start "Apache" and "MySQL".
- Use the guideline of Contribution:mySqlMany up to "Populate tables...".
- Download the sources.
- Copy the complete zend folder to the htdocs-directory of your XAMPP-installation.
- Start your Web browser and go to http://localhost/zend/public/.
There are no revisions for this page.
User contributions
User edits
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.