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

Navigation

Tags

ajax apache doctrine java javascript jquery mysql pear php propel prototype svn symfony ubuntu windows xml

Derniers commentaires/last comments latest comments

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).

Les plus vus Les plus vus

[jQuery] Contrôle de champs radio-box et checkbox - 4541 view(s)

1er cas:

Ici on est dans un cas ou:

- On a 2 radio-box par ligne (et seulement 2)
- Au moins l'une des 2 radio-box doit être sélectionnée
- Si erreur on met le focus sur la 1ère radio du champ
- Si erreur on affiche un message d'erreur à partir du texte d'un div caché

function control_questionnaire()
{  
  checked = false;
 
  jQuery(":radio:even", form).each
  (
    function(intIndex)
    { 
      radio = jQuery(this);
      checked = jQuery(":radio[@name='" + radio.attr('name') + "']:checked", form).size();
 
      if (checked == false)
      {
        radio.focus();
        showFocus(jQuery("#anim_" + radio.attr('id')));
        alert(jQuery("#control_" + radio.attr('id')).html());
 
        return false;
      } 
    }   
  );
 
  if (checked)
  {
    jQuery('#loading-indicator').show();
    jQuery('#diag-form').submit();
  }
}

2ème cas:

Cette fois ci on est dans un cas ou:

- On a un nombre de questions quelconque
- On a un nombre de réponses quelconque, chaque réponse étant représentée par une checkbox
- On peut cocher plusieurs réponses par question
- Au moins l'une des checkbox doit être sélectionnée
- Si erreur on met le focus sur la 1ère checkbox du champ
- Si erreur on affiche un message d'erreur à partir du texte d'un div caché

function control_questionnaire_complexe()
{  
  checked = false;
  name = '';
 
  jQuery(":checkbox", form).each
  (
    function(intIndex)
    { 
      checkbox = jQuery(this);
 
      // Controle si seulement on a pas deja controle le groupe de checkbox
      if (name != checkbox.attr('name'))
      {  
          checked = jQuery(":checkbox[@name='" + checkbox.attr('name') + "']:checked", form).size();
 
          if (checked == false)
          {
            checkbox.focus();
            answer_id = checkbox.attr('id').split('_');
            showFocus(jQuery("#anim_" + answer_id[0]));
            alert(jQuery("#control_" + answer_id[0]).html());
 
            return false;
          }
 
          name = checkbox.attr('name');
      }
    }   
  );
 
  if (checked)
  {
    jQuery('#loading-indicator').show();
    jQuery('#diag-form').submit();
  }
}
par COil le 2009-01-09, taggé : form  javascript  jquery  radio  test 
(1 commentaire)

[symfony] Joomla to symfony mini-bridge [EN] (deprecated) - 1275 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 :

  • Symfony 1.0.0 stable
  • Joomla 1.0.12 stable

  • Install the plugin (check the plugin Wiki page in Symfony )

  • or Download here
    • Copy it in the plugins folder (i'll make a full symfony package later)
    • Copy the plugin web directory in the /web directory of your project

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

  • option : identify the sf module name
  • task : identify the sf module action
  • After that you can add all the paremeters you want, they will be available to Symfony.

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 
(7 commentaires)

[symfony] Noscript "off" in dev with "prod" controller and "on" in prod with the same settings.yml file - 1224 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 

[Ubuntu] Compression basique avec zip - 843 view(s)

Zipper le répertoire test tous ces fichiers et sous-répertoires.

zip -r test.zip test

Pour décompresser, simplement faire unzip sur l'archive.

unzip test.zip
par COil le 2008-11-29, taggé : compression  ubuntu  zip 
(1 commentaire)

[WAMP 2.0] Activer les sous-domaines sur le localhost - 843 view(s)

Dans WAMP,par défaut la gestion des sous-domaines n'est pas activée; pour ce faire vous devez ajouter la directive NameVirtualHost. Mais aussi surtout ajouter une entrée vhost pour le domaine locahost sinon quand vous accéderez à cette adresse vous ne verrez pas le site correspondant à votre racine web (typiquement /www) mais le site correspondant au 1er vhost que vous aurez déclaré. Ce qui est assez gênant. (modifications à faire dans le fichier httpd.conf)

NameVirtualHost *:80
 
# Root localhost
 
<VirtualHost *:80>
  ServerName localhost
  DocumentRoot "d:\wamp\www"
  DirectoryIndex index.php
 
  <Directory "C:\wamp\www">
    AllowOverride All
  </Directory>
</VirtualHost>
 
## projet 1 ##
 
<VirtualHost *:80>
  ServerName dev.projet1.com
  DocumentRoot "d:\wamp\www\projet1\web"
  DirectoryIndex index.php
 
  <Directory "C:\wamp\www\projet1\web">
    AllowOverride All
  </Directory>
</VirtualHost>
 
## projet 2 ##
 
<VirtualHost *:80>
  ServerName dev.projet2.com
  DocumentRoot "d:\wamp\www\projet2\web"
  DirectoryIndex index.php
 
  <Directory "C:\wamp\www\projet2\web">
    AllowOverride All
  </Directory>
</VirtualHost>

Ne pas oublier non plus d'ajouter les entrées 'ServerName' dans votre fichiers hosts (/etc/hosts ou /windows/system32/drivers/etc/hosts).

127.0.0.1       dev.projet1.com, dev.projet2.com

Ici je mets tout les sites en vrac dans le fichier httpd.conf car sous windows.. Mais sous Unix on préférera évidemment faire des fichiers distincts pour chaque sous-domaine déclaré. (typiquement dans /etc/apache2/sites-available)

par COil le 2008-11-12, taggé : apache  vhost  wamp  windows 
(1 commentaire)

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

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

[Apache] Changer la page d'erreur 404 par défaut - 668 view(s)

Donc pour avoir une belle page d'erreur 404, au lieu de la page apache par défaut:

Not Found
The requested URL /kikoo was not found on this server.

Dans le fichier définissant le domaine ajouter la clause ErrorDocument:

<Directory "/var/www/phpdebug">
        AllowOverride All
        Allow from All
        ErrorDocument 404 /www/404.php
</Directory>

Suivi du chemin relatif vers la page 404 personnalisée (ici /www/404.php), ce chemin est relatif à partir de la racine physique du domaine. Ensuite il faut donc habiller sa page 404, on peut par exemple ajouter le widget google 404 (voir tools webmaster de google) afin de permettre à l'utilisateur de lancer une recherche avec le terme/page qui a renvoyé une page 404 sur l'ensemble des pages indexées sur google pour le site donné. Comme ici par exemple.

Ne pas oublier de rajouter dans default:

ErrorDocument 404 default

Sinon toutes les pages 404 de tout les sites définis sur le serveur seront redéfinies.

Enjoy. :)

par COil le 2008-10-20, taggé : 404  apache  error  redirect 
(1 commentaire)

[svn] Lister tous les fichiers modifés entre 2 révisions données - 642 view(s)

Donc ici on commence à la version 116 pour terminer à la révision 140. Pour le détail du code modifié sous forme de patch enlever l'option --summarize.

svn diff -r 116:140 --summarize
par COil le 2009-02-08, taggé : svn  ubuntu 

[symfony 1.2] Créer un contexte d'application à partir d'une tâche - 603 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 
(4 commentaires)

[symfony 1.0 / 1.1] Renaming an uploaded file with an admin_input_file_tag - 540 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)
Debug toolbar