Chapter 2. Creating Projects

As with just about any Integrated Development Environment (IDE) on the market today, users are guided into the concept of doing their work in blocks or groups of tasks, also known as projects. Projects are also naturally the central control point to creating a web application in Zend Studio for Eclipse, so this chapter guides you through creating and managing projects.

Projects Wizard

Zend Studio for Eclipse has added a project creation wizard to its environment to help you get underway with new projects. When you decide to start a new project, you can use this wizard to guide you through the different options available within Zend Studio for Eclipse. Before you start a new Zend Studio for Eclipse project, you should take some time to consider its features in terms of the following:

  • Where will the project files be stored?

  • Will a team of developers work on this project?

  • Will the location of the project files be important to testing while in development?

  • What supporting libraries will be needed for the new project?

There are other unique questions that you will want to have answered for each particular project, but the preceding questions, when answered, give you a good starting point to almost any Zend Studio for Eclipse project.

To start a new Zend Studio for Eclipse project, right-click on the PHP Explorer view in the top-left section of the IDE and select New, or open the File menu and select New. Within this menu, you have the option to launch a few different wizards, but for now just select the PHP Project option. This selection is shown in Figure 2.1.

Launching the PHP Project Wizard.

Figure 2.1. Launching the PHP Project Wizard.

After you select the PHP Project option from the menu, the corresponding wizard is launched. In this option window, some of those initial questions are now answered. The first thing the wizard needs is the name of the new project in question. For this example, we will name the project “PHP Sample”, so this name will appear in the PHP Explorer when the wizard is finished.

The next option that you are presented with is choosing where you will be storing the contents of this project. In other words, where will you be saving your project files? In this matter, there are some factors to consider. If you take the directory path offered to you by the wizard (and you have not changed any of the Workspace settings), your project files will be stored in a rather obscure location. The file path offered to me was C:Documents and SettingspetermacendWorkspacesDefaultWorkspacePHP_Sample.

It would be better for the project to have its own location under a less complex file path for two reasons: Finding the path is easier if it is not buried so deeply in the file system, and if you want to run any of the files within the browser and you have a local or networked access to a web server, it would be beneficial to save all your files within the file structure of a web server. This also allows you to skip the step of “publishing” the files each time you want to review them in a browser. Therefore, I chose to save my project files in my local copy of Apache at C:Program FilesApache GroupApachehtdocsPHP_Sample. And although this path is rather lengthy, it will be available to my localhost browser for testing as I build the web application.

These options are not the only ones offered to you in the initial step of the PHP Project Wizard. The next block of information offered to you, titled PHP Version, is the ability to override the Workspace settings for this particular project. The settings in the Workspace are generally systemwide options that are expected to apply to all projects within the Zend Studio for Eclipse IDE. Here, though, you are given the option to override those options because the project that you are now defining may have some special requirements. Figure 2.2 shows these options with the settings I chose.

Changing the default settings on the PHP Project Wizard.

Figure 2.2. Changing the default settings on the PHP Project Wizard.

If you indeed decide to override the Workspace settings, you need to initially mark the Enable Project Specific Settings checkbox. When you do this, the options under the control of this checkbox are activated and await your alterations. In this case, only two options are available: to tell Zend Studio for Eclipse that you want to use a different version of PHP and whether you want your project to be able to use ASP tags as PHP tags. For our example, keep the Workspace default project settings as they are already defined.

When you have finished with all the options on this window of the wizard, you can click on the Next button at the bottom to continue the wizard’s progress. Or, if you have no other needs in defining this particular project, you can click Finish.

If you clicked on the Next button, the next screen in the Project Creation Wizard is displayed. On this screen you can identify any supporting libraries or projects that you want to use in conjunction with this new project. For example, in this project we identified the fpdf library (a free PHP library used to build dynamic PDF files for websites) as being required, as shown in Figure 2.3.

Identifying required supporting libraries for a new project.

