Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

epwzf20

.pdf
Скачиваний:
6
Добавлен:
21.02.2016
Размер:
2.14 Mб
Скачать

Easy PHP Websites with the Zend Framework

228

 

 

Custom view helpers should extend the Zend_View_Helper_Abstract class. They should be placed in the project's application/views/helpers directory.

Name two reasons why the Zend Framework's URL view helper is preferable over manually creating hyperlinks?

The native URL view helper is convenient because it can dynamically adapt the URL in accordance with any changes made to the website structure. Additionally, URL helpers can refer to a custom route definition rather than explicitly naming a controller or action.

Chapter 4

Which Zend Framework component is primarily responsible for simplifying the accessibility of project configuration data from a central location?

The Zend_Config component is the primary vehicle used for accessing a Zend Framework project's configuration data.

What is the name and location of the default configuration file used to store the configuration data?

Although it's possible to store a Zend Framework project's configuration data using a variety of formats, the default solution involves using an INI-formatted file named application.ini stored in the directory application/configs.

Describe how the configuration data organized such that it is possible to define stage-specific parameters.

The application.ini file is broken into multiple sections, with each section representative of a lifecycle stage. These sections are identified by the headers [production], [staging:production],

[testing:production], and [development:production]. The latter three stages inherit from the production stage, as is indicative by the syntax used to denote the section start.

What is the easiest way to change your application's lifecycle stage setting?

Although the Zend Framework's APPLICATION_ENV can be set in a variety of ways, the most common approach involves setting it in the .htaccess file.

Chapter 5

Name two reasons why the Zend_Form component is preferable to creating and processing forms manually.

Easy PHP Websites with the Zend Framework

229

 

 

Although one could cite dozens of reasons why the Zend_Form component is preferable to creating and processing forms manually, two particularly prominent reasons include the ability to encapsulate a form's components and behavior within a model, and the ease in which form fields can be validated and repopulated.

How does the Flash Messenger feature streamline a user's website interaction?

The Flash Messenger is useful because the developer can create a message which should be presented to the user following the completion of a specific task, such as successfully registering or logging in, and then present this message on a subsequent page, thereby streamlining the number of interactions a user needs to make in order to navigate the website.

What is the role of PHPUnit's data provider feature?

PHPUnit's data provider feature is useful for vetting various facets of a particular website feature by repeatedly executing a test and passing in a different set of test data with each iteration.

Chapter 6

Define object-relational mapping (ORM) and talk about why its an advantageous approach to programmatically interacting with a database.

Object-relational mapping provides a solution for interacting with a database in an object-oriented fashion, thereby reducing and possibly entirely eliminating the need to inconveniently mingle incompatible data structures.

Given a model named Application_Model_DbTable_Game, what will Zend_Db assume to be the name of the associated database table? How can you override this default assumption?

Given a model named Application_Model_DbTable_Game, the Zend_Db component will assume the associated database table is named game. You can override this assumption by defining a protected property named name in your model.

What are the names and purposes of the native Zend_Db methods used to navigate model associations?

The findParentRow() method is used by a child to retrieve information about its parent row. The findDependentRowset() method is used by a parent to retrieve information about its children rows.

Chapter 7

Talk about the advantages Doctrine provides to developers.

Easy PHP Websites with the Zend Framework

230

 

 

Doctrine offers quite a few powerful advantages, including notably a mature object-relational mapper, a database abstraction layer, and a powerful command-line tool. Its possible to identify standard PHP classes as persistent through a simple configuration process, thereby greatly reducing the amount of code a developer would otherwise have to write to implement persistence features.

Talk about the different formats Doctrine supports for creating persistent objects.

Doctrine can marry PHP objects and the underlying database using DocBlock annotations, XML, and YAML. DocBlock annotations are the author's preferred approach, although any of the three will work just fine.

What are DocBlock annotations?

DocBlock annotations allow developers to define a standard PHP class as persistent by embedding metadata within PHP comment blocks. These annotations are used to define the mapping between a class' properties and the associated SQL type, specify primary keys, and define associations.

What is DQL and why is it useful?

