Archive for category Programming
how to build schema and keep I18n attributes in the yml file using propel and symfony 1.4
Posted by sonius in PHP, Programming, Symfony, Web Development on February 17, 2012
I had created I18n table set and all seemed to be working well until I tried to propel:build-schema.
I had lost my attribues:
isI18N: true, i18nTable: page_i18n & isCulture: true
This is how I want my schema to looked in the beginning:
cms:
_attributes: { phpName: Cms, isI18N: true, i18nTable: cms_i18n }
id:
handle: {type: varchar, size: 50}
created_at:
updated_at:
cms_i18n:
id: { type: integer, size: 11, foreignTable: cms, foreignReference: id, required: true, primaryKey: true }
culture: { type: varchar, size: 7, required: true, primaryKey: true, isCulture: true }
content: { phpName: Content, type: LONGVARCHAR, required: true }
Basically how the build-schema work flow works like this
- Execute symfony propel: build-schema
- The sfPropelBuildSchemaTask script will create an schema.xml file from the database
- Then sfPropelBuildSchemaTask will create a schema.yml from the newly created schema.xml before deleting it
The way to fix this problem is to modify the schema.xml before it transformed into the schema.yml
This is how I fixed the problem.
- You need to find and modify the sfPropelBuildSchemaTask.class.php file
- Find: protected function reverseDatabase()
- You will see where they define the yml and the xml path
$xmlSchemaPath = sfConfig::get('sf_config_dir') . '/' . $name . '.xml'; $ymlSchemaPath = sfConfig::get('sf_config_dir') . '/' . $name . '.yml'; - below this you should find an if block. There is no use modifying the xml if it doest exists
if (file_exists($xmlSchemaPath)) { - Immediately at the start of the ‘if’ block added this code, you may need to modify to fit your situation…
$I18ntables = array(); $schema = file_get_contents($xmlSchemaPath); $xml = simplexml_load_file($xmlSchemaPath); //iterate once to get all i18n tables foreach ($xml->table as $table) { foreach ($table->attributes() as $attributeskey0 => $attributesvalue1) { if ($attributeskey0 == 'name') { if (preg_match("/_i18n/", $attributesvalue1)) { $I18ntables[] = str_replace('_i18n', '', $attributesvalue1); } } } } //iterate again because we dont know the order of the tables //grab the sister tables and add the new attributes foreach ($xml->table as $table) { foreach ($table->attributes() as $attributeskey0 => $attributesvalue1) { if ($attributeskey0 == 'name') { if (in_array($attributesvalue1, $I18ntables)) { $table->addAttribute('isI18N', "true"); $table->addAttribute('i18nTable', strtolower($attributesvalue1 . '_i18n')); } //as we are scrolling through the tables again, grab the i18n table //find the column called 'culture' and add a new attribut to that if (preg_match("/_i18n/", $attributesvalue1)) { foreach ($table->children() as $columnkey0 => $columnvalue1) { if ($columnkey0 == 'column') { foreach ($columnvalue1->attributes() as $collAttrKey0 => $collAttrValue1) { if ($collAttrKey0 == 'name') { if ($collAttrValue1 == 'culture') { $columnvalue1->addAttribute('isCulture', 'true'); } } } } } } } } } //the schema has changed now so assign it here $schema = $xml->asXML();
There are a couple of rules you need to know to use my code
- the 2 I18N tables must be named the same , except for the ‘_i18n’ appendment of course
- The column where you set the culture must be named ‘culture’
Simple oAuth Twitter plugin for Symfony
Posted by sonius in PHP, Programming, Symfony, Web Development on November 4, 2010

This plugin was developed to allow you to post to ONE twitter account programmatically.
This plugin uses classes originally developed by Abraham Williams, TwitterOAuth handles the authentication of OAuth requests to interface with Twitter and can be used with all versions of Symfony.
* sf 1.0
* sf 1.1
* sf 1.2
* sf 1.3
* sf 1.4
Installation Method
1. Copy the twitterOAuthPlugin dir to your plugins directory of your Symfony project
2. Activate the module ‘twitterOAuthPluginSetup’ in one of your symfony apps.
look at ‘Activating a plug-in Module’ in the book
3. clear cache
4. goto http://www.yourwebapp.com.au/twitterOAuthPluginSetup
5. you should get instructions similar to the steps below..
>>>
Steps:
1. Log into the Twitter account you want this symfony project to post to.
2. Go to http://dev.twitter.com/apps and ‘Register a new application’.
3. Give your application a unique name and description
4. for Application Website: enter, eg: http://www.yourapplication.com.au
5. Callback URL may be left blank. There’s no login process, so there’s no need to provide a URL to redirect users to.
6. Default Access type refers to the access your application will have to Twitter. Read & Write allows complete access. This is almost certainly what you want for your this project.
7. Replace the ‘xxx’ in the the plugin app.yml, twitterOAuthPlugin/config/app.yml, with your Consumer Key & the Consumer Secret.
twitter_consumer_key: xxx
twitter_consumer_secret: xxx
8. Go to ‘My Acesss token’

9. Replace the ‘xxx’ in the the plugin app.yml, twitterOAuthPlugin/config/app.yml, with your Access Token & the Access Token Secret.
twitter_access_token: xxx
twitter_ access_token_secret: xxx
10. Save the app.yml and clear cache.
11. To post a message to your Twitter account use the following static method in twitterOAuthPlugin.class.php
public static function sendTweet($message = null) { …..
eg: twitterOAuthPlugin::sendTweet(‘Test Message’);
How to get the returned value from a given module/action without rendering a view template. symfony 1.3
Posted by sonius in Programming, Symfony, Web Development on September 2, 2010
I had been tring to figure this out for a while now.
Typically if you wanted an action to render text, you would use the following line of code.
public function executeTest() {
return $this->renderText('abcdefg');
}
This is fine if you access that action directly.
I wanted a way to grab the output of another module/action.
The best way to this is using the getPresentationFor($module, $action) method
public function executeTest2(){
$output = sfContext::getInstance()->getController()->getPresentationFor('user', 'test');
echo $output;
exit;
}
The problem is…
This method grabs the presentation (ie, rendered template) for the module/action (‘user’, ‘test’) but in action executeTest, there is no template to render, causing an error.
Why dont I just create a template and be happy with the returned presentation? Id rather bypass this step to optimise code execution.
Normally I would return sfView::NONE in my action to fluff the template, but getPresentationFor() still looks for a template and I cant return any rendered text if Im returning sfView.
I found a way to set the view to NONE without returning sfView. This leaves me a way to return $this->renderText().
this is how I did it…
public function executeTest() {
sfContext::getInstance()->getController()->getRenderMode(sfView::NONE);
return $this->renderText('abcdefg');
}
public function executeTest2(){
$output = sfContext::getInstance()->getController()->getPresentationFor('user', 'test');
echo $output;
exit;
}
The World of Programming
Posted by sonius in PHP, Programming, Web Development on July 13, 2010
