This snippet shows you to test if there was at least one modification on a list of fields.
/** * Test if one of the 3 columns was modified. * * @author COil * @since 13 sept 08 * * @return boolean */ public function isAdrressModified() { $columns = array_flip($this->modifiedColumns); return isset($columns[UserProfilePeer::TOWN]) || isset($columns[UserProfilePeer::ADDRESS]) || isset($columns[UserProfilePeer::POSTAL_CODE]); }
This snippet is deprecated, please use the sfJoomla15BridgePlugin plugin witch works with the new 1.5 Joomla and the symfony 1.2 version.
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)
Versions used :
Joomla 1.0.12 stable
Install the plugin (check the plugin Wiki page in Symfony )
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.
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. }
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
We are going to do a page (module/action) whitch will be called by Joomla with the help of its new component.
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()); }
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¶m2=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
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 /!\
Has to be updated for symfony 1.1
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 :)
'onchange' => remote_function(array( 'update' => 'item_domain', 'url' => 'list/subdomain', 'with' => "'id=' + this.options[this.selectedIndex].value" ))
// 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; }
$configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true); sfContext::createInstance($configuration);
deb http://old-releases.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
public function getFields() { return array_keys($this->widgetSchema->getFields()); }
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'));
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() ?>');
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(); } }
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(); } }
logs
8699.6 KB