Symfony And MVC


Table of Contents

Symfony MVC 
The Basic File Structure 
URI-Related Information 
Using sfRouting to Get Information About the Current Route 
Using the module / action name in the view 
Using the module / action name in the view 
How to call link_to from model 
How to call link_to from model 
Forward/redirect in a component 
Post process after save 
Post process after save 
Post process after save 
Pros and Cons of front- and backend in separate applications 
Pros and Cons of front- and backend in separate applications 
Pros and Cons of front- and backend in separate applications 
Pros and Cons of front- and backend in separate applications 

Symfony MVC 

The Basic File Structure 

http://www.symfony-project.org/book/trunk/19-Mastering-Symfony-s-Configuration-Files#The%20Basic%20File%20Structure

sf_root_dir           # myproject/
                      #   apps/
sf_app_dir            #     myapp/
sf_app_config_dir     #       config/
sf_app_i18n_dir       #       i18n/
sf_app_lib_dir        #       lib/
sf_app_module_dir     #       modules/
sf_app_template_dir   #       templates/
sf_bin_dir            #   batch/
                      #   cache/
sf_base_cache_dir     #     myapp/
sf_cache_dir          #       prod/
sf_template_cache_dir #         templates/
sf_i18n_cache_dir     #         i18n/
sf_config_cache_dir   #         config/
sf_test_cache_dir     #         test/
sf_module_cache_dir   #         modules/
sf_config_dir         #   config/
sf_data_dir           #   data/
sf_doc_dir            #   doc/
sf_lib_dir            #   lib/
sf_model_lib_dir      #     model/
sf_log_dir            #   log/
sf_test_dir           #   test/
sf_plugins_dir        #   plugins/
sf_web_dir            #   web/
sf_upload_dir         #     uploads/

URI-Related Information 

http://www.symfony-project.org/book/trunk/06-Inside-the-Controller-Layer#Accessing%20the%20Request http://www.symfony-project.org/api/1_0/sfWebRequest

getUri() Full URI http://localhost/myapp_dev.php/mymodule/myaction
getUriPrefix Uri prefix protocol, hostname and server port
getPathInfo() Path info of web request /mymodule/myaction
getReferer() Referrer http://localhost/myapp_dev.php/
getHost() Host name localhost
getScriptName() Front controller path and name [path/]myapp_dev.php

Using sfRouting to Get Information About the Current Route 

http://www.symfony-project.org/book/trunk/09-Links-and-the-Routing-System#Dealing%20with%20Routes%20in%20Actions

// If you require a URL like http://myapp.example.com/article/21
// Use the following in article/read action
$uri = sfRouting::getInstance()->getCurrentInternalUri();
 => article/read?id=21
$uri = sfRouting::getInstance()->getCurrentInternalUri(true);
 => @article_by_id?id=21
$rule = sfRouting::getInstance()->getCurrentRouteName();
 => article_by_id
// If you just need the current module/action names,
// remember that they are actual request parameters
$module = $this->getRequestParameter('module');
$action = $this->getRequestParameter('action');