Créer un compte ou loggez-vous pour pouvoir ajouter, commenter et noter les snippets.

Navigation

Tags relatifs

my Symfony Plugins

Plugins demos


My bookmarks

Vous pouvez commenter/noter en utilisant le compte anonymous (mot de passe: anonymous)
You can comment/rate using the anonymous account (password: anonymous).

Snippets taggés : "symfony" Snippets taggés : "symfony"

[PHP] Installer XDEBUG sous Wamp - 93 view(s)

http://www.xdebug.org/download.php

Pour savoir la version à utiliser, dans votre phpinfo(), rearder les informations VC6 et thread safe. (*-vc6.dll pour thread safe)

par COil le 2010-06-17, taggé : bug  symfony  wamp  xdebug 

[Symfony 1.2] Form white list function - 771 view(s)

Allow to remove all fields of a form except a given list:

public function unsetAllExcept($fields = array())
{
  foreach($this->getObject()->toArray(BasePeer::TYPE_FIELDNAME) as $key => $val)
  {
    $tmp[] = strtolower($key);
  }
 
  $tmp = array_diff($tmp, $fields);
 
  foreach($tmp as $value)
  {
    unset($this[$value]);
  }
}

Remove created_at, updated_at ...

$this->unsetAllExcept(array('comment'));
par COil le 2009-08-13, taggé : form  security  symfony 
(1 commentaire)

[Symfony 1.2] Autoriser l'envoi de champs additionnels à un formulaire - 1501 view(s)

public function allowExtraFields()
{
  $this->validatorSchema->setOption('allow_extra_fields', true);
}
par COil le 2009-08-13, taggé : form  symfony 
(1 commentaire)

[symfony 1.2] Créer un contexte d'application à partir d'une tâche - 1101 view(s)

$configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
sfContext::createInstance($configuration);
par COil le 2009-06-10, taggé : application  configuration  context  instance  symfony  task 
(1 commentaire)

[symfony] Récupérer la version majeure de symfony utilisée - 499 view(s)

if (defined('SYMFONY_VERSION'))
{
  // symfony 1.1.x or 1.2.x
  $version = explode('.', SYMFONY_VERSION);
  {
    $version = $version[0]. '.'. $version[1];
  }
}
else
{
  $version = '1.0';
}
par COil le 2009-04-06, taggé : symfony  version 
(1 commentaire)

[Symfony 1.2] Récupérer la liste des champs du modèle associés à un formulaire - 611 view(s)

public function getFields()
{
  return array_keys($this->widgetSchema->getFields());
}
par COil le 2009-04-01, taggé : fields  form  model  symfony  widget 
(1 commentaire)

[PEAR] Forcer la version installée de symfony - 386 view(s)

pear install -f symfony/symfony-1.2.4
par COil le 2009-03-24, taggé : pear  php  symfony 
(1 commentaire)

[Eclipse] Forcer et activer l'auto-complétion pour un objet donné - 742 view(s)

Typiquement on peut utiliser ce snippet dans un template symfony, puisque les différentes variables n'y sont pas déclarées. Eclipse ne sait donc pas le type des variables qu'il utilise.

/*@var $ad_base ipAdBase */
par COil le 2009-03-24, taggé : autocompletion  eclipse  symfony  template 
(1 commentaire)

[symfony 1.2] Charger un groupe d'helper depuis une action ou le modèle - 586 view(s)

Donc permet de charger un helper depuis un contexte autre que depuis les templates:

sfProjectConfiguration::getActive()->loadHelpers(array('Url'));

Tip original

par COil le 2009-03-22, taggé : action  configuration  context  helper  symfony 
(1 commentaire)

[Ubuntu] Installer XDebug - 417 view(s)

Sur un Ubuntu 8.10:

$ sudo apt-get install php5-dev
$ sudo pecl install xdebug

Puis ajouter dans le fichier php.ini dans la section de gestion des extensions:

$ sudo updatedb
$ sudo locate xdebug.so

Remplacer avec le bon chemin vers le fichier xdebug.so:

zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so
par COil le 2009-02-25, taggé : debug  php  symfony  tests  ubuntu  xdebug  zend 
(1 commentaire)

[symfony] Noscript "off" in dev with "prod" controller and "on" in prod with the same settings.yml file - 1330 view(s)

[Edit 06/02/09] Enabling the apache mod_rewrite is a little faster than using this snippet. ;)

Well if you are using Windows + Wamp for your dev, the "noscript" setting (settings.yml) does not work well when you are using the prod controller to test your application with you dev computer. (if mod_rewrite is not installed)

So i wanted to deactivate this settings in dev environment with the prod controller and having it on in prod with the prod controller without having 2 different settings.yml files.

So here here a small tip for this:

prod:
  .settings:
    no_script_name:          echo ((isset($_SERVER['HTTP_HOST']) && strstr($_SERVER['HTTP_HOST'], 'dev') ? 'off' : 'on')) . "\n"; ?>
    logging_enabled:        on

This code assumes that your dev url contains "dev" like http://dev.blogsnippets.com.

par COil le 2009-01-19, taggé : dev  noscript  prod  settings  symfony 
(1 commentaire)

[symfony 1.1 /1.2] Fonction updateObject typique pour un formulaire imbriqué - 499 view(s)

Tiré de l'article http://www.miximum.fr/methodes-et-outils/104-mixons-des-formulaires-avec-symfony

public function updateObject()
{
  parent::updateObject();
 
  $address = $this->getObject()->getAddress();
  $values = $this->getValues();
 
  $address->fromArray($values['address'], BasePeer::TYPE_FIELDNAME);
  $address->save();
 
  return $this->object;
}
par COil le 2008-11-04, taggé : embed  form  object  symfony 
(1 commentaire)

[symfony] Joomla to symfony mini-bridge [EN] (deprecated) - 1659 view(s)

This snippet is deprecated, please use the sfJoomla15BridgePlugin plugin witch works with the new 1.5 Joomla and the symfony 1.2 version.


This tutorial is for the 0.7.0 version please check the Symfony Wiki for 0.8.0 doc until i can update this tutorial.

Intro

Well, in fact i have taken the idea from what has already been done with cakePHP, you can find the original blog articles here (1) and thanks to the authors for the work. Now a full project for this purpose is available for cakePHP it is called Jake

(1)

1 - Installation

Versions used :

Now you must have a sfJoomlaBridge dir in your plugins dir and a com_symfony dir in /web/components

The Symfony application is built as usual and the Joomla installation must be achieved in the /web of the Symfony project.

2 - Configuration

Joomla component

Open symfony.html.php, line 8 modify the name of Symfony controller file (frontoffice.php by default). Take care to use a production controller, because we should't have any debug information

Un-comment line 34 with file_get_contents if you don't have curl installed on you web server, and comment the curl related line above.

In index.php of Joomla

before (near line 114)

// mainframe is an API workhorse, lots of 'core' interaction routines
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();

add

//Before Joomla initialize its mainframe, lets play…
// check missing component — added before $mainframe is being initialized
//##########################
if (!file_exists($mosConfig_absolute_path . '/components/'. $option )) { 
    $option = 'com_symfony';  
    //set component to com_cake if a controller is not found.
}

Symfony

Clear the cache

> symfony clear cc

There is nothing really specific except the new link helper to use in the templates. To use the Joomla helpers :

<?php use_helper('Joomla'); ?>

You can also modify the index file of Joomla application in plugins/sfJoomlaBridge/config/config.php

3 - Use

Creation of Symfony page

We are going to do a page (module/action) whitch will be called by Joomla with the help of its new component.


sf actions creation

Nous are going to create 2 actions, 1 basic (static content) and one with the users list of Joomla administration

index/actions/actions.class.php

/**
     * Executes index action
     */
    public function executeIndex()
    {
    }
 
    /**
     * Test Joomla/Symfony integration
     * 
     * @author lvernet
     * @since  26 feb 2007
     */
    public function executeUsers()
    {
        $this->users = JosUsersPeer::doSelect(new Criteria());
    }


sf view creation

The plugin introduce a new helper link_to_joomla that allows to do link to others symfony pages but with staying in the Joomla application.

templates/usersSuccess.php

<?php use_helper('Joomla'); ?>
 