The Doctrine Query Language (DQL) is a query language useful for querying and interacting with your project's object model. DQL is useful because it allows the developer to mine data which continuing to think in terms of objects rather than in SQL.

What is QueryBuilder and why is it useful?

The QueryBuilder is an API which provides developers with a means for rigorously constructing a DQL query.

Why is it a good idea to create a custom repository should your query requirements exceed the capabilities provided by Doctrine's magic finders?

Custom repositories provide a convenient way to encapsulate your custom data-access features in a specific location rather than polluting the domain entities.

Chapter 8

Explain how Zend_Auth knows which table and columns should be used when authenticating a user against a database.

The Zend_Auth component includes an adapter named Zend_Auth_Adapter_DbTable which supports methods used to map the adapter to a specific database table, and identify the table

Easy PHP Websites with the Zend Framework

231

 

 

columns used store the account username and password. These methods include setTableName(), setIdentityColumn(), and setCredentialColumn(), respectively.

At a minimum, what are the five features you'll need to implement in order to offer basic user account management capabilities?

The five fundamental account management features include account registration, account login, account logout, password update, and password recovery.

Talk about the important role played by the account table's recovery column within several features described within this chapter.

The account table's recovery column is used for unique identifiers which serve to create a one-time URL. A one-time URL is sent to a newly registered user's e-mail address. When clicked, the unique identifier will be compared against the database in order to confirm the account.

Chapter 9

Why should you link to the jQuery library via Google's content distribution network rather than store a version locally?

Linking to the jQuery library via Google's content distribution network will greatly increase the likelihood that the library is already cached within a user's browser, thereby reducing the amount of bandwidth required to serve your website.

What role does jQuery's $.getJSON method play in creating the Ajax-driven feature discussed earlier in this chapter?

The $.getJSON method is useful for asynchronously communicating with a remote endpoint via an HTTP GET request.

Chapter 10

Why is it a wise idea to use PHP's CLI in conjunction with scripts which could conceivably run for a significant period of time?

When using PHP scripts to execute batch processes, using the command-line interface (CLI) is a wise idea because CLI-based PHP scripts do not take PHP's max_execution_time setting into account. Additionally, CLI-based scripts can be automatically executed using a scheduling daemon such as CRON.

Easy PHP Websites with the Zend Framework

232

 

 

What two significant improvements does the Google Maps API V3 offer over its predecessor?

The Google Maps API V3 offers several improvements over its predecessor, however two of the most notable changes include the removal of the API key requirement and the streamlined syntax which greatly reduces the amount of code otherwise required to implement key features such as map customization and marker display.

Chapter 11

Define unit testing and talk about the advantages it brings to your development process.

Unit testing provides developers with a tool for formally and rigorously determining whether specific parts of an application's source code behave as expected. Using an automated unit testing tool is advantageous because a suite of tests can be created, managed and organized in an efficient manner.

What Zend component and open source PHP project work in conjunction with one another to bring unit testing to your Zend Framework applications?

PHPUnit and the Zend Framework's Zend_Test component work together to bring unit testing features to your Zend Framework projects.

What is the name of the syntactical construct used to validate expected outcomes when doing unit testing?

Expected outcomes are confirmed using assertions.

Why are code coverage reports useful?

Code coverage reports are useful because they provide developers with a valuable tool for determining how many lines of a project have been "touched" by unit tests.

Chapter 12

Provide a few reasons why a tool such as Capistrano is superior to FTP for project deployment tasks.

Capistrano is superior to FTP because Capistrano is faster, more secure, and able to automatically revert a website to its last known good state should a problem occur during the deployment process. Additionally, the developer can manually revert a website to its previous state should he detect a problem following deployment.

Easy PHP Websites with the Zend Framework

233

 

 

Describe in general terms what steps you'll need to take in order to ready your project for deployment using Capistrano.

After installing Capistrano (and optionally Railsless-deploy), and configuring shared-key authentication, you'll want to create a Capfile and a deployment file (which contains the project's deployment configuration settings). Before deploying your project you'll want to ready the deployment server by executing Capistrano's deploy:setup command. Finally, when ready to deploy you'll execute the deploy command.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]