Figure 2.3. Identifying required supporting libraries for a new project.

After all the parts of the project are identified, click on the Finish button, and the project is created. There are only these two main windows in the Project Creation Wizard, but a lot is accomplished. The newly created project is now shown in the PHP Explorer. You can create your PHP files and edit them within this new project context.

Zend Framework Project

You may want to create a different kind of PHP project within Zend Studio for Eclipse that makes proper use of the Zend Framework library. In this instance all you have to do is select File, New, Zend Framework Project in the menu system. The resulting wizard is almost identical in that you have to provide a project name and a project storage location. You also have the option to override the Workspace default project settings if you desire.

The difference then comes in the second screen of the wizard. On this screen, you are shown that the wizard has already included the Zend Framework Library for you. You can also add your own libraries if you want to at this stage. When you complete the wizard, Zend Studio for Eclipse does a little extra work for you in setting up a Model-View-Controller (MVC) environment for your newly created project in the context of the Zend Framework. As you can see in Figure 2.4, the project is created with the library attached and the MVC framework in place.

A Zend Framework Project skeleton has been created.

Figure 2.4. A Zend Framework Project skeleton has been created.

Note

For more coverage about the Zend Framework Library and MVC concepts, see Chapter 17, “Designing the Project.”

Multiproject Support

As you can see from Figure 2.4, another great feature is added to the Zend Studio for Eclipse environment: that of multiple concurrent project management. You can open and close as many projects as your development hardware and operating system allow. This capability is beneficial in that you can have code in one project that you want to have access to while you are working on a different project altogether. This feature alone is worth its weight in gold if you’re a multitalented modern PHP developer, especially if you are also in a maintenance role supporting many web applications at the same time.

These projects can be expanded and collapsed at will and can even be temporarily removed from the PHP Explorer View if they are in the way. To remove a project from this viewer, simply select the project and right-click to bring up the pop-up menu. Then select Delete from that menu to remove the project from view. Be sure to select the correct option from the Confirm Project Delete dialog if you don’t want to totally remove the project from the system.

To bring any existing project back into the PHP Explorer View, right-click on any whitespace in the viewer and select Import from the pop-up menu. In the Import dialog that is displayed, select Existing Projects into Workspace under the General folder. This brings up a browse dialog where you can list all your existing projects. Select the project that you want and click Finish. This brings the project back into the PHP Explorer view. Figure 2.5 shows the Open Project dialog with the existing projects that Zend Studio for Eclipse knows about. You can select multiple projects by clicking on their checkboxes.

Adding existing projects to the PHP Viewer.

Figure 2.5. Adding existing projects to the PHP Viewer.

All this opening and closing of existing projects can also be controlled through the drop-down menu (the PHP Explorer menu) that is at the immediate right of the PHP Explorer view and is identifiable by the white triangle pointing downward. When this menu is activated, you see a whole filtering capability that is also available. If you want to hide or show projects of different types, click the Filters menu item (second to last on the list) to open the project filtering window. As shown in Figure 2.6, this dialog allows you to filter on much more than just project files, and this capability further enhances your project management within Zend Studio for Eclipse.

Assigning filter selections for the PHP Viewer.

Figure 2.6. Assigning filter selections for the PHP Viewer.

Setting Up Working Sets

Working sets are another variation of the filtering process within Zend Studio for Eclipse. With working sets, you can have multiple projects open or even just one project open and simply request the IDE to show you only certain files from the project or projects that you currently have open. The benefit is that you may, for example, have two projects open and want to see only a single file from one of those projects instead of having the display “cluttered” with all the files of that project.

To set up a working set, pull down the view’s menu and choose Select Working Set. In the dialog that appears, you can name and define your working set. If this is your first time using this dialog, nothing is shown in the list of existing working sets. Clicking on the New button starts a new working set wizard of sorts that allows you to define the type of working set that you want, whether it’s PHP, Java, or others. In this case, select the PHP list item and click Next. The following dialog shows you all the PHP projects that you are currently working with in your overall environment and allows you to pick and choose what elements of each project you want to see in this newly defined working set. As shown in Figure 2.7, only a few files are selected from the ExampleProject, the entire project is selected for the Framework_Sample project, and the working set is named MyWorkingSet.

