Sunday, July 31, 2011

Advance form-> Write to multiple tables in one form

http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms

Thursday, July 28, 2011

xdebug for symfony testing

Update: The latest version of mamp already comes with xdebug so all we need to do is just to uncomment that xdebug line in php.ini.

/*
http://oldforum.symfony-project.org/index.php/t/18326/

Download revised version of xdebug from Komodo

Replace the xdebug.so from MAMP php lib folder (e.g. /Applications/MAMP/bin/php5/lib/)

uncomment the xdebug line from the php.ini file.

Restart apache and the test should run~
*/

Wednesday, July 20, 2011

Layout and template system in Symfony

CSS
view.yml (under apps/frontend/config/) defines which css file to be used as default.
Multiple default css files could be included in view.yml.

To customize a specific css file for a specific module and action, we can create a view.yml file under apps/frontend/modules/"module name"/config/

For instance, we have a job module, to specify which css to be used, we can create the following view.yml in apps/frontend/modules/job/config/

How does the final html actually being generated and presented to the user? Here's the flow.
Request from user->routing based on the requested URL->action.class.php analyze which action to be taken->select the appropriate template-> combine the content through actiona nd template->page back to user.

If we take a look at the file actions.class.php, there are different functions like
executeIndex, executeShow, executeNew
The string after "execute" are the actual action, which usually refer to the URL sent by the user.
For instance, if you type http://localhost:8080/job/new
the executeNew function will be triggered, and the "newSuccess.php" template will be loaded.


Data model in Symfony using Doctrine (ORM)

In day 3 of the book (Practical Symfony), a data model was created using an Doctrine, a kind of ORM, It looks pretty complicate at the first sight, but prove to be very handy after a while.
In fact Doctrine make use of another language (YAML) to deal with schema definition. The relationship between Doctrine and YAML could be found here.

In Symfony, in order to define your data model (which is fundamentally the relational database schema), the first file you need to hack in is the schema.yml which is placed under (config/doctrine/)

I followed the instruction in Practical Symfony book, which define the whole database and its relation in YAML format. But you can do a reverse Doctrine generate through symfony doctrine:build-schema, which essentially build the YAML file based on your existing mysql structure. Mind you you have to define the right foreign key and define the database info in databases.yml (in config/) first.

Here's the really cool thing about Symfony, php database objects generation.

symfony doctrine:build --model (generate models files)
symfony doctrine:build --sql (generate sql for inserting data models to SQL)
symfony doctrine:insert-sql (quite obvious, isn't it?)

Alternatively, all these steps could be compress to a simple
symfony doctrine:build --all command

So the database tables has been built, but we still need to load some data into the DB to get it to work. You're right, we need another YAML file. These files are put in /data/fixtures
For instance if we're going to put some data in the obeetCategory table, we can create a file like the following:
JobeetCategory:   actAs: { Timestampable: ~ }   columns:     name: { type: string(255), notnull: true, unique: true }

We can do the same for creating other yml files for other tables, and put it in the folder (data/fixture/)

After all the yml files are created, we can now run the following command and load the initial data in the database

symfony doctrine:data-load

Before we see the miracle of symfony, we need to run one more command to generate the nessceary php files in the module folder.
symfony doctrine:generate-module --with-show --non-verbose-templates frontend job JobeetJob

Now if we check the module folder (apps/frontend/modules/), a new folder (job/) is created with actions and templates in it.

Visit the following URL to have a taste of Symfony
http://localhost/frontend_dev.php/job

Viola, it's already working!



Symfony note (Basic project setup)

Some basic setup of symfony projects

Download and install symfony

Create a project directory (e.g. /project/symfony/projectx)
in the project path (/project/symfony/projectx), run the following command
symfony generate:project "name of your project", in this case
symfony generate:project projectx
Change the permission of cache and log to 777 (Make sure they are not in your web root)
chmod 777 log/ cache/

Download the symfony framework and unzip it in the lib/vendor (need to be created) folder of your project
in this case /project/symfony/projectx/lib/vendor/symfony

Define the new site in httpd.conf (refer to Practical Symfony 1.4 Doctrine version Day 2 exercise)
Link the image folder through adding a Location directive in httpd

You should now be able to access your site through http://localhost:8080/

Friday, July 8, 2011

Install Symfony framework in OSX with MAMP

http://www.tech-recipes.com/rx/2884/os_x_how_to_install_symfony_into_mamp/

PEAR configuration

To configure pear (PHP related framework)