Abstract Data Structures
Abstract data structures look at content in a different way. In an abstract system, content is content. The database's primary responsibility is to store and serve this content, not to make sense of it. This is solely the application's job. Let's consider a common example to illustrate how this works. Say your CMS has two modules, one that manages news and one that manages events. On the front end of your site, news articles and events are unique items with unique properties. The key here is to...
Search for Group Photos
Flickr offers a wide variety of photo support and user participation. Users can comment on each other's photos, so it comes as no suprise that Flickr has allowed users to join together into groups that share the same interests. If you're a fan of crazy costumed fans at KISS concerts, you can find others who share their recent Gene Simmons and gang photos on Flickr. Let's see how you can view it by using the Zend_Service_Flickr component. You need the group ID, which you find by doing a search...
Creating a Server
Two main classses, Zend_Rest_Client and Zend_Rest_Server, make up the Zend_Rest component. These classes provide the option to either create a REST client or a server that accepts REST requests. Before you dive into the client and call web services, you'll create your own server, which you'll later use to test the REST client implementations. Looking under the hood, the Zend_Rest_Server class allows you to specify either a method or a complete class that contains the code to process requests....
Creating Textarea Fields
Let's create a textarea, a widely used form element that allows developers to create an input field in which the user has ample amount of space to type in any number of characters. This is a great field if you want the user to type in large amounts of data, such as a personal biography or a short story. To add the element to the form, you use the Zend_Form_Element_TextArea class. Let's use the new Zend_Form_Element_TextArea class to create the update form. The new action will create the update...
Creating the Base Class
Create a new class in this file named CMS_Content_Item_Abstract. Since this class wraps a standard page, you need to add properties for each of the pages table's columns to it. Make all the fields except namespace public. The namespace field will be set on an item level and should be protected so only child classes can change it. Also, add a protected property for the Page model, which will be loaded in the constructor, so it needs to get loaded only once. Once you set these up, add the...
Rendering the Most Recent Pages
To get started, create a new method in the Page model to fetch the most recently created pages. This method will need to fetch the pages in the order that they were created. It then needs to cycle through these pages, opening each one. Finally, it should return these pages as an array that you can pass to the view Listing 6-17 . Listing6-17. ThegetRecentPages Method in application models Page.php public function getRecentPages count 10, namespace 'page' select- gt order 'date_created DESC'...
Integrating ZendTranslate with Your Project
There are many ways to integrate Zend_Translate with your project, but I prefer to create application resources for any kind of generalized configuration like this. This enables you to reuse the resource in any ZF project you work on. To get started, create a new folder in the application folder named lang. Then create two files in this folder source-en.csv and source-es.csv. Note It is not technically necessary to create a language file for your default language. If the translate helper does...
Request Object
Going back to the MVC life cycle, after the controller finishes processing with no errors, it initializes the user interface UI that the user will see, otherwise known as the view. Because the view is a critical component for the controller, the controller automatically creates three objects for immediate use The Request object is covered in this section you'll look at the ViewRenderer and the Response object in Chapter 4 . The Request object handles all incoming user data or any data sent from...
Using REST web services with ZendRest 1
At the start of this chapter, we mentioned that the various Zend Framework components we'd be working with would include XML but that we wouldn't be needing to deal with it directly. The Zend_Rest section of the manual opens by stating that REST Web Services use service-specific XML formats, which is true, but it needs a little clarification because REST web services don't care whether or not they use XML. Zend_ Rest does use XML as its format of choice, but it's possible to circumvent this if...
Using Item Elements
Channel element information is only half of what Zend_Feed can parse. The second main section of an RSS document are the items syndicated articles contained in the document. Table 7-18 shows the full list of tags the Zend_Feed component supports when parsing the document's data. Using the table, you'll expand on the section's example and parse the two articles contained in the rssexample.xml RSS feed. Table 7-18. Zend_Feed_RSS Supported Item Tags Element Method Call Return Type M-Array elements...
Creating an FTPSSH Connection
This procedure describes how you can configure an FTP or SFTP connection in Zend Studio. To create an FTP SSH Connection 1. Open the Remote Systems Perspective by going to Window Open Perspective Other Remote Systems Explorer. 2. Open the Remote Systems view by going to Window Show View Other Remote Systems Remote Systems Remote Systems. 3. Click the 'Define a connection to remote system' button on the view's toolbar. 4. The New Connection dialog will appear. 5. Select 'FTP Only' for an FTP...
add a Path Map to a server
Open the PHP Servers Preferences Page by going to Window Preferences on the Menu Bar and selecting PHP PHP Servers from the Preferences list. Select the server on which you would like to create the Path Map and click Edit. In the Edit Server dialog, select the Path Mapping tab. Click Add. An Add new Path Mapping dialog appears. Enter the Server Path from which you would like to create the Path Map. Files called from this location will be searched for in the path specified below. Select either...
Updating the Bug Record
Now you need to create a method in the Bug model to update an existing record. It will be virtually identical to the createBug method except that you are going to pass the method an ID the primary key , and it is going to find the row to update rather than creating a new one see Listing 4-30 . Listing4-30. The updateBug Method in application models Bug.php public function updateBug id, name, email, date, url, description, priority, status find the row that matches the id row this- gt find id -...
XPath Queries 1
One of the most powerful parts of the DOM extension, is its integration with XPath in fact, DomXpath is far more powerful than the SimpleXML equivalent dom new DomDocument dom- gt load libra ry.xml result foreach result as book echo book- gt data This example seems quite complex, but in actuality it shows just how flexible the DOM XPath functionality can be. First, we instantiate a DomXpath object, passing in our DomDocument object so that the former will know what to work on. Next, we register...
Adding User Registration to the Application
Implementing a user registration system is a fairly involved process, not only because there's a lot to do in setting up a user account, but also because it's the first real interaction between the web application and the end-user that we've looked at in this book. The process of accepting user registrations will involve the following Adding navigation so the user can find the registration form Displaying the registration form to the user, including a CAPTCHA image Accepting and validating the...
Adding images to the page
Adding images to your PDF document starts by loading your image file, which must be in TIFF, PNG, or JPEG format, passing its full path to the Zend_Pdf_Image image-WithPath method, then adding it to the page like so image page- gt drawImage image, x1, y1, x2, y2 The x and y values here are the same as you'd use for drawing a rectangle. Your image will be stretched to fit the specified size if it isn't the same as, or proportional to, the original image size. If you need to load alternative...
Launches button to remove any terminated debug sessions from the list During
Debug View - Here you can control stop, pause, and resume the debugging process. You can also decide whether to step into, step over or step return step out off certain functions. Variables - Will display the various variables in your script. Breakpoints - Will display the breakpoints you have entered Parameter Stack - Will display the parameters through which functions are reached. Editor Window - Will display the code at the relevant sections, according to which line is selected in the Debug...
Outputting FlashMessenger Messages on the Web Site
Finally, we must output any existing messages to the template. In order for messages to be displayed regardless of where the user is in the site in other words, so we can use it in other areas aside from managing blog posts , we add the display code to the footer.tpl template, because we will be displaying messages in the right column. Just like the error containers we created for form errors, we will reuse this message container for similar messages we generate from Ajax requests. To achieve...
C Case sensitivity
Zend Framework's router and dispatcher are sensitive to the case of action and controller names. This is for a very good reason PHP's function and method names aren't case sensitive, but filenames generally are. This means that there are rules when using capital letters or other word separators as controller names to ensure that the correct class files can be found. For action names, it's important that the correct view script can be found. The following subsections outline the rules for...
find and replace a string
From within the file, press Crtl F or from the Menu Bar go to Edit Find Replace. A find and replace dialog will appear. P ase S-ensiitve I- Wrap iaioh r r ncrcmertjl P ase S-ensiitve I- Wrap iaioh r r ncrcmertjl 3. Enter the required string to find. 4. Enter the required string to replace it. 5. If necessary, configure the settings under the direction, scope and options category. The found string will be replaced by the new string.
To add the Web server certificate to the JVM
1. Open Internet Explorer and enter your Zend Platform URL. An error message is displayed. C Certificate Error Navigtjton 8lsd d WtndPm Inlemel E ptor r A r-. Caudate Lri lt x H ,-,tf .t r-.tt-s -ed There is a probJem with this website's security certificate, The security certificate presented by this website was not Issued by a trusted certificate authority, The security certificate presented by this website has expire or is not yet valid, The security certificate presented by this website...
Setting Up Dojo Integration in Zend Framework Projects
The Dojo library can also be added to Zend Framework projects through the New Zend Framework Project wizard. When creating a Zend Framework project, mark the 'Enable Dojo Support' checkbox in the Dojo Support category. This will create a link to the external Dojo toolkit library, allowing for Dojo development functionality. This option will only be available if Zend Framework version 1.6 was selected. Figure 103 - New Zend Framework Project - Dojo Support In addition, you can select to import...
The Factory Pattern
The Factory pattern is used in scenarios where you have a generic class the factory that provides the facilities for creating instances of one or more separate specialized classes that handle the same task in different ways. A good situation in which the Factory pattern provides an excellent solution is the management of multiple storage mechanisms for a given task. For example, consider configuration storage, which could be provided by data stores like INI files, databases or XML files...
To install phpMyAdmin after the installation process on LinuxUnixMac
2. In the Zend Core installation package directory, run the command Install -g for a GUI based installation or Install -y for a text-based installation and follow the on-screen instructions. 3. In the screen asking which components you would like to install, ensure you select phpMyAdmin. 4. Continue the installation until the installation process has completed. phpMyAdmin will be installed and the MySQL Tab will be available the next time Zend Core is run.
To use Mark Occurrences
Stand on a variable, method or type in your file. 27 function substitute text,word,replacement var temp text 3 1 perform string replacement using substring. 3 3 while temp.indexOf word gt 0 3 4 temp temp.substr 0,temp.indexOf word replacement 35 All instances where the element is referenced within the file will be highlighted. To configure Mark Occurrences settings 1. To toggle mark occurrences, click the Toggle Mark Occurrences button L J on the toolbar -or- press Alt Shift O. 2. To configure...
Listing B Using iteration with Zend Db Table Rowset
class Users extends Zend_Db_Table users new Users userRowset users- gt fetchAll lt foreach userRowset as user lt echo user- gt name . n Defines gateway class to Users database table As we'd expect, using a rowset is as easy as using an array. This is possible because Zend_Db_Table_Rowset_Abstract implements the Iterator SPL interface, as shown in listing B.12.
Lazy Loading
Prior to PHP 5, instantiating an undefined class, or using one of its methods in a static way would cause a fatal error. This meant that you needed to include all of the class files that you might need, rather than loading them as they were needed just so that you wouldn't forget one or come up with complicated file inclusion mechanisms to reduce the needless processing of external files. To solve this problem, PHP 5 features an autoload facility that makes it possible to implement lazy...
Step Creating the GameNomad Contact Form
The contact form provides your user with a simple way to contact you, while ensuring they provide all of the information you require to ensure a timely and accurate response. For instance, if you were building a website which managed magazine subscriptions, you might want users to include the subscription number found on the magazine label when contacting you for support. A contact form can force the user to include this, thereby saving the hassle of your support team to otherwise ask for it if...
add an external source folder to the projects Build Path
In the Build Path Properties page, click the 'Link Source ' button. -Or- In PHP Explorer view, right-click the project and select Build Path Link Source. The Link Source dialog is displayed. 2. Click the 'Browse ' button and browse to the location of the folder you want to add to the Build Path. Alternately, click Variables and select the variable which points to the required resource. 3. The Folder name field will have been automatically populated with the name of the original folder. 4....
CrossSite Request Forgeries
A cross-site request forgery CSRF is an attack that attempts to cause a victim to unknowingly send arbitrary HTTP requests, usually to URLs requiring privileged access and using the existing session of the victim to determine access. The HTTP request then causes the victim to execute a particular action based on his or her level of privilege, such as making a purchase or modifying or removing information. Whereas an XSS attack exploits the user's trust in an application, a forged request...
Viewing Type Hierarchies
Type hierarchies can be viewed in either a Quick Type Hierarchy view or in the Type Hierarchy view. Viewing Types in the Quick Type Hierarchy View To view a type in a Quick Type Hierarchy view 1. Select the type name in the PHP editor, or PHP Explorer or outline views. -Or- from the Menu Bar go to Navigate Quick Type Hierarchy. The Quick Type Hierarchy view will be displayed in the editor with the selected type. public runction 3engender igieridec j p ub 11 c f U nc 11 o n trctOcndt c tiass...
Export Submenu
The Export submenu is available under File Export from the Menu Bar. The options available under the Export submenu are The options available under the Export submenu are Archive File - Exports files from the Workbench to an archive file in the local file system. File System - Export files from your workspace to your local file system. Preferences - Export preferences from the Workbench. In the Export Preferences wizard, select the preferences to export and the location of the preferences .epf...
To create a new scheme
1. Open the Colors amp Fonts tab in Preferences Tools Preferences Colors amp Fonts. 3. Customize the appearance by navigating through the tabs and defining appearance preferences. 4. Select Save As and enter the new scheme's name into the Scheme Name field. The customization options are as follows The customization options are as follows Define the general appearance of elements in the editor window. Customize PHP colors and appearance. Customize HTML colors and appearance. Customize Java...
Zend License Manager
The Zend License Manager enables ISVs to manage the commercial distribution of their PHP applications by generating license keys and creating files that require a license key to operate. Software vendors can easily specify license models without changing their application's source code. Licensing PHP applications enables software vendors to dramatically penetrate their available market, enhance customer loyalty and account penetration, resulting in increased revenue and profitability. The Zend...
Designing a Database That Can Grow with Your System
The preceding example demonstrated that data can be standardized but did not allow for the fact that not all forms of data can fit into this standard structure. Say, for example, that you needed to add a location to the CMS events. Many news articles could use this field, but many would not. In a simple example like this, the problem may not have any practical impact the articles that don't have a location could simply ignore this field. In a more complex, real-world example, this issue can...
Working with CMS Data
Your job as a CMS developer is to make managing and publishing information as easy as possible. This challenge is compounded by the fact that the information can take many forms on the Web. There are as many solutions to this problem as there are CMSs, each with its own pros and cons. One of the real benefits of developing with a framework like Zend Framework is that you don't have to worry about much of the low-level application logic. The framework provides a standardized API, which you can...
LoudBitecom
Sign Up View All Artists Add Artists My Store Add to Favorite List Figure 4-2. Adding a favorite artist You need a way to process the data the user submits using the add artist page. Create an additional action, saveArtistAction , in the ArtistController.php file, as shown in Listing 4-4. Listing 4-4. ArtistController.php New Additions Save the Artist entered by the user. artistName genre rating isFav The new action, saveArtistAction , is invoked after the user has submitted the form rendered...
Translating with ZendTranslate
As we've already seen, website translation requires, at a minimum, ensuring that every string that is displayed has a translated version. The most common way to do this is with gettext , which is powerful but fairly complicated. Zend_Translate supports the gettext format but also supports other popular formats such as arrays, CSV, TBX, Qt, XLIFF, and XmlTm. Zend_Translate is also thread-safe, which can be very helpful if you're running a multithreaded web server, such as IIS. Zend_Translate...
To create a new PHP project
1. From the menu bar, go to File New PHP Project -Or- In PHP Explorer view, right-click and select New PHP Project. The New PHP Project wizard is displayed. Project name - The required project name Contents - Select whether to Create a new project in the workspace - Creates a new PHP project in the workspace directory. By default a workspace will have been created in when you first launched Zend Studio. Create a project from existing source - Creates a PHP project pointing to files situatued...
Installing PDO
Out of the box, Zend Framework's database support works, but it requires an additional piece to function properly when using it with PHP's PDO. What's PDO, how do you get it, and how can you install it PDO, which stands for PHP Data Object, is an extension that requires and is included with all PHP 5 installations. PDO allows a PHP developer using different relational database management systems RDBMSs to access data in a universal way. If the system used MySQL without the PDO extension, you...
Updating the fetchBugs Method to Return a ZendPaginator Adapter
The fetchBugs method that you wrote earlier creates a Zend_Db_Table_Select object, runs the fetchAll method, and then returns the results. Things work a little differently with the paginator since Zend_Paginator runs its own queries, you need to update the fetchBugs method to return an instance of the DbTableSelect adapter. One other thing since the method is no longer returning bugs, you should rename the method to fetchPaginatorAdapter . I always like to name a method so it describes what the...
Refactoring the Bug Controller listAction to Load the Paginator
Now you need to refactor the BugController's listAction one more time to fetch the paginator and pass it to the view. Note that as you develop more with the framework, you will see a pattern emerge where you cycle from the model to the controller to the view, working on all three components simultaneously to build and refactor functionality. You first need to refactor how the controller is handling the request parameters in listAction . This is because the sort and filter criteria are going to...
To apply a quick fix suggestion
1. Open the file containing the problematic code. The line s containing code to which a quick fix can be applied will be indicated by a lightbulb icon in the vertical marker bar to the left of the editor window. See Real Time Error Detection for more information on how errors are indicated. 2. Place the cursor on the problematic code section and press Ctrl 1 -or- click the lightbulb icon in the marker bar. The Quick Fix list suggests options for fixing the code.
Adjust Your Document Root
Ok, there's just one more step before we can actually begin using our Zend Framework-powered website. Because the .htaccess and index.php files reside within the public directory, the public 120 CHAPTER 5 INTRODUCING THE ZEND FRAMEWORK directory must be identifiable by Apache as the website's document root and root directory. To change these settings, open your httpd.conf file and search for DocumentRoot. Until now the Document-Root directive has been set to C apache htdocs gamenomad, however...
Installing PHPUnit
The book's examples use PHPUnit for testing. You will need PHPUnit installed to run these tests. PHPUnit can be installed using PHP's PEAR interface and using the following commands pear channel-discover pear.phpunit.de pear install --alldeps phpunit PHPUnit Running this command will automatically install PHPUnit for you. The version used in the book is 3.3.6 although later 3.x versions should also work. You can find more information about PHPUnit at http www.phpunit.de. To test your...
Using FTP and SSH
Zend Studio's FTP and SSH support is given through the RSE Remote Server Explorer plugin. Files from FTP SSH servers opened in Zend Studio can be edited using Zend Studio's PHP editing functionality such as Debugging, Profiling, Content Assist, Outline views, Formatting and Getter and Setter generation. To view and edit a file from an FTP SSH server in Zend Studio, you must first create an FTP SSH connection. There are then two ways of working with files linked to FTP SSH 1. Viewing and editing...
Creating the Edit Action
Next, to create the editAction method in the bug controller, first create the action with Zend_Tool, as shown in Listing 4-27. Listing 4-27. Creating the Bug Controller Edit Action with Zend_Tool The edit action is similar to the submit action, except it needs to open the selected item and then populate the form with its values, as shown in Listing 4-28. Note that Zend_Db_Table_Row has a helpful toArray method, which makes populating the form with a database row very easy. Listing4-28....
Building and Processing Web Forms with ZendForm
Almost every aspect of your CMS project will be dealing with dynamic data in one form or another. Managing this data is broken down into two areas of responsibility Capturing the data The data is captured, validated, and filtered by Zend_Form. Storing the data This depends on the data source, but in the case of this CMS, the data will be stored by Zend_Db. This separation contrasts some other patterns that handle data validation and filtering in the database abstraction layer. There is a good...
ZendControllerRouterRouteHostname
Router_Route_Hostname unsurprisingly handles hostname routing. A common use case for this is matching usernames that are in the sub domain segment of the hostname. For instance, if we have our public facing web site on www.domain.com and our registered users have account URL like user1.domain.com, then we can use the Router_Route_Hostname route to rewrite the requests to the account controller. route new Zend_Controller_Router_Route_Hostname , username.domain.com', array 'controller' gt...
PHPDocs
PHPDocs provides structured, easy-to-read documentation of all your php elements. PhpDocumentor can automatically create PHPDocs from your scripts, using a templating system to change your source code comments into readable formats. The PHPDoc Generator Wizard is Zend Studio's interface with phpDocumentor. PHPDocs list all classes, functions, files and other elements in an easily-browsable format so that scripts can be easily navigated and understood. PHPDocs also incorporate PHPDoc Block...