<h1>Joomla Users list</h1>
<p>This list is retrieved with the help of the ORM of Symfony</p>

  <?php if ($users): ?>   <table class="contenttoc"> <thead> <th>Id</th> <th>Name</th>   <th>User name</th> </thead> <?php foreach($users as $user): ?> <tr> <td><?php echo $user->getId(); ?></td> <td><?php echo $user->getName(); ?></td> <td><?php echo $user->getUsername(); ?></td> </tr> <?php endforeach; ?> </table> <?php endif; ?>  
<?php echo link_to_joomla('Back to index', 'index/index', array('query_string' => 'param1=chat&param2=rat')); ?>

templates/indexSuccess.php

<?php use_helper('Joomla'); ?>
 
<h1>This content is provided through Symfony framework.</h1>
 
<?php echo image_tag('powered_by.png') ?> &&
<?php echo image_tag('http://www.symfony-project.com/images/symfony_logo.gif') ?>
 

<?php echo link_to_joomla('Users list', 'index/users'); ?>

Now we must desactivate the view's layout, because we don't want it as we will use the one of Joomla.

In index/config/view.yml :

indexSuccess:
  has_layout:    off
 
usersSuccess:
  has_layout:    off


Call and test it in Joomla

We can now call our sf pages in Joomla, link are formed as following : index.php?option=index&task=users

Go to the url: http://projectroot/index.php?option=index&task=users, the users list is displayed and you have a link to go to the index page (link created with the joomla helper)

/!\ Be carefull, the option param should not match the name of a Joomla component /!\

4 - Demo

Has to be updated for symfony 1.1

5 - Conclusion

I made this quiet quickly, of course there are lot of things to do to have a perfect integration as the Jake project does it for cakePHP. If someone is interested, feel free to take the code and contribute, it would be nice.

COil :)

par COil le 2008-10-19, taggé : bridge  joomla  plugin  symfony 
(4 commentaires)

[symfony plugins] Batch typique pour le plugin sfDB4toPropelPlugin - 321 view(s)

db4.sh

#!/bin/bash
 
SYMFONY=`dirname $0`"/symfony"
 
SEP="==========================================================================="
echo "Rebuilding full database from DB4 schema and fixtures"
 
echo $SEP
echo "Converting DB4 schema for propel..."
$SYMFONY propel:db4-to-propel frontend --env=cli --debug=1 --file_dir=/doc/database --file=snippets_db4.xml --output_dir=/config --output=snippets_schema --package=lib.model.snippets
 
echo $SEP
echo "Rebuilding all tables & ORM classes..."
$SYMFONY propel:build-all-load frontend
 
echo $SEP
echo "Clearing the cache..."
$SYMFONY cc
 
echo $SEP
cd ..
echo "JOB's DONE ! ;)"
par COil le 2008-10-07, taggé : batch  db4  plugin  propel  symfony 
(1 commentaire)

[symfony 1.1] Récupérer l'environnement en cours - 186 view(s)

<?php if (sfConfig::get('sf_environment') != 'dev'): ?>
par COil le 2008-10-07, taggé : config  dev  env  prod  symfony 
(1 commentaire)

[symfony 1.0 / 1.1] Renaming an uploaded file with an admin_input_file_tag - 747 view(s)

generator:
  class:              sfPropelAdminGenerator
  param:
    model_class:      Example
    theme:            default
 
    edit:
      fields:
        pdf:
          type:          admin_input_file_tag
          upload_dir:    pdf_files
          filename:      pdf_%%id%%
          params:        include_link=user_pics include_remove=true
par COil le 2008-10-05, taggé : admingenerator  file  helper  symfony  upload 
(1 commentaire)

[Symfony 1.1] Récupérer le numéro de version de symfony - 143 view(s)

Utiliser la constante SYMFONY_VERSION:

<?php echo link_to('Powered by symfony '. SYMFONY_VERSION, 'http://www.symfony-project.com'); ?>
par COil le 2008-10-01, taggé : constant  symfony  version 
(1 commentaire)

[symfony 1.1] Fichier ProjectConfiguration.php typique pour une installation symfony en svn external - 583 view(s)

<?php
 
require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();
 
class ProjectConfiguration extends sfProjectConfiguration
{
}
?>
 
par COil le 2008-09-29, taggé : config  external  project  svn  symfony 
(1 commentaire)

[symfony 1.1] Classe de formulaire typique - 687 view(s)

<?php
 
/**
 * Form to add a classified ad.
 * 
 * @author loic.vernet
 * @since  7 august 08
 *
 * @package    form
 */
 
class qbNewThreadForm extends qbThreadForm 
{
  // Default mask to create fields names
  public static $main_fields_name = 'qb_thread';
 
  // Default labels
  protected $labels = array(
 
    // Thread
    'title'         => 'Sujet',
    'category_id'   => 'Forum',
 
    // Contact form
    'qb_post'       => 'Post',
  );
 
  // Default fields to keep
  protected $fields_to_keep = array(
 
    // Thread
    'id',
    'category_id',
 
    // Post
    'qb_post',
  );
 
  // Liste of field that can't be modified by direct input values
  protected static $protected_fields = array(
  );
 
  /**
   * Configuration of form.
   */
  public function configure()
  {
    // Build widgets
    $this->setWidgetOptions();
 
    // Set wdigets
    $this->processWidgets();
 
    // Set validators    
    $this->processValidators();
 
    // Embed other forms
    $this->embedForms();
  }
 
  /**
   * Set generic options for widgets.
   * 
   * @author loic.vernet
   * @since
   */
  protected function setWidgetOptions()
  {
    // name format
    $this->widgetSchema->setNameFormat(self::$main_fields_name. '[%s]');
 
    // Set labels    
    $this->setLabels($this->labels);
 
    // Allow extra fields for all forms
    $this->allowExtraFields();
  }
 
  /**
   * set all widgets.
   * 
   * @author loic.vernet
   * @since
   */
  public function processWidgets()
  {
    $this->removeAllFieldsExcept($this->fields_to_keep);
 
    $this->widgetSchema['category_id'] = new sfWidgetFormPropelSelect(
      array(
        'model'     => 'qbCategory', 
        'add_empty' => false,
        //'criteria'  => ipAdBasePeer::getCategoriesCriteria()
    ));
 
    $this->widgetSchema['title'] = new sfWidgetFormInput();
  }  
 
  /**
   * Set all validators.
   * 
   * @author loic.vernet
   * @since 
   */
  public function processValidators()
  {
    $this->validatorSchema['category_id'] = new sfValidatorString(
        array('required' => true),
        array('required' => 'Veuillez choisir un forum')
    );
 
    $this->validatorSchema['title'] = new sfValidatorString(
        array('required' => true),
        array('required' => 'Veuillez choisir un titre pour le sujet')
    );
  }
 
  /**
   * Embed other forms to the current form.
   * 
   * @author loic.vernet 
   * @since 
   */
  protected function embedForms()
  {
  }
}
par COil le 2008-09-29, taggé : class  field  form  labels  symfony  validator  widget 
(1 commentaire)

[symfony 1.1] Template de formulaire typique - 385 view(s)

[Edit 20081017: Ajout affichage des erreurs globales]

<?php /*@var $form qbNewThreadForm */ ?>
 
<?php qb_forum_add_style(); echo qb_include_resources(); ?>
 
<h1><?php echo $forum->getTitle(); ?></h1>
<h2>Création d'une nouvelle discussion</h2>
 
<?php include_partial('forum/breadcrumb', array('forum_root' => $forum)); ?>
 
<?php if ($form->hasGlobalErrors()): ?>
  <?php echo $form->renderGlobalErrors(); ?>
<?php endif; ?>
 
<div class="thread-edit">
 
  <div id="thread-edit-bb-tools" class="cadre">
    Outils de mise en page
  </div>
 
  <div id="thread-edit-title" class="cadre">
    <?php echo $form['title']->renderLabel(); ?>
    <?php echo $form['title']->renderError(); ?>
    <?php echo $form['title']->render(); ?>
  </div>
 
  <div id="thread-edit-forum" class="cadre">
    <?php echo $form['category_id']->renderLabel(); ?>
    <?php echo $form['category_id']->renderError(); ?>
    <?php echo $form['category_id']->render(); ?>
  </div>
 
  <div id="thread-edit-bb-code" class="cadre">
  </div>
 
  <div id="thread-edit-files" class="cadre">
    Fichiers joints
  </div>
 
  <div id="thread-edit-options" class="cadre">
    Options
  </div>
 
  <div id="thread-edit-tone" class="cadre">
    Ton du message
  </div>
 
