NB68symfony

Note: This article is a translation of a Spanish article written by Diego Silva

Contents

Symfony on Windows in NetBeans 6.8

Symfony is a framework for PHP that allows you to develop web applications based on MVC. It helps enormously in building complex web applications in PHP. While symfony was designed to work from the command line, NetBeans 6.8 support for symfony lets you use it in the NetBeans graphic user interface.

Installing the Symfony plug-in

Installation is fairly simple. It can be downloaded from the Update Center (Tools> Add-ons). We have installed the plugin for PHP. If you do not have it installed, this is a good time to do so.

Image:Symfony-01_NB68symfony_es.jpg

... If you install the PHP plugin, the IDE will prompt you to install the JavaScript Debugger

Image:Symfony-01a_NB68symfony_es.jpg

Let the IDE install the plug-ins, and when it is finished, the IDE will ask if you want to restart the IDE. And that'll do: restart the IDE.

Installing Symfony

In the previous section we installed only NetBeans IDE's support for symfony. We also need to install the actual symfony framework. For this we must do the following

  1. Download symfony from here:
    http://www.symfony-project.org/installation/1_2
    .
  2. Although symfony has its own installation instructions, here we follow our own course. Extract the Zip file in the root of C:\ so that you have created a folder called
    C:\symfony-1.2.9
    .

Usually, that's all you need to do to install symfony.

If you have already installed symfony before setting up symfony support in NetBeans IDE, it does not matter. The important thing is to remember where you are.

Configuring the Symfony Plug-in

Now, in NetBeans we go to Tools> Options and select "PHP". Then open the "symfony" tab. What we do here is to select the main script for symfony.

Image:Symfony-02_NB68symfony_es.jpg

Note that the file has no extension. Actually (if opened from a text editor) it is a PHP file, but it doesn't have the .php extension.

Creating a Project

Now create a new PHP project using symfony. Press Shift + Ctrl + N (File> New Project)

Image:Symfony-03a_NB68symfony_es.jpg

Click Next. We create the project name. For our example it will be "MiApp."

Image:Symfony-03b_NB68symfony_es.jpg

We leave the other default options. Click Next

Set the path to be displayed in the browser when you run the application.

Click Next.

Now, select the "Symfony" framework.

Image:Symfony-03d_NB68symfony_es.jpg

Note that is calling a special key, for security purposes to prevent attacks CSRF token in forms. For purposes of this tutorial, we will use the same key proposal UniqueSecret.

Click Finish.

The IDE now creates our project.

Preparing the project

Configuring Apache

This application runs on the Apache Web Server, which must be installed. What we recommend is to run the symfony development application on another host. This host will be local and virtual, so that it runs under a different name on another host and port number. In our case it running on port 9090.

On the left side of our project, we open the config / vhost.sample which has a code like this:

    # Be sure to only have this line once in your configuration
    NameVirtualHost 127.0.0.1:80

    # This is the configuration for MiApp
    Listen 127.0.0.1:80

    <VirtualHost 127.0.0.1:80>
      ServerName MiApp.localhost
      DocumentRoot "D:\home\DSILVA\Mis documentos\NetBeansProjects\MiApp\web"
      DirectoryIndex index.php
      <Directory "D:\home\DSILVA\Mis documentos\NetBeansProjects\MiApp\web">
        AllowOverride All
        Allow from All
      </Directory>

      Alias /sf "C:\symfony-1.2.9\data\web\sf"
      <Directory "C:\symfony-1.2.9\data\web\sf">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>

Well, what we do first is to edit this file to run the symfony application on port 9090, as follows:

    # Be sure to only have this line once in your configuration
    NameVirtualHost 127.0.0.1:9090

    # This is the configuration for MiApp
    Listen 127.0.0.1:9090

    <VirtualHost 127.0.0.1:9090>
      ServerName MiApp.localhost
      DocumentRoot "D:\home\DSILVA\Mis documentos\NetBeansProjects\MiApp\web"
      DirectoryIndex index.php
      <Directory "D:\home\DSILVA\Mis documentos\NetBeansProjects\MiApp\web">
        AllowOverride All
        Allow from All
      </Directory>

      Alias /sf "C:\symfony-1.2.9\data\web\sf"
      <Directory "C:\symfony-1.2.9\data\web\sf">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>


The routes of the project folder have already been established by symfony.

Now,

  1. Copy this content,
  2. Open up the httpd.conf file located in the $ APACHE_HOME \ conf,
  3. Paste the content
  4. Save your changes
  5. And restart the Apache service.
To see if you have Apache configured correctly, open up the browser on
http://localhost:9090
, or run the project with the F6 key.

Image:Symfony-04_NB68symfony_es.jpg

Configuring the database

Now we have to create the database. From the MySQL console (can be useful on the command line, or the more sophisticated uses) execute (as root) the following:

create database tienda_virtual; #crea la base de datos
grant all on tienda_virtual.* to tienda_virtual@localhost identified by "tienda_virtual"; #crea un usuario con acceso a esa base de datos

Run from NetBeans.

I recommend not to use the root user to access a database from the application. Therefore I recommend creating a user for every database that is being created. It is for security purposes.

Then we set the configuration of our application with the database. To do this, right click on the icon of the symfony project and select Symfony > Run command ...

Image:Symfony-05_NB68symfony_es.jpg

This opens the symfony Run Command dialog. Type "config" into the Filter field and the IDE displays the commands associated with configure. Select configure:database from the list and write as arguments "mysql: host = localhost, dbname = store" shop store

Image:Symfony-05a_NB68symfony_es.jpg

Then click "Run".

We can see that it has updated the file config/databases.yml.

Creating tables

The tables can be created from the config/schema.yml file. Yml is a standard serialization and friendly programming languages.

We will create two tables: product_type and product. To do this, edit config/schema.yml with the following:

propel:
  product_type:
    type_id: ~
    type_name: {type: varchar(255)}
  product:
    product_id: ~
    type_id: {type: integer,foreignTable: product_type, foreignReference: type_id,required: true}
    Product Name: {type: varchar(255)}
    stock: {type: integer}
    Price: {type: double(10,5)}

Note the spaces between each statement, type and value.

Now you can use symfony inside NetBeans IDE to create the tables. To do this, from the Run Command dialog, find and run the
propel:insert-sql
command.

Image:Symfony-05b_NB68symfony_es.jpg

This will create the schema for our application and also the tables in our database

Image:Symfony-05c_NB68symfony_es.jpg

Note: If you already have created a database, do not edit
config/schema.yml</tt> and run the command <tt>{symfony propel:build-schema
And to end with the database, we must create the data model, which is a php class mapping between the tables of your database. To do this run the command
propel:build-model
.

After that, we see the result in the lib folder

Image:Symfony-05d_NB68symfony_es.jpg

Running the application

The application is not quite finished. Missing styles, colors. But you can see something. Before that, we must build the application. To do this run the command
propel:build-all
. This builds everything about the scheme until the forms.

Image:Symfony-06a_NB68symfony_es.jpg

Then run
propel:generate-module
with the parameters as shown in the image.

Image:Symfony-06b_NB68symfony_es.jpg

And so we have the table "product_type." Click here to see
http://localhost:9090/frontend_dev.php/tipo

Image:Symfony-06c_NB68symfony_es.jpg

Image:Symfony-06d_NB68symfony_es.jpg

Image:Symfony-06e_NB68symfony_es.jpg

Finally

Since the purpose of this tutorial was not to be a course of symfony, I suggest reading the useful manual
http://www.symfony-project.org/jobeet/
, which shows you over 24 days (for one hour each day) how to make a functional project with symfony.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo