Showing posts with label symfony. Show all posts
Showing posts with label symfony. Show all posts

Monday, August 23, 2010

sugarbox part 3

routing.yml

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

blog:
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:

Congratulations!
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:

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

blog_new:
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'

Thursday, August 5, 2010

Mongodb : Getting wet


Mongodb is another database system using the features of RDBMS and key-value stores. It's a non-sql database. All the results display in json format. MongoDB is a scalable document database, which is also open source. In MongoDB there are no tables and rows. You have collections and documents instead. And collections can contain any type of document, it is not limited by the columns or fields like a table. i.e. Mongodb is schemaless. So that you can update with new fields,
without altering the entire structure. In the case of RDBMS you must change the schema.

Mongodb can be download from here: Downloads
Mongodb installation for unix : Installation

In this post i'm writing about symfony2+doctrine2-ODM+mongodb

doctrine2-ODM (Doctrine MongoDB Object Document Mapper). You can read more from here.
There is a blog tutorial in here.

sandbox configuration

All the configuration files goes into hello/config folder. The file structure is given below.
config folder
the configuration files written in yaml format. doctrine configurations are done in config.yml. you can do seperate configuration for dev, prod, even for testing.

doctrine configuration:(in config.yml)

doctrine.dbal:
    driver:   PDOMySql
    dbname:   todo
    user:     root
    password: admin
doctrine.orm: ~


routing.yml



homepage:
    pattern:  /
    defaults: { _controller: FoundationBundle:Default:index }


hello:
    resource: HelloBundle/Resources/config/routing.yml

Wednesday, August 4, 2010

The Architecture

Today we going to understand the directory structure, basic routing,controller-view actions etc.

This is the basic directory structure of symfony 2 sandbox.

Tuesday, August 3, 2010

Introduction

This blog is dedicated to symfony2 web development. i intend to post a series of tutorials for using symfony2 in real web apps.

There is a support group here
My codes are here