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...

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...

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 -...

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...

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...

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...

Updating the Bug Controllers Submit Action

Now that you have the database and model set up, you are ready to update the bug controller and implement the submit action. In the previous chapter, you created this action but just had it dump the submitted data out onto the page if the form passed its validation. Now you need to update this action and insert the bug into the database see Listing 4-6 . First you create a new instance of the Bug model in the submit section. Then, once you have this instance, you call the createBug method,...

The Search Form

The first thing you are going to need is a search form. Create a new file in application forms named SearchForm.php. Then create a class in the SearchForm.php file named Form_SearchForm, which extends Zend_Form. Zend_Form runs a method called init when it is constructed this is where you build the form. Add a field for the search keywords and a submit button to the form, as shown in listing 9-7. Listing9-7. The Search Form in application forms Search.php lt php class Form_SearchForm extends...

Designing Your Site

In this chapter, you'll create the template for your CMS using Zend_View and Zend_Layout, which make up the presentation layer for the Zend Framework. Rendering the Presentation Layer with Zend_View The core purpose of the Zend_View class is to separate this presentation code from the application logic and data. Separating the HTML from your core application code makes all your code easier to read and follow. The view scripts are basically PHP files that are rendered within the scope of...

Index

abstract Content_Item class, 87, 91 creating base class, 87 extending base content item class, 92-3 loading pages, 88, 90 manipulating data, 91 overview, 87 utility methods, 90 abstract data structures, 77-8 abstraction layer, 87 access control, 164-5 action controllers, 12 add menu item action, 130 addAction , 130 addAction method, 131 addFilters method, 43 adding menu items, 228-9 addItem method, 131 addMultiOptions method, 45 addRole method, 165 addValidators method, 43 admin menus creating,...