</div>
 
<?php // echo $form; ?>
par COil le 2008-09-29, taggé : form  symfony  template  view  widget 
(1 commentaire)

[symfony 1.1] Gestion de formulaire typique - 281 view(s)

  /**
   * Ad publication form for the users.
   * 
   * @todo : Eventually save posted datas in session to be able to retrieve
   * values even when changer the main category of the ad. 
   */
  public function executePost($request)
  {
    // Default ad_base object
    $ad_base = $this->getAdBaseOrCreate($request);
 
    // Secure edition
    if (!$ad_base->isNew())
    {
      $this->forward404Unless($ad_base && ($ad_base->getIpAdContact()->getCreatedBy() == $this->getUser()->getId()));
    }
 
    // Form and params
    $ip_ad_base_post = $request->getParameter('ip_ad_base');
    $form = new ipAdPostForm($ad_base, $ip_ad_base_post);    
    $category_refresh = isset($ip_ad_base_post['category_refresh']) ? $ip_ad_base_post['category_refresh'] : 0;
 
    // Refresh category and save submitted form values (without input validation)
    if ($category_refresh)
    {
      $ip_ad_base_post['category_refresh'] = 0;
      $form->setDefaults($ip_ad_base_post);
    }
 
    // Post and save form
    if (!$category_refresh && $this->isPost() && $ip_ad_base_post)
    {
      $form->bind($ip_ad_base_post, $request->getFiles('ip_ad_base'));
 
      if ($form->isValid())
      {
        $form->save();
 
        // Photo deletion
        if ($delete_flag = $form->hasDeletePhotoFlag() && !$ad_base->isNew())
        {
          $ad_base->deletePhoto();
        }
 
        // Photo upload
        if (!$delete_flag && $form->hasPhoto())
        {
          $form->saveAndUploadPhoto($request);
        }
 
        // Send email to administrator if it is a new ad to validate
        //if ($form->getObject()->isNew())
        //{
          //ipTools::dump('send email', 'send email', 1);
          $form->getObject()->notifyWebmasterForNewAd();
        //}
 
        // Redirect
        $this->getUser()->addNotice('Votre annonce a été sauvegardée, elle sera visible dès qu\'elle aura été validée par un administrateur');
        $this->redirect('iposte_user/adsList');
      }
    }
 
    // Pass form to template
    $this->form = $form;
  }
 
par COil le 2008-09-29, taggé : action  form  post  symfony 
(1 commentaire)

[symfony 1.1] Créer un handler de config yml basique pour un plugin - 309 view(s)

Permet de loader un yml dans le plugin avec la possibilité de l'overwritter s'il ce meme fichier est present dans l'application.

Dans /plugin/myPlugin/config faire un fichier config_handlers.yml

config/sfBBCodeParser.yml:
  class: sfSimpleYamlConfigHandler
 

Donc ici, on va preparer une pre-compilation de ce fichier de config dans le cache, mais il ne sera pas inclut par défaut. Il faut donc l'apeller a partir du cache config des lors qu'on en a besoin.

/**
 * Test and include the default sfBBCodeParserPlugin config if it doesn't exists.
 * 
 * @author loic.vernet
 * @since  30 july 08
 * 
 * @param Array $config
 */
function bb_check_and_include_config($config)
{
  if (!$config)
  {
    // Include config file from generated cache  
    $bb_config_file = include(sfContext::getInstance()->getConfigCache()->checkConfig(sfBBCodeParserConfig::getConfileFilePattern()));
    sfConfig::set(sfBBCodeParserConfig::getNamespace(), $bb_config_file);
  }
 
  return $config['config'];
}
 

Ici j'ai ajouté une classe d'abstraction pour gérer la configuration du plugin.

par COil le 2008-09-29, taggé : cache  config  handler  symfony  yml 
(1 commentaire)

[symfony 1.0] Supprimer le bouton create dans la liste d'un admin gen - 148 view(s)

      actions: { }
 
par COil le 2008-09-29, taggé : action  admingenerator  create  symfony  yml 
(1 commentaire)

[symfony 1.1 / 1.2] : Validation OR sur 2 champs différents - 813 view(s)

    // Check category or query
    $v = new sfValidatorCallback(array(
      'callback' => array($this, 'checkCategoryOrQuery')
    ,) ,
    array(
      'invalid'  => 'Veuillez choisir une rubrique ou un mot clé'
    ));
 
    $this->validatorSchema->setPostValidator($v);

et le callback qui va bien:

  /**
   * Check if a category or a keyword has been set.
   *
   * @param sfValidator $validator
   * @param Array $value Form values
   * @param Array $arguments  Validation arguments
   * 
   * @return mixed
   */
  public function checkCategoryOrQuery($validator, $value, $arguments)
  {
    if (empty($value['category_id']) && empty($value['nature_id']))
    {
      throw new sfValidatorError($validator, 'invalid');
    }
 
    return $value;
  }
par COil le 2008-09-29, taggé : callback  form  symfony  validation  validator 
(3 commentaires)

[MySQL] Nommer index et clés étrangères pour les scripts de migration symfony - 157 view(s)

Permet de pouvoir faire des scripts de migration fiables puisque les noms de clé et d'index seront les mêmes sur tout les serveurs.

<?php
 
/**
 * Migration qui ajoute les colonne permettant d'effectuer la localisation
 * d'un membre comme les bars.
 */
 
class Migration024 extends sfMigration 
{
 