Defining a working set for the PHP Explorer.

Figure 2.7. Defining a working set for the PHP Explorer.

When this working set is properly defined, named, and saved, you can select it by its name at any later time. So with this method of filtering, you are able to easily return to the project environment that you were working on at any time. Also, with multiple working sets, you can change to any of those predefined project environments at will.

Note

These working sets honor any filters that are currently active. If you are including files from a project that is closed and are filtering closed projects, those selected files within the working set are not shown.

Importing Projects

When you start working with Zend Studio for Eclipse, it is a rare case to start a brand-new project. Typically, you are working on existing projects or are at least doing maintenance on previously completed work. So there is obviously a need to be able to work on these existing projects within the Zend Studio for Eclipse environment.

Within the PHP Explorer view menu system is the capability to import existing projects. After right-clicking on the view’s whitespace, you can select Import from the subsequent menu (this import process can also be started from the main File menu). Keep in mind, however, that you must have at least one project predefined within Zend Studio for Eclipse to be able to import into it. Again, after you select the Import option, you starting another wizard process. The initial dialog in the wizard offers many different kinds of import sources: archive files, breakpoints, other existing projects, and so on. The type of import process that we are describing here is that of a file system import. It is an existing PHP application that you now want to work on within the Zend Studio for Eclipse IDE. So, after selecting the File System option and clicking the Next button, you see a dialog like that shown in Figure 2.8.

Importing an existing PHP project into Zend Studio for Eclipse.

Figure 2.8. Importing an existing PHP project into Zend Studio for Eclipse.

When you see this dialog, you can navigate to the folder location for the files to be imported, select all the files (or a subset) in the selected folder, direct which folder these files should be imported into, and probably—and most importantly—direct the wizard to import only the files and folders selected, or take the entire folder structure of the incoming project. Additionally, you can filter the file types to be imported with the Filter Types button. Typically, you choose the Create Selected Folders Only option at the bottom of the dialog because the other option takes in the complete folder structure for the selected project.

After you have selected the files that you want and start the import process, Zend Studio for Eclipse brings those files into the designated project. These files are directly copied from the source folder, and no pointers are used to refer to the original files, so be sure that you do not continue to work on the files in the original folder at the same time because they will become immediately unsynchronized.

Exporting Projects

Exporting projects is just the opposite process to that discussed in the preceding section. As before, a wizard process is activated when you select the Export menu option. Now you can also select the files that you want or simply mark them all for export. Designating the destination path and other options is similar to the import; one thing to note here, though, is that if you select the top-level folder to be exported, that folder is created under the named destination folder. So, to get around that, you have to select the individual files at the top level and then any other folders subordinate to that.

The export wizard can employ many different formats and file types. Exporting breakpoints in a project, for example, could be helpful for a team development project that is being developed on two separate machines. The breakpoints can be exported and then subsequently imported to the second machine, and both support developers can watch the same code and make observations at the same time as the code runs and stops at the same locations. The breakpoint file that is exported is actually a well-formed XML file, as shown in Figure 2.9.

Exported breakpoints file in XML format.

Figure 2.9. Exported breakpoints file in XML format.

Creating New Files

The main point behind the PHP Explorer is to maintain projects in a development environment. But what are projects without files? We have seen how these projects can import and export existing files, so in this section we cover the basic process of creating PHP files.

When adding a new PHP file to an existing project, right-click on the PHP Explorer’s whitespace to bring up the Project menu. Once again, you can accomplish this task of creating a PHP file under the File menu; select New and then PHP File from the submenu. Yet another wizard interface is launched, and you are asked to supply the source folder (where the file will be stored after it is created) and the filename. Then you can click the Next button and select from the offering of file templates that are shown. Figure 2.10 shows this dialog.

