<?xml version="1.0" encoding="utf-8"?> <install type="component" version="1.5.0" method="upgrade"> <name>snippets</name> <version>1.0</version> <creationDate>2008 11 27</creationDate> <author>Vernet Loïc</author> <authorEmail>cocoil@yahoo.fr</authorEmail> <authorUrl>http://www.strangebuzz.com</authorUrl> <copyright>(C) 2008 - 2009 COil</copyright> <license>COil</license> <description>Great component</description> <administration> <menu img="templates/myadmintemplate/images/menu/comments.png">My component</menu> </administration> <install /> <uninstall /> </install>
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 :)
#!/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 ! ;)"
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`"); } }
$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') );
logs
8195.9 KB