  /**
   * Up
   */
  public function up() 
  {
    $this->diag('Debut UP 24');
 
    // Table user_profile
    $this->diag('MAJ champs user_profile');
    $this->executeSQL("
ALTER TABLE `user_profile` 
ADD `country_code` varchar(2) default NULL COMMENT 'Code du pays' AFTER `personal_url` ,
ADD `zone_id` int(11) default NULL COMMENT 'Departement du membre' AFTER `country_code` ,
ADD `lat` decimal(12,9) default NULL COMMENT 'Latitude' AFTER `zone_id` ,
ADD `lng` decimal(12,9) default NULL COMMENT 'Longitude' AFTER `lat` ,
ADD `latlng_precision` int( 11 ) default NULL COMMENT 'Precision de la localisation' AFTER `lng`;
    ");
 
    // ALTER TABLE `user_profile` ADD FOREIGN KEY ( `zone_id` ) REFERENCES `zone` (`id`) ON DELETE SET NULL;
    // Ajout des cle etrangeres
    $this->diag('MAJ contraintes user_profile');
    $this->executeSQL("    
ALTER TABLE `user_profile`
 ADD CONSTRAINT `zone_id_FK`
 FOREIGN KEY `zone_id_idx` ( `zone_id` )
 REFERENCES `zone` (`id`)
 ON DELETE SET NULL;
");
 
  }
 
  /**
   * Down
   */
  public function down() 
  {
    $this->diag('Debut DOWN 24');
 
    // Suppr
    $this->diag('SUPPRESSION contraintes champs a supprimer');
 
    $this->executeSQL("
      ALTER TABLE `user_profile`
      DROP FOREIGN KEY `zone_id_FK`
    ");
 
    $this->executeSQL("
      DROP INDEX `zone_id_idx` ON `user_profile` 
    ");
 
    $this->diag('SUPPRESSION champs user_profile');
    $this->executeSQL("
ALTER TABLE `user_profile`
  DROP `country_code`,
  DROP `zone_id`,
  DROP `lat`,
  DROP `lng`,
  DROP `town`,
  DROP `latlng_precision`;    
    ");
  }
}
 

Ou en décomposant la création des index/clés

<?php
 
/**
 * Migration qui ajoute les colonne permettant d'effectuer la localisation
 * d'un membre comme les bars.
 */
 
class Migration024 extends sfMigration 
{
 
  /**
   * Up
   */
  public function up() 
  {
    $this->diag('Debut UP 24');
 
    // Table am_user_profile
    $this->diag('MAJ champs user_profile');
    $this->executeSQL("
ALTER TABLE `user_profile` 
ADD `country_code` varchar(2) default NULL COMMENT 'Code du pays' AFTER `personal_url` ,
ADD `lat` decimal(12,9) default NULL COMMENT 'Latitude' AFTER `country_code` ,
ADD `lng` decimal(12,9) default NULL COMMENT 'Longitude' AFTER `lat` ,
ADD `latlng_precision` int( 11 ) default NULL COMMENT 'Precision de la localisation' AFTER `lng`;
    ");
 
    // ALTER TABLE `am_user_profile` ADD FOREIGN KEY ( `zone_id` ) REFERENCES `am_zone` (`id`) ON DELETE SET NULL;
    // Ajout des cle etrangeres
    /*
    $this->diag('MAJ conrtaintes am_user_profile');
    $this->executeSQL("    
ALTER TABLE `user_profile`
 ADD CONSTRAINT `zone_id_FK`
 FOREIGN KEY `zone_id_idx` ( `zone_id` )
 REFERENCES `am_zone` (`id`)
 ON DELETE SET NULL;
");
  */
    $this->diag('CREATION table am_user_zone');
    $this->executeSQL("        
CREATE TABLE `user_zone` (
  `id` int(11) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `zone_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;    
");
 
/*
  KEY `user_zone_FI_1` (`user_id`),
  KEY `user_zone_FI_2` (`zone_id`)
  ALTER TABLE `user_zone` ADD INDEX ( `user_id` )  
*/
 
    $this->diag('MAJ conrtaintes am_user_zone');
    $this->executeSQL("
ALTER TABLE `user_zone` 
ADD INDEX `user_zone_FI_1` ( `user_id` )         
    ");
    $this->executeSQL("     
ALTER TABLE `user_zone` 
ADD FOREIGN KEY `user_zone_FK_1` ( `user_id` ) 
REFERENCES `sf_guard_user` (`id` ) ON DELETE CASCADE;
");
 
    $this->executeSQL("
ALTER TABLE `user_zone` ADD INDEX `am_user_zone_FI_2` ( `zone_id` )         
    ");
    $this->executeSQL("     
ALTER TABLE `user_zone` 
ADD FOREIGN KEY `user_zone_FK_2` ( `zone_id` ) 
REFERENCES `zone` (`id` ) ON DELETE CASCADE;
");
 
  }
 
  /**
   * Down
   */
  public function down() 
  {
    $this->diag('Debut DOWN 24');
 
    // Suppr
    $this->diag('SUPPRESSION contraintes champs a supprimer');
 
    /*
    $this->executeSQL("
      ALTER TABLE `user_profile`
      DROP FOREIGN KEY `zone_id_FK`
    ");
 
    $this->executeSQL("
      DROP INDEX `zone_id_idx` ON `user_profile` 
    ");
    */
 
    $this->diag('SUPPRESSION champs user_profile');
    $this->executeSQL("
ALTER TABLE `user_profile`
  DROP `country_code`,
  DROP `lat`,
  DROP `lng`,
  DROP `latlng_precision`;    
    ");
 
    $this->diag('SUPPRESSION table user_zone');
    $this->executeSQL("DROP TABLE IF EXISTS `user_zone`");
  }
}
 
par COil le 2008-09-29, taggé : constraint  index  migration  mysql  plugin  propel  symfony 
(1 commentaire)

[symfony 1.0] Retourner du text de partial à partir de l'action - 174 view(s)

Typiquement pour une action Ajax:

    if (!$this->user)
    {
      sfLoader::loadHelpers('Partial');
      return $this->renderText(get_partial('member/rdv/list'));
    }
 
par COil le 2008-09-29, taggé : action  ajax  helper  partial  symfony 
(1 commentaire)

[symfony] Ajouter du cache client html - 154 view(s)

    if ($this->getRequest()->isXmlHttpRequest())
    {
      $this->getResponse()->addCacheControlHttpHeader('max_age=3600');
      $this->response->setHttpHeader('Pragma', null, false);
      $timestamp = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
      $this->getResponse()->setHttpHeader('Expires', $this->getResponse()->getDate($timestamp));
    }
 
par COil le 2008-09-29, taggé : ajax  cache  date  header  html  symfony 
(1 commentaire)

[symfony 1.0] Get the current action instance - 357 view(s)

$action_instance = sfContext::getInstance()->getController()->getActionStack()->getFirstEntry()->getActionInstance();
 
par COil le 2008-09-29, taggé : action  context  instance  symfony 
(1 commentaire)

[symfony 1.0] Remote function sur un select tag - 120 view(s)

          <?php echo select_tag('per_page', options_for_select(MessageSent::getMessagesPerPageComboBox(), $sf_user->getMessagesPerPage()), array(
            'id'       => 'sgMessagesPP',
            'style'    => 'margin: 0 0 0 5px;',
            'class'    => 'floatL',
            'onchange' => remote_function(array(
                'update'  => 'messages_list',
                'url'     => '@messages_per_page',
                'with'    => "'count=' + this[this.selectedIndex].value + '&message_type_id=' + $message_type_id",
                'loading' => "replaceContentWithIndictator('messages_list');"
            )),
          )); ?>
 
par COil le 2008-09-29, taggé : ajax  remote  select  symfony 
(1 commentaire)

[symfony] Extraire une table par batch d'un schema.xml - 133 view(s)

  // Delete external tables from plugin schema (already defined in another schema (main or other plugin))
  if (DCMC_EXTERNAL_TABLE) {
    foreach (explode(',', DCMC_EXTERNAL_TABLES) as $external_table) {
      $reg_exp = '/(<table name="'. $external_table. ')(((.)*(\s)*)*?)(<\/table>)/';
      $xmlstr = preg_replace($reg_exp, '', $xmlstr);
    }
  }
 
par COil le 2008-09-29, taggé : propel  regexp  schema  symfony  xml 
(1 commentaire)

[symfony 1.0] Débugger un email rapidement à la volée - 215 view(s)

      $order = OrderPeer::doSelectOne(new Criteria());
      $shop_order = $order->getShopOrders();
      $shop_order = $shop_order[0];
 
//      goTools::dump($order, '$order', 0);
//      goTools::dump($shop_order, '$shop_order', 1);
 
      sfContext::getInstance()->getRequest()->setAttribute('client',     $order->getClient($con), 'mail');
      sfContext::getInstance()->getRequest()->setAttribute('order',      $order,                  'mail');
      sfContext::getInstance()->getRequest()->setAttribute('shop_order', $shop_order,   'mail');
      sfContext::getInstance()->getRequest()->setAttribute('shop',       $shop_order->getShop($con),   'mail');
      sfContext::getInstance()->getLogger()->debug(
          sfContext::getInstance()->getController()->sendEmail('goMail', 'sendOrderPaidToShop')
      );
 
par COil le 2008-09-29, taggé : debug  email  plugin  symfony 
(1 commentaire)

[symfony 1.0] Utiliser la même session pour tout les sous-domaines - 333 view(s)

I had to inherit from sfSessionStorage to make it work.. Also, I just couldn't get it to work with domain limitations in that Explorer seems to send the cookies of the main domain to all subdomains. So I had to use a subdomain-based session name Here is the code bit, at the end it came out pretty simple, but I used hours trying to get it to work with domain limiting the cookies

class mySessionStorage extends sfSessionStorage
{
  /**
   * This override sets the exact (sub)domain for session cookie and then initializes this Storage instance.
   *
   * @param sfContext A sfContext instance
   * @param array   An associative array of initialization parameters
   *
   * @return boolean true, if initialization completes successfully, otherwise false
   *
   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage
   */
  public function initialize($context, $parameters = null)
  {
//    $parameters['session_cookie_domain'] = $_SERVER['SERVER_NAME']; // This doesn't work
    $parameters['session_name'] = 'symfony_'.$_SERVER['SERVER_NAME']; // This works
    // initialize parent
    parent::initialize($context, $parameters);
  }
 
}
 
par COil le 2008-09-29, taggé : domain  server  session  storage  subdomain  symfony 
(1 commentaire)

[symfony 1.0] Récupérer directement la valeur brute d'une variable de template échappée - 130 view(s)

<?php $order = $order->getRawValue(); ?>
 
par COil le 2008-09-29, taggé : escaping  raw  symfony  template  view 
(1 commentaire)

[symfony] Désactiver l'auto-start de session - 175 view(s)

in factories.yml file add a auto_start entry like this:

all:
   storage:
     param:
       auto_start: false
 
par COil le 2008-09-29, taggé : config  session  start  storage  symfony  yml 
(1 commentaire)

[symfony 1.0] Récupérer la valeur brute d'un champ échappé dans un template - 191 view(s)

$form_ajax_options = $sf_data->get('form_ajax_options', ESC_RAW);
par COil le 2008-09-29, taggé : escaping  field  form  security  symfony  template  value 
(1 commentaire)

[symfony 1.0] Restreindre la période d'un object_select_date - 138 view(s)

Donc pour un contrôle non riche, n'utilisant pas le calendrier.

<?php echo go_row_input('born_at', __('Date de naissance :'),
            object_input_date_tag($client, 'getBornAt', 'year_start=1920 year_end='.date('Y'))) ?>
par COil le 2008-09-29, taggé : date  helper  object  rich  select  symfony  year 
(1 commentaire)

[symfony] Accéder à la session sans namespace - 108 view(s)

$storage = sfContext::getInstance()->getStorage();
$storage->write('test', 1);
//$_SESSION['test'] = 1;
 
par COil le 2008-09-29, taggé : namespace  session  storage  symfony 
(1 commentaire)

[symfony] Rafraîchissement de div en remote call avec des slots - 250 view(s)

<?php slot('search-nb-results'); ?>
  Element.update('search-nb-results', '<?php echo $pager->getNbResults(); ?>');
  Element.update('search-nb-results-offers', '<?php echo $count_offers; ?>');
<?php end_slot(); ?> 
<?php echo javascript_tag(get_slot('search-nb-results')); ?>
 

Avec echappage du js:

    <?php // Maj javascript par slot  ?>
    <?php $slot_name = 'old_match_bar_'. $old_bar_match_id; ?>
    <?php slot($slot_name); ?>
 
      <?php $html = escape_javascript(get_component('member_match', 'barSummaryLeft', array(
        'match_bar_id' => $old_bar_match_id,
      ))); ?>
 
      Element.update('membres-going-matchbar<?php echo $old_bar_match_id; ?>', '<?php echo $html; ?>');
 
    <?php echo javascript_tag(get_slot($slot_name)); ?>
 
par COil le 2008-09-29, taggé : ajax  div  remote  slot  symfony  update 
(1 commentaire)

[symfony 1.0] Creer un lien vers une popup et modifer sa taille - 238 view(s)

<?php echo link_to(__('(code phpbb activé)'), 'http://www.phpbb.com/support/documentation/2.0/#section4_2_5', array('popup' => array(__('Code phpBB'), 'width=750,height=400,left=0,top=0,scrollbars=1'))); ?>
 

== Liste des options

The parameters  URL, name, features, replace have the following meaning:
URL     String specifying the location of the Web page to be displayed in the new window. If you do not want to specify the location, pass an empty string as the URL (this may be the case when you are going to write some script-generated content to your new window).
name    String specifying the name of the new window. This name can be used in the same constructions as the frame name provided in the frame tag within a frameset <FRAME NAME=name ...>. For example, you can use hyperlinks of the form <a target=name href="page.htm">, and the hyperlink destination page will be displayed in your new window.
 
If a window with this name already exists, then window.open() will display the new content in that existing window, rather than creating a new one.
features    An optional string parameter specifying the features of the new window. The features string may contain one or more feature=value pairs separated by commas.
replace     An optional boolean parameter. If true, the new location will replace the current page in the browser's navigation history. Note that some browsers will simply ignore this parameter.
 
The following features are available in most browsers:
toolbar=0|1     Specifies whether to display the toolbar in the new window.
location=0|1    Specifies whether to display the address line in the new window.
directories=0|1     Specifies whether to display the Netscape directory buttons.
status=0|1  Specifies whether to display the browser status bar.
menubar=0|1     Specifies whether to display the browser menu bar.
scrollbars=0|1  Specifies whether the new window should have scrollbars.
resizable=0|1   Specifies whether the new window is resizable.
width=pixels    Specifies the width of the new window.
height=pixels   Specifies the height of the new window.
top=pixels  Specifies the Y coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)
left=pixels     Specifies the X coordinate of the top left corner of the new window. (Not supported in version 3 browsers.)
par COil le 2008-09-29, taggé : javascript  link  popup  symfony 
(1 commentaire)

[symfony 1.0] Récupérer la configuration de sécurité d'un module à partir d'une action - 162 view(s)

$security = $this->getSecurityConfiguration();
 
par COil le 2008-09-29, taggé : config  security  symfony  yml 
(1 commentaire)

[symfony 1.0] Appeler une remote function après modification d'une combobox - 485 view(s)

'onchange' =>
                 remote_function(array(
                   'update' => 'item_domain',
                   'url' => 'list/subdomain',
                   'with' => "'id=' + this.options[this.selectedIndex].value"
                 ))
par COil le 2008-09-29, taggé : ajax  prototype  symfony 
(3 commentaires)

[symfony 1.0] Validation avec un fichier de validateurs externes - 151 view(s)

fillin:
  enabled:      on
  param:
    id:         seller_stockcreate_form
 
fields:
  shop_product{quantity}:
    required:
      msg:                 Vous devez selectionner une quantité
    itemQuantityValidator:
 
  shop_product{price}:
    required:
      msg:                 Vous devez entrer un prix
    shopProductPriceValidator:
 
# Inclusion de l'ensemble des validateurs definis pour le site
<?php include('validate/_validators.yml'); ?>
par COil le 2008-09-29, taggé : config  symfony  validation  validator 
(1 commentaire)

[symfony errors] Page blanche même en dev lors de la construction d'une requête par criterion - 231 view(s)

/!\ Les fonctions de criterion n'acceptent que des autres criterions en parametre /!\

/!\ Appel d'une methode doSelect sans passer de criteria /!\

/!\ Passage d'une valeur nulle ou d'un objet quelquonque a place d'un criteria /!\

par COil le 2008-09-29, taggé : criteria  criterion  error  mysql  propel  sferrors  symfony 
(1 commentaire)

[symfony] Récupérer une date au format court indépendemment de la culture - 143 view(s)

$value = $dateFormat->format($specialoffer_form['begin_at'], 'I', $dateFormat->getInputPattern('d'));
 
par COil le 2008-09-29, taggé : culture  date  format  symfony 
(1 commentaire)

[symfony] Encapsulation d'ordres SQL dans un bloc try/catch avec commit et rollback - 256 view(s)

// Debut de la transaction
      $con = Propel::getConnection();
      $con->begin();      
      try
      { 
        $this->shop_ribs->saveShopRibsFromRequest($shop_ribs_form);
        $this->shop->setShopRibs($this->shop_ribs);
        $this->shop->save();
        $con->commit();
      }
      catch (Exception $e)
      {
        $con->rollback();
        $this->getRequest()->setError('error', $this->getContext()->getI18N()->__('Une erreur est survenue pendant l\'enregistrement, veuillez essayer d\'ici quelques minutes.'));
      }
 
par COil le 2008-09-29, taggé : catch  mysql  propel  symfony  try 
(1 commentaire)

[symfony] Récupérer un paramètre flash independamment du contexte - 119 view(s)

sfContext::getInstance()->getController()->getActionStack()->getFirstEntry()->getActionInstance()->getFlash('notice')
 
par COil le 2008-09-29, taggé : context  controller  fash  symfony 

[Symfony] Choix multiple pour un requirement sans regexp - 382 view(s)

page:
  url: /:sf_culture/:page
  requirements: { sf_culture: (?:fr|en|de) }
  params: ...
 
par COil le 2008-09-29, taggé : config  routing  symfony 
(1 commentaire)

[symfony] Générer une url independemment du contexte - 149 view(s)

$url=sfContext::getInstance()->getController()->genUrl($uri);
 
par COil le 2008-09-29, taggé : context  controller  symfony  url 

[symfony] Levée d'une exception avec traduction du message d'erreur - 104 view(s)

throw new exception(sfContext::getInstance()->getI18N()->__('Aucun template defini par défaut, vérifier la table Templates'));
 
par COil le 2008-09-29, taggé : error  exception  i18n  symfony 

[Symfony] Inclure un partial à partir d'un sous repertoire - 133 view(s)

<?php include_partial('shop/partials/navigation', array('shop' => $shop)) ?>
 
par COil le 2008-09-29, taggé : file  partial  symfony  template  view 

[symfony 1.0] Fichier de validation typique - 352 view(s)

methods:
  post:
    - "user_profile{login}"
    - "user_profile{password}"
    - "user_profile{check_password}"
    - "user_profile{email}"
    - "user_profile{civility}"
    - "user_profile{first_name}"
    - "user_profile{last_name}"
    - "user_profile{birth_date}"
    - "user_profile{address}"
    - "user_profile{postal_code}"
    - "user_profile{town}"
    - "captcha"
    - "user_profile{is_newsletter_subscribed}"
    - "user_profile{is_partners_subscribed}"
    - "user_profile{photo}"
    - "user_profile{personal_url}"
 
fillin:
  enabled: true
  param:
    name: form_register_member
 
names:
  user_profile{login}:
    required:      Yes
    required_msg:  le login est obligatoire
    validators:    [usernameValidator, loginValidator]
 
  user_profile{password}:
    required:      Yes
    required_msg:  le mot de passe est requis
    validators:    passwordValidator
 
  user_profile{check_password}:
    required:     Yes
    required_msg: La confirmation du mot de passe est obligatoire 
    validators:   passwordValidator
 
  user_profile{email}:
    required:      Yes
    required_msg:  l'email est obligatoire
    validators:    [emailValidator, mailuniqValidator]
 
  user_profile{civility}:
    required:      Yes
    required_msg:  veuillez choisir votre civilité
 
  user_profile{first_name}:
    required:      Yes
    required_msg:  le prénom est obligatoire
    validators:    usernameValidator
 
  user_profile{last_name}:
    required:      Yes
    required_msg:  le nom est obligatoire
    validators:    usernameValidator
 
  user_profile{birth_date}:
    required:      Yes
    required_msg:  le nom est obligatoire
    validators:    usernameValidator     
 
  user_profile{address}:
    required:     Yes
    required_msg: l'adresse est obligatoire
 
  user_profile{postal_code}:
    required:      Yes
    required_msg:  le code postal est obligatoire
    validators:    zipcodeValidator

  user_profile{town}:
    required:     Yes
    required_msg: la ville est obligatoire
 
  captcha:
    required:      Yes
    required_msg:  vous devez recopier le code
    validators:    captchaValidator
 
  user_profile{is_newsletter_subscribed}:
    required:     no
 
  user_profile{is_partners_subscribed}:
    required:     no
 
  user_profile{photo}:
    required:     no
 
  user_profile{personal_url}:
    required:     no
 
passwordValidator:
  class:          sfCompareValidator
  param:
    check:          passconf
    compare_error:  les mots de passe ne correspondent pas
 
loginValidator:
  class:            sfPropelUniqueValidator
  param:
    class:          sfGuardUser
    column:         username
    unique_error:   ce login est déjà enregistré, choisissez en un autre.
 
mailuniqValidator:
  class:            sfPropelUniqueValidator
  param:
    class:          UserProfile
    column:         email
    unique_error:   cet email est déjà enregistré, choisissez en un autre.

zipcodeValidator:
  class:            sfNumberValidator
  nan_error:        Veuillez n'entrer que des chiffres
  min:              5
  min_error:        le code postal est au minimum composé de 5 chiffres
 
usernameValidator:      
  class: sfStringValidator
  param:
    min: 3
    min_error: ce login doit être plus long
 
emailValidator:
  class:         sfEmailValidator
  param:
    email_error: l'adresse email n'est pas valide
 
captchaValidator:
  class:         captchaValidator
  param:
    error:       vous devez recopier correctement le code de validation
 
 
 
 
 
methods:         [post]     # This is the default setting
 
fillin:
  enabled:       true
  param:         
    name:        send_page_to_friend_form
    #skip_fields:   [email]  # Do not repopulate these fields
    #exclude_types: [hidden, password] # Do not repopulate these field types
    #check_types:   [text, checkbox, radio, password, hidden] # Do repopulate these
 
validators:
  myStringValidator:
    class: sfStringValidator
    param:
      min:       2
      min_error: This field is too short (2 characters minimum)
      max:       100
      max_error: This field is too long (100 characters maximum)
 
fields:
  name:
    required:
      msg:       The name field cannot be left blank
    myStringValidator:
  email:
    required:
      msg:       The email field cannot be left blank
    myStringValidator:
    sfEmailValidator:
      email_error:  This email address is invalid
  age:
    sfNumberValidator
      nan_error:    Please enter an integer
      min:          0
      min_error:    "You're not even born. How do you want to send a message?"
      max:          120
      max_error:    "Hey, grandma, aren't you too old to surf on the Internet?"
  message:
    required:
      msg:          The message field cannot be left blank
par COil le 2008-09-29, taggé : config  form  symfony  validation  validator 
(1 commentaire)

[symfony] Cacher simplement un fragment de code - 193 view(s)

Cacher le résultat d'un processus coûteux pour 24h :

<?php if (!cache('huge_process_of_the_death', 86400)): ?>
  <?php foreach ($stuff as $item): ?>
    // Your amazingly huge iteration processes here
  <?php endforeach; ?>
  <?php cache_save() ?>
<?php endif; ?>
 

Pour le cacher pour un utilisateur spécifique :

<?php if (!cache('huge_process_of_the_death'.md5($user->getEmail()), 86400)): ?>
  <?php foreach ($stuff as $item): ?>
    // Your amazingly huge iteration processes here
  <?php endforeach; ?>
  <?php cache_save() ?>
<?php endif; ?>
 

On s'assure juste de prendre l'empreinte md5 d'un attribut unique dans la table associée ;)

par COil le 2008-09-29, taggé : cache  optimisation  symfony 
(1 commentaire)

[symfony] Cacher un objet Propel - 109 view(s)

$key = md5('myPropelObjectKey');
$cache = new sfProcessCache();
if ($sfProcessCache->has($key)) 
{
  $obj = unserialize($cache->get($key));
}
else
{
  $obj = Table::doSelect();
  $cache->set($key, serialize($obj))
}
 
par COil le 2008-09-29, taggé : cache  propel  serialisation  symfony 

[symfony 1.0] Autoloader toutes les classes d'un répertoire particulier - 101 view(s)

require_once($sf_symfony_lib_dir.'/util/sfCore.class.php');
sfCore::initSimpleAutoload('/path/to/libs');
par COil le 2008-09-29, taggé : autoloader  config  symfony 

[symfony] Optimisation basique d'un serveur de production - 399 view(s)

Configuration du serveur

Configuration php

Accelerateur de code PHP

APC

A downloader ici si pas dans la distrib php du server :

A ajouter dans php.ini : (au minimum)

Sour Windows pour tester en env de dev

extension=php_apc.dll
apc.enabled          = 1
 

apc.enabled a mettre a 0 ou cas ou il y ai un pb.

Apres il y d'autres parametre qui peuvent etre affinés : (documentation : http://www.php.net/manual/en/ref.apc.php)

apc.shm_segments     = 1
apc.shm_size         = 30
apc.optimization     = 0
apc.num_files_hint   = 1000
apc.ttl              = 0
apc.gc_ttl           = 3600
apc.cache_by_default = 1
apc.filters          = NULL
apc.mmap_file_mask   = NULL
apc.slam_defens      = 0
apc.file_update_protection = 2
apc.enable_cli       = 0
apc.max_file_size    = 1M
apc.stat             = 1
 

Configuration Symfony

Autres optimisations

Voir la documentation officielle au sujet des performances

par COil le 2008-09-28, taggé : apc  config  optimisation  server  symfony 
(1 commentaire)

[symfony 1.0] Forcer l'assignation des javascripts à un template - 143 view(s)

Dans la vue faire (en fin de template)

echo include_javascripts();
 

Typiquement ce pourra être utile dans un template sans layout.

On pourra aussi utiliser le helper sf_include_resources (js+css) du plugin sfJoomlaBridgePlugin, qui contrairement a include_javascripts, inclu dynamiquement les ressources et ne casse pas la conformite XHTML.

par COil le 2008-09-28, taggé : css  helper  javascript  symfony  template  xhtml 

[symfony] Passer des paramètres à une action avant un forward - 107 view(s)

$this->getRequest()->setParameter('confirm', true);
$this->forward('users', 'index');
 
par COil le 2008-09-28, taggé : action  forward  parameters  symfony 

[symfony 1.0] Changer le chemin relatif d'une application - 97 view(s)

.settings
  relative_url_root: /relative/path/to/symfony/app
 
par COil le 2008-09-28, taggé : config  settings  symfony  web 

[symfony 1.0] Chronométrer et débugger une section de code - 96 view(s)

$timer = sfTimerManager::getTimer('method1');
 
for ($index = 0; $index < $iterations; $index++)
{
  $resultado .= "cadena " . $variable;
}
 
$timer->addTime();
$elapsedTime = $timer->getElapsedTime();
$this->debugMessage('"cadena " . $variable; ---> '. round($elapsedTime, 4). ' s');
 

Reference documentation

par COil le 2008-09-28, taggé : debug  optimisation  symfony  timer 

[symfony 1.0] Validation manuelle d'extension de fichier uploadé - 335 view(s)

Pour eviter les problemes de type MIME, notemment sous MAC.

    /**
     * Fonction de validation manuelle de l'importation
     * 
     * @internal Pour bug Mac type mime
     * 
     * @author Vernet Loic
     * @since  6 mars 2007
     */
     public function validateImport()
     {
        $fieldName = 'importfile';
        $fileName = $this->getRequest()->getFileName($fieldName);
        $validExts = array('.CSV');
 
        if ($this->getRequest()->getMethod() == sfRequest::POST) {
            if ($fileName) {
                foreach($validExts as $validExt) {
                    if (strpos(strtoupper($fileName), $validExt)) {
                        return true;
                    }
                }
                $this->getRequest()->setError($fieldName , 'Extension invalide, l\'extension doît être .csv');                
                return false;
            } else {
                $this->getRequest()->setError($fieldName , 'Fichier invalide');                
                return false;
            }
        }        
        return true;
     }
 
par COil le 2008-09-28, taggé : excel  file  form  post  symfony  upload  validation 
(1 commentaire)

[symfony 1.0 / 1.1] Multi-sort for the admin generator - 97 view(s)

Here we go !

The sort in admin generator is for a single field only, but in some complex list, it can be usefull to sort by multiple criterias. This is the main goal of this snippet. Those functions therefore override the ones of your auto-generated class. (1) And to display what are the ongoing sort criterias, you have to modify your 'listth_tabular.php' file.

1 - In your 'action.class.php'

//
    /**
     * Add a sort criteria
     */
    protected function processSort ()
    {
        $sort = $this->getRequestParameter('sort');
        $type = $this->getRequestParameter('type');            
 
        // Register sort                 
        if ($sort) {
            $this->getUser()->setAttribute($sort, $type, 'sf_admin/produits/sort');
        }
    }    
 
    /**
     * Add the sort criterias to the query
     */
    protected function addSortCriteria(&$c)
    {
        $multisort = $this->getUser()->getAttributeHolder()->getAll('sf_admin/produits/sort');
 
        if ($multisort) {
            foreach($multisort as $sort_column => $sort_type) {
                $sort_column = Propel::getDB($c->getDbName())->quoteIdentifier($sort_column);
                if ($sort_type == 'asc') {
                    $c->addAscendingOrderByColumn($sort_column);
                }
                elseif ($sort_type == 'desc') {
                    $c->addDescendingOrderByColumn($sort_column);
                }
            }
        } else {
            // Default sort 
            $sort_column = Propel::getDB($c->getDbName())->quoteIdentifier('libelle');
            $c->addAscendingOrderByColumn($sort_column);            
        }
    }
 
    /**
     * Specific function for multi-sort
     */
    protected function processFilters ()
    {
        if ($this->getRequest()->hasParameter('filter'))
        {
            $filters = $this->getRequestParameter('filters');            
 
            // Multi-sort initialisation
            if (!is_array($filters)) {
                $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/produits/sort');
            }
 
            $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/produits/filters');
            $this->getUser()->getAttributeHolder()->add($filters, 'sf_admin/produits/filters');
        }
    }
 

2 - In 'listth_tabular.php'

(for each sortable field)

<?php 
 
$multisort = $sf_user->getAttributeHolder()->getAll('sf_admin/produits/sort');
 
?>
 
    <th id="sf_admin_list_th_libelle">
        <?php 
        if (isset($multisort['libelle'])) {
            echo link_to('Libellé', 'Produits/list?sort=libelle&type='. ($multisort['libelle'] == 'asc' ? 'desc' : 'asc'));
            echo ' ('. $multisort['libelle'] . ')';
        } else {
            echo link_to('Libellé', 'Produits/list?sort=libelle&type=asc'); 
        }
        ?>
    </th>
 

'Produits' is the module name, 'libelle' is the field to sort.


Notes:

The 'reset button' of filters also initialize the multi-sort. The sort is made from the first field clicked to the last. That means, if you want a different primary sort you will have to use the reset filter button before.

PS: Obviously, this modification can be easly integrated in your backoffice theme, note that the default sort criteria set in the 'generator.yml' is used in the addSortCriteria function (from line // default sort)

par COil le 2008-09-28, taggé : admingenerator  sort  symfony 

[symfony 1.0 / 1.1] Champ de type file dans l'admin generator - 100 view(s)

      imageliste:
        name: Liste du catalogue
        type: admin_input_upload_tag
        upload_dir: dyn/produits
        params: 
          include_link:dyn/produits
          include_remove:true
          include_text: Voir la photo liste du catalogue
          include_remove_text:Supprimer la photo
 
par COil le 2008-09-28, taggé : admingenerator  config  symfony 

[symfony 1.0] Réupérer les informations sur le template en cours - 381 view(s)

Vue

$template = $sf_view->getTemplate()

Action / autre

$template = $context->getCurrentViewInstance()->getTemplate();
par COil le 2008-09-28, taggé : symfony  template  view 
(1 commentaire)

[symfony 1.0] Garder un comportement get avec un link_to - 114 view(s)

<?php echo link_to('interesting article', 'article/read', array('query_string' => 'title=Finance_in_France')) ?>
 
par COil le 2008-09-28, taggé : get  helper  link  symfony  url 

[symfony 1.0] Forcer la suppression de toutes les feuilles de style associees à un template - 103 view(s)

Dans "view.yml" :

stylesheets:    [-*]
 
par COil le 2008-09-28, taggé : css  symfony  view  yml 

[symfony] Utiliser un helper dans une classe action - 318 view(s)

sfLoader::loadHelpers(array('First', 'Second'));
 
par COil le 2008-09-28, taggé : action  helper  loader  symfony 
(1 commentaire)

[symfony 1.0] Ajouter des paramètres par défaut dans toutes les routes - 104 view(s)

sfConfig::set('sf_routing_defaults', array('culture' => 'en'));
 
par COil le 2008-09-28, taggé : config  parameters  routing  symfony 

[symfony] Récupérer tout les paramêtres d'une requête HTTP - 109 view(s)

$request = $this->getRequest()->getParameterHolder();
 
par COil le 2008-09-28, taggé : form  parameters  request  symfony 

[symfony 1.0] Récupérer le nom de la session en cours - 96 view(s)

$sessionName = sfContext::getInstance()->getStorage()->getParameter('sf_session_name')
 
par COil le 2008-09-28, taggé : session  symfony  user 

[symfony] Récupérer la page référante - 169 view(s)

$referer = $this->getRequest()->getReferer()
 
par COil le 2008-09-28, taggé : login  navigation  referer  request  symfony 

[symfony 1.0] Boucle sur les erreurs de validation - 111 view(s)

<?php 
if ($sf_request->hasErrors()) { 
    foreach($sf_request->getErrors() as $key => $error) {
        echo '<li>'. $key. ' => '. $error. '</li>';
    }    
}
?>
 

Version synthaxe alternative

<?php if ($sf_request->hasErrors()): ?> 
    <ul>
    <?php foreach($sf_request->getErrors() as $key => $error): ?> 
        <li><?php echo $key; ?> => <?php echo $error; ?></li>
    <?php endforeach; ?>
    </ul>    
<?php endif; ?>
 
par COil le 2008-09-28, taggé : error  form  symfony  validation 

[symfony 1.0] Test si un formulaire a été posté - 135 view(s)

if ($this->getRequest()->getMethod() == sfRequest::POST) {
    // $this->actionWhenPosted()
}
 
par COil le 2008-09-28, taggé : action  form  post  symfony 

[symfony] Utiliser des constantes d'application dans un fichier .yml - 129 view(s)

all:
  lucene:
    index_path: %MY_CONSTANT%/data/lucene
 
  image_path:
    photos: %SF_WEB_DIR%/images/photos
    avatars: %SF_WEB_DIR%/images/avatars
 
par COil le 2008-09-28, taggé : config  constant  symfony  yml 

[symfony 1.0 / 1.1] Multi sort in admin generator - 188 view(s)

Here we go !

The sort in admin generator is for a single field only, but in some complex list, it can be usefull to sort by multiple criterias. This is the main goal of this snippet. Those functions therefore override the ones of your auto-generated class. (1) And to display what are the ongoing sort criterias, you have to modify your '_list_th_tabular.php' file.

1 - In your 'action.class.php'

//
    /**
     * Add a sort criteria
     */
    protected function processSort ()
    {
        $sort = $this->getRequestParameter('sort');
        $type = $this->getRequestParameter('type');            
 
        // Register sort                 
        if ($sort) {
            $this->getUser()->setAttribute($sort, $type, 'sf_admin/produits/sort');
        }
    }    
 
    /**
     * Add the sort criterias to the query
     */
    protected function addSortCriteria(&$c)
    {
        $multisort = $this->getUser()->getAttributeHolder()->getAll('sf_admin/produits/sort');
 
        if ($multisort) {
            foreach($multisort as $sort_column => $sort_type) {
                $sort_column = Propel::getDB($c->getDbName())->quoteIdentifier($sort_column);
                if ($sort_type == 'asc') {
                    $c->addAscendingOrderByColumn($sort_column);
                }
                elseif ($sort_type == 'desc') {
                    $c->addDescendingOrderByColumn($sort_column);
                }
            }
        } else {
            // Default sort 
            $sort_column = Propel::getDB($c->getDbName())->quoteIdentifier('libelle');
            $c->addAscendingOrderByColumn($sort_column);            
        }
    }
 
    /**
     * Specific function for multi-sort
     */
    protected function processFilters ()
    {
        if ($this->getRequest()->hasParameter('filter'))
        {
            $filters = $this->getRequestParameter('filters');            
 
            // Multi-sort initialisation
            if (!is_array($filters)) {
                $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/produits/sort');
            }
 
            $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/produits/filters');
            $this->getUser()->getAttributeHolder()->add($filters, 'sf_admin/produits/filters');
        }
    }
 

2 - In '_list_th_tabular.php'

(for each sortable field)

<?php 
 
$multisort = $sf_user->getAttributeHolder()->getAll('sf_admin/produits/sort');
 
?>
 
    <th id="sf_admin_list_th_libelle">
        <?php 
        if (isset($multisort['libelle'])) {
            echo link_to('Libellé', 'Produits/list?sort=libelle&type='. ($multisort['libelle'] == 'asc' ? 'desc' : 'asc'));
            echo ' ('. $multisort['libelle'] . ')';
        } else {
            echo link_to('Libellé', 'Produits/list?sort=libelle&type=asc'); 
        }
        ?>
    </th>
 

'Produits' is the module name, 'libelle' is the field to sort.


Notes:

The 'reset button' of filters also initialize the multi-sort. The sort is made from the first field clicked to the last. That means, if you want a different primary sort you will have to use the reset filter button before.

PS: Obviously, this modification can be easly integrated in your backoffice theme, note that the default sort criteria set in the 'generator.yml' is used in the addSortCriteria function (from line // default sort)

Original Snippet

COil :)

par COil le 2008-09-28, taggé : admingenerator  multi  sort  symfony 

[symfony] Fix perms of a project after a > symfony sync - 253 view(s)

[En] After having tested the sync command of Symfony i realised that all the permissions of my /web directory were wrong. The symfony command : (1)

It supposed to correct this, unfortunately the command line php version is 4 on my shared hosting, so i had to to it by hand with a little unix script : (2)

There are lot and different problems on shared testing as can can see in this forum thread


[Fr] Apres avoir testé la commande de synchronisation de symfony, plus rien ne marchait... En fait c'est du au fait que tous mes fichiers de /web n'avait plus les bonnes permission et il fallait les repasser en 755. Une commande symfony permet de regler ce problème : (1)

> symfony fix-perms
 

Néanmoins la version de PHP sur mon server mutualisé est la 4 ! le script symfony ne peut donc pas fonctionner... On peut néanmoins contourner en executant la commande suivante : (2)

> symfony cc
> find . -type f | xargs chmod 644
> find . -type d | xargs chmod 755
 

La joie des serveurs mutualisés avec symfony, ce n'est pas toujours de tout repos comme le montre ce post sur le forum

par COil le 2008-09-28, taggé : cli  prod  rsync  symfony  unix 

[symfony] sync exclude list - 250 view(s)

[Fr] Dans la doc j'ai trouvé la liste de fichier à exclure assez peu fournie. Voici une liste plus complète à personnaliser : (1)


[En] In the documentation i found the exclude file list quiet small. Here is a more consistant one to customize : (1)

.svn
.CVS
.project
.settings
.settings/*
symfony
 
/cache/*
 
/config/config.php
/config/propel.ini
/config/databases.yml
/config/properties.ini
 
/doc/*
 
/log/*
 
/lib/symfony
/lib/symfony/*
 
/data/symfony
/data/symfony/*
 
/plugins/.channels/
/plugins/.registry/
/plugins/.depdb
/plugins/.depdblock
/plugins/.filemap
/plugins/.lock
/plugins/.pearrc
 
/stats/*
 
/test/*
 
/web/.htaccess
/web/frontend_dev.php
/web/backend_dev.php
/web/phpinfo.php
/web/test.php
/web/uploads/*
/web/sf
/web/sf/*
 
par COil le 2008-09-28, taggé : config  rsync  symfony 

[symfony] Fichier typique .htaccess pour OVH - 501 view(s)

[EN] This is a typical .htaccess file for the french hoster OVH (1)

[FR] Voici un fichier .htaccess typique pour faire fonctionner une application Symfony sur un hébergement mutualisé OVH comme le 240gp.

(1)

SetEnv PHP_VER 5
SetEnv REGISTER_GLOBALS 0
SetEnv MAGIC_QUOTES 0
mod_gzip_on Off
 
Options +FollowSymLinks +ExecCGI
 
<IfModule mod_rewrite.c>
  RewriteEngine On
 
  # we skip all files with .something
  RewriteCond %{REQUEST_URI} \..+$
  RewriteCond %{REQUEST_URI} !\.html$
  RewriteCond %{REQUEST_URI} !\.php
  #RewriteCond %{REQUEST_URI} !\.php
  RewriteRule .* - [L]
 
  # we check if the .html version is here (caching)
  RewriteRule ^$ /index.html [QSA]
  RewriteRule ^([^.]+)$ /$1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f
 
  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ /index.php [QSA,L]
 
  # hidden frontoffice controller
  RewriteRule ^index\.php/(.*)$ /index.php [QSA,L]
 
  # fo controllers
  RewriteRule ^frontend\.php/(.*)$ /frontend.php [QSA,L]
  RewriteRule ^frontend_dev\.php/(.*)$ /frontend_dev.php [QSA,L]
 
</IfModule>
 
# big crash from our front web controller
ErrorDocument 500 "<h2>Application error</h2>symfony application failed to start properly"
 
par COil le 2008-09-28, taggé : apache  config  hosting  ovh  symfony 
(3 commentaires)

[symfony 1.0] Keep page number after update in an admin generator list - 409 view(s)

Here is a small patch for the action.class of the admin generator theme :

in executeList() function replace :

$this->pager->setPage($this->getRequestParameter('page', 1));
 

by :

$this->pager->setPage($this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'sf_admin/<?php echo $this->getSingularName() ?>')));
 

in executeList() function add at the end :

// Save page
    if ($this->getRequestParameter('page')) {
        $this->getUser()->setAttribute('page', $this->getRequestParameter('page'), 'sf_admin/<?php echo $this->getSingularName() ?>');
    }
 

in the process() function, before the 1st removeNamespace statement add :

$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/<?php echo $this->getSingularName() ?>');
 

Original forum post

par COil le 2008-09-28, taggé : admingenerator  list  pager  symfony 
(2 commentaires)
Debug toolbar