Selecting a file template for a new PHP file.

Figure 2.10. Selecting a file template for a new PHP file.

Note

You can create and name your own file templates in the PHP section of the Preferences management area. See Chapter 3, “Environmental Settings,” for more information on creating a file template.

Other file types can be created in this new file process, and depending on the file type that you specify, the Template dialog adjusts to those kinds of templates. So, for example, if you are creating a cascading style sheet (CSS) file, the Template dialog offers you any predefined CSS templates from which to choose.

After a file is created and assigned to a project, you can begin to write your code. Chapter 4, “The Code Editor,” covers most of the tasks that you can accomplish within the code editor.

Using Link with Editor

Another feature that you may find handy within Zend Studio for Eclipse is its capability to switch the file in the editor (the viewer to the immediate right of the PHP Explorer on a typical perspective) on the fly. You see a menu option called Link with Editor, which is also identified by the menu icon of yellow arrows pointing left and right. When this toggle (on/off) feature is activated, if you change your highlighted file in the PHP Explorer (and the file is open in the code editor), that file is instantly brought into focus in the editor. This timesaving feature allows you to quickly jump between open files. This icon is also visible in the PHP Project Outline and Outline views that typically appear under the PHP Explorer view, so you can turn it on or off in either location and it will have the same effect.

Accessing Remote Files

Naturally, in today’s broadband world of remote development, there are lots of examples of web development projects being created with team members in different cities all over the world. To that end, Zend Studio for Eclipse is able to work on remotely located files via either the FTP or SFTP protocols. In this chapter we discuss this topic briefly and define only an FTP connection. Chapter 13, “Version Control Integration,” provides more in-depth coverage on remote development topics.

If you are going to make a connection to a remote location or server that is housing your project, you first have to tell Zend Studio for Eclipse where that server is located and any credentials that you need to gain access to it. If you are in the PHP perspective, you have to open the Remote Systems View, (if it is not already available behind the PHP Explorer View) by selecting Window, Show View, Remote Systems. The Show View dialog appears, as shown in Figure 2.11.

Selecting the Remote Systems view from the Show View dialog.

Figure 2.11. Selecting the Remote Systems view from the Show View dialog.

After opening the Remote Systems View, you can define a remote site within it. Click on the first icon on its toolbar (green square with a yellow cross) or right-mouse on the view and select New, Connection to start the definition of an FTP server. When the New Site dialog appears, select the FTP Only option and click Next. The Remote FTP Only System Connection dialog appears, asking for your credentials, as is evident in Figure 2.12.

Providing the credentials for a remote FTP server connection.

Figure 2.12. Providing the credentials for a remote FTP server connection.

Once this connection is established (you will be asked for a username and password when you first make a connection), you can then browse the files on that remote server from within the Remote Systems View.

Then to make this an even better option, Zend Studio for Eclipse allows you to create a remotely connected project. To do this, descend your file tree on the remote server to the location where a project would start (generally under the htdocs folder) then right-mouse on that folder and select Create Remote Project. This will then tell Zend Studio for Eclipse to create a project in the PHP Explorer View with the name of the server and the project folder combined into its name within that view (see Figure 2.13).

Creating a project in the PHP Explorer View based on a remote FTP connection.

Figure 2.13. Creating a project in the PHP Explorer View based on a remote FTP connection.

Note

You may also notice the console view appear and begin to become quite active during this process. This is merely the FTP connection information being displayed to you as you make connections and perform activities on the remote server.

Summary

This chapter covered the basics of working with projects within the IDE environment and showed you some import and export methods. As well, multi-project editing and support was also discussed. Also, you briefly saw how to establish an FTP connection to a remote server and how to manage that connection within the context of local and remote projects. Once you get familiar with managing projects within Zend Studio for Eclipse, you will be well on your way to becoming extremely efficient in PHP development within this IDE.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.42.87