Book Image

PHP Application Development with NetBeans: Beginner's Guide

By : M A Hossain Tonu
Book Image

PHP Application Development with NetBeans: Beginner's Guide

By: M A Hossain Tonu

Overview of this book

<p>NetBeans has many features that greatly simplify PHP development, and with its several features and great flexibility, PHP developers can become overwhelmed by the IDE's options. This book provides step-by-step instructions that show you how to take control of the environment and make use of these features to make your PHP application development more efficient and productive than ever before.<br /><br />"PHP Application Development with NetBeans: Beginner's Guide" leads you through the crucial parts of PHP programming and shows you how to use the features of NetBeans that will improve your PHP development experience, through clear and easy instructions.<br /><br />The book gets you started with the development environment and tools, and takes you through working on practical projects with a clear focus. With each chapter being mission-critical, the book is a perfect companion to boost your PHP coding productivity and gain experience with even complex projects.<br /><br />The book starts with setting up the PHP development environment and introduces exciting and useful IDE features. You'll learn how to build real life PHP projects such as Facebook like Status Updater and even User Registration, Login &amp; Logout application. Also the book will introduce you with some must know development tools such as debugging &amp; testing tools, source documenter tools, and versioning tools.<br /><br />Working with the NetBeans IDE for PHP development has its own advantages, and this book reassures the purpose. This book is full of illustrations, screenshots, and clear instructions to take your PHP development to a new level and even shows you time-saving tricks and other productivity enhancements.</p>
Table of Contents (16 chapters)
PHP Application Development with NetBeans Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action — creating a NetBeans PHP project


Finally, we are going to create a NetBeans PHP project to have the PHP content organized, and get more control over the created project.

In order to create a NetBeans PHP project, follow the steps below:

  1. 1. In order to start the project creation, go to File | New Project from the IDE menu bar.

  2. 2. From this window, choose PHP for the project category, and select PHP Application that is selected by default, which means we are going to create a PHP project from scratch. If you already have source PHP code, then go for PHP Application with Existing Sources, and you will have to browse to your existing sources to set your source directory.

  3. 3. Click on the Next button, which will take you to the following screen, as shown below:

  4. 4. Define the project name and IDE, which automatically suggests the source folder for the given name. However, we can explicitly define the source folder path by browsing the folder path. Also, choose the appropriate PHP Version, according to which the project will behave at the IDE, and select Default Encoding. We will go for the selected items, by default, to have the latest PHP version behavior, and UTF-8 as Default Encoding.

  5. 5. Remember that the project metadata is the data that is used only at the local stage; optionally, you may put the project metadata created by NetBeans into a separate directory. To do that, check the box Put NetBeans metadata into a separate directory.

  6. 6. So, we name our project as chapter1, and click on Next, as shown in the following screenshot:

  7. 7. Define where the project will run (remote server, and so on), as well as the project URL. The default project URL is a formation of http://localhost/ concatenated with a trailing project name. Click on Next to get to the following screenshot:

    Optional checkboxes are used to add the PHP framework support into your project, if required. The IDE supports the two popular PHP frameworks—the Symfony and Zend frameworks.

  8. 8. Finally, click on Finish to complete the project wizard, and NetBeans will open the PHP project. It should look similar to the following screenshot:

    An index page, index.php, is created inside the project source automatically.

  9. 9. To test the project, we will put some code between PHP tags. So, let's put a simple echo as follows:

    <?php
    echo "Hello World";
    ?>
    
  10. 10. Save the file and point your browser to a project URL, http://localhost/chapter1/. The page should give an output similar to the following screenshot:

    So, we can see that our PHP project is performing fine.

  11. 11. To add more files and classes into our project, you may right-click on the project name, which will show the Project menu:

    With this project context menu, we can add more PHP files, classes, and so on from New, whenever required. As we can see in this screenshot, a project can be modified as well. For example, you can rename, copy, or alter the project configuration, should you so wish.

What just happened?

Creating a new PHP project in NetBeans has worked like a charm. While creating it, we have observed that we can easily set several configurations of a project with the help of the step-by-step project creation wizard. Also, we have seen that after the creation of a new project, the IDE supports new PHP files, classes, interfaces, and so on from the project context menu. Note that, from the project context menu, you can manage the project operations, such as running and versioning tasks. To change the settings of an existing project, position the cursor on the project node, and choose Properties from the pop-up menu.

So, from now on, these will be our steps to create a new PHP project in NetBeans.

Have a go hero — creating a project from existing sources

If you already have some foundation source code for a PHP project, you can bring those source files under NetBeans, to have more control over the project. Create a new project from existing sources by selecting File | New Project.