» symfony reference card 1.0 «

sfAction < Action

Returns

->forward($module, $action), ->render_text($text), sfView::SUCCESS

Shortcuts

->getController(), ->getUser(), ->getRequest(), ->getRequestParameter($name)()

Template variables

->setVar(), ->setVars(), ->removeVar(), ->hasVar(), ->getVars(), ->clearVars()

Models an helpers

->useModel(s)(), ->useHelper(s)()

Authentication

->setSecure(S|L|A), ->checkCredential($crendentials, S|L|A)

Cache

->setCache($time, S|L|A), ->cacheExists(), ->isCached()
sfView::ALL (toutes les actions)

Introspection

->getModuleName(), ->getActionName()

Templates

->setHasLayout($boolean), ->hasLayout() ->setLayout($name) ->setTemplate($name)

sfUser < SecurityUser < User < ParameterHolder

Authentication

->isAuthenticated(), ->setAuthenticated(B)

Droits

->addCredentials(S|L|A), ->hasCredential(S|L|A), ->clearCredentials(), ->removeCredential(S)

Language

->setCulture(code ISO), ->getCulture()

WebRequest < Request < ParameterHolder

For access to parameters, cf. ParameterHolder class.

Form validation

->getError($name), ->getErrors(), ->hasError($name), ->hasErrors(), ->setError($name, $message), ->getErrorNames(), ->removeError($name)

Files

->moveFile($name, $file, [$fileMode = 0666], [$create = true], [$dirMode = 0777]), ->hasFileError($name), ->hasFileErrors(), ->getFileName($name), ->getFiles(), ->hasFile($name), ->hasFiles(), ->getFile($name), ->getFileType($name), ->getFileError($name), ->getFileNames(), ->getFilePath($name), ->getFileSize($name)

Attributes

->getAttribute($name), ->getAttributeNames(), ->hasAttribute($name), ->setAttribute($name, $value), ->removeAttribute($name), ->clearAttributes()

ParameterHolder

->clearParameters(), ->getParameter($name, [$default]), ->getParameterNames(), ->getParameters(), ->hasParameter($name), ->removeParameter($name), ->setParameter($name, $value), ->setParameters($parameters), ->setParameterByRef($name, $value), ->setParametersByRef(&$parameters)

Validators

  • NumberValidator [max], [max_error], [min], [min_error], [nan_error], [type], [type_error]
  • RegexValidator pattern, [match], [match_error]
  • StringValidator [insensitive], [max], [max_error], [min], [min_error], [values], [values_errors]
  • sfEmailValidator [email_error]
  • sfHtmlValidator [html_error]

schema.xml

<?xml version="1.0" encoding="UTF-8"?>
<database name="DATABASE_NAME" defaultIdMethod="native">
 <table name="TABLE_NAME">
   <column name="COLUMN_NAME" [phpName="PHP_NAME"]
     type="(integer|varchar|longvarchar|date|boolean)"
     [required="true"] [defaultValue=""]
     [primaryKey="true"] [autoIncrement="true"] />
  <foreign-key foreignTable="TABLE_BIS_NAME">
   <reference local="id_TABLE_BIS_NAME" foreign="id"/>
  </foreign-key>
 </table>
</database>

Generated object classes

Object.class.php

  • ->get[PHP_COLUMN](), ->set[PHP_COLUMN]($value)
  • ->add[RELATED COLUMN]($obj), ->get[RELATED COLUMN]()
  • ->getByName($name), ->setByName($name, $value)
  • ->save(), ->delete(), ->copy()

ObjectPeer.class.php

$c : Criteria
  • ::doCount($c), ::doSelectOne($c), ::doDeleteAll(), ::doSelect($c)
  • ::retrieveByPK($pk)
  • ::doSelectJoin[JOIN_COLUMN]($c), ::doSelectJoinAll($c)

Criteria

  • ->setLimit($limit)
  • ->setOffset($offset)
  • ->addGroupByColumn($groupBy), ->clearGroupByColumns()
  • ->add(Asc|Desc)endingOrderByColumn($name), ->clearOrderByColumns()

Exemple Action

class mainActions extends sfActions
{
  public function preExecute()
  {
    $this->setCache(2 * 86400, 'Index', 'Show');
    $this->useModels('person', 'company');
    $this->useHelpers('Wiki', 'List');
  }

  public function executeIndex()
  {
    $this->setVar('persons', PersonPeer::doSelect());
    return sfView::SUCCESS;
  }
}

Command line

Administration

  • clear-cache cache erase all
  • sync-prod[-dry] synchronisation (-dry test)

Generation

  • init-project projet creation
  • propel-build-model object model generation
  • propel-generate-crud back-office generation

Template helpers

$options : additional html attributes, in hash or string syntax
Array('class' => 'myclass', 'id' => 12, 'style' => 'width:100px' )
'class=myclass id=12 style=width:100px'

URL

  • url_for($url, [absolute=true])
  • link_to($name, $url, [$options])
$url: module/action?param=value or @rule?param=value

Form

  • form_tag($url, [$options])
  • input_tag($name, [$value], [$options])
  • same for input_hidden_tag, input_password_tag, textarea_tag
  • select_tag($name, [$option_tags], [$options])
  • options_for_select($options, [$selected])
  • input_file_tag($name, [$options])
  • checkbox_tag($name, [$value = 1], [$checked = false], [$options])
  • radiobutton_tag($name, $value, [$checked = false], [$options])
  • submit_tag($value, [$options])

Assets

  • auto_discovery_link_tag([$type], [$options])
  • javascript_tag(S|L|A) by default in js/ and .js
  • image_path($source) by default in images/ and .png
  • image_tag($source, [$options])

I18N

  • __($text, [$culture])

Templates

  • include_partial($name, [$vars]) inclusion template 'name', 'module/name' ou 'global/name'

Text

  • truncate_text($text, $length = 30, $truncate_string = '...')
  • highlight_text($text, $phrase, [$highlighter]) classe 'highlight' par défaut
  • excerpt_text($text, $phrase, $radius = 100, $excerpt_string = '...')
  • simple_format_text($text)
  • auto_link_text($text, $link = 'all')
  • strip_links_text($text)

Date

  • format_date($timestamp, [$culture])
  • distance_of_time_in_words($from_timestamp, $to_timestamp, [$include_seconds])
  • time_ago_in_words($from_timestamp, [$include_seconds])

Partial cache

  • cache($cache_time = 3600)
  • cache_save
    <?php if (!cache()): ?>... HTML ...<?php cache_save() ?><?php endif ?>

Javascript

  • link_to_function($name, $function, [$html_options])
    link_to_function(image_tag("delete"), "if confirm('Really?'){ do_delete(); }")
  • link_to_remote($name, [$options], [$html_options])
  • form_remote_tag([$options])
  • remote_function($options)
  • observe_field($field_id, [$options])
  • observe_form($form_id, [$options])
  • escape_javascript($javascript])

Object

$object represents the object (Propel)
$column represents the column name ($object->get$column())
unique signature: ($object, $column, [$options], [$value]) object_plain, object_textarea_tag, object_image_tag, object_date_tag, object_input_password_tag, object_select_tag, object_input_hidden_tag, object_input_tag, object_checkbox_tag

Tree structure

  • [SF_ROOT_DIR]
    /
  • [SF_APP_DIR]
    apps/
  • x n applications
      [APP]/
  • [SF_MESSAGES_DIR]
       > i18n/
  •    > lib/
  •    > config/
  •    > i18n/
  •    > lib/
  •    > modules/
  • x n modules
          > [MODULE]/
  •        > actions/
  •          > Actions.class.php
  •        > config/
  •        > lib/
  •        > templates/
  •          > IndexSuccess.php
  •        > validate/
  •    > templates/
  •        > layout.php
  •        > error.php
  • batch/
  • [MO_CACHE_DIR]
    cache/
  •  > [APP]/
  •     > [ENV]/
  •       > config/
  •       > template/
  • config/
  •   > build.properties
  •   > rsync_exclude.txt
  •   > schema.xml
  • data/
  •  > sql/
  • doc/
  • [SF_CLASSES_DIR]
    lib/
  •  > model/
  •     > om/
  •       > Base[OBJECT].php
  •       > Base[OBJECT]Peer.php
  •     > [OBJECT].php
  •     > [OBJECT]Peer.php
  • log/
  • test/
  •  > sf/
  • [SF_WEB_DIR]
    web/
  •  > css/
  •  > images/
  •  > js/
  • [SF_UPLOAD_DIR]
     > uploads/
  •  > index.php

Constants

Symfony

  • SF_PROJECT
  • SF_DEBUG
  • SF_DEFAULT_CULTURE
  • SF_TIMEOUT

Criteria

  • EQUAL / NOT_EQUAL
  • GREATER_THAN / LESS_THAN
  • GREATER_EQUAL / LESS_EQUAL
  • LIKE / NOT LIKE / ILIKE / NOT ILIKE
  • IN / NOT IN