Monday, August 23, 2010

sugarbox part 3


pattern: /
defaults: { _controller: FrameworkBundle:Default:index }

resource: BlogBundle/Resources/config/routing.yml

From the first line(homepage), it's clear that, the URL http://localhost/sugarbox/web/index.php/ goes to the 'Default' controller in 'FrameworkBundle' and point to the 'index' action. It shows this in your browser:

You have successfully created a new Symfony 2 application.
So check it yourself. You can give any name instead of homepage.

The second(blog), point to another routing file inside src/Application/BlogBundle/Resources/config/routing.yml

it goes like this:

pattern: /blog
defaults: { _controller: BlogBundle:Blog:index }

pattern: /blog/new
defaults: { _controller: BlogBundle:Blog:new }

so when a request like this http://localhost/sugarbox/web/index.php/blog points to 'Blog' controller in 'BlogBundle' and 'index' action. This outputs this:

Blog Application
Hello Blog index!

Http://localhost/sugarbox/web/index.php/blog/new points to 'Blog' controller in 'BlogBundle' and 'new' action. This outputs this:

Beware: we can't save the post now. So by clicking submit button make no sense!

In your terminal go to sugarbox directory
$ cd sugarbox
symfony2 has inbuilt CLI. We now initiate thie
$ php blog/console -s
this will display this:

to list all commands

Symfony > list
Symfony displays this:

Now we are going to create database as configured in config.yml
initialy, we drop the database(todo), if there any present.
Symfony > doctrine:database:drop
Dropped database for connection named todo
Symfony > doctrine:database:create
Created database for connection named todo

to check, go to your phpmyadmin. You'll see todo database(empty)
To create tables according to schema created in BlogBundle/Entity/Blog.php.

first, we create repositories
Symfony > doctrine:generate:repositories
Generating entity repositories for "BlogBundle"

> generating Bundle\BlogBundle\Entity\BlogRepository

now we create the schema
Symfony > doctrine:schema:create

to check, go to phpmyadmin. There is a table named 'posts'

1 comment:

  1. Nice howto.
    I have a question: Is there something similar to Scaffolding in sf1?