Friday, June 06, 2008

using FusionCharts

example of using FustionCharts in Symfony project

create folder swf in /web
then copy Column3D.swf to it, /web/swf/Column3D.swf
then create the data file in it, /web/swf/Data.xml

in your application page, ie: dashboard/index insert

      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="900" height="300" id="Column3D" >
         <param name="movie" value="/swf/Column3D.swf" />
         <param name="FlashVars" value="&dataURL=/swf/Data.xml">
         <param name="quality" value="high" />
         <embed src="/swf/Column3D.swf" flashVars="&dataURL=/swf/Data.xml" quality="high" width="900" height="300" name="Column3D" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
      </object>

it's using relative path, the data and flash file are relative to the index.php in web folder (or frontend_dev.php)

Thursday, May 15, 2008

symfony sync

when the project get into production stage, upload the site and upgrade becoming a big problem.

symfony using rsync to do it.

more reference is on:

http://www.symfony-project.org/askeet/1_0/22

http://www.symfony-project.org/forum/index.php/m/50719/?srch=rsync#msg_50719

the 2nd link above is about the solution in Windows

Monday, May 05, 2008

how to get s3 work with symfony

I've tried the s3 plugin, but had no luck. So I started to use the example from IBM on http://www.ibm.com/developerworks/library/os-php-amzmm/index.html
actually, this example is very similar to the official example on http://developer.amazonwebservices.com/connect/entry.jspa?externalID=847&categoryID=137
there's some problem, the solution is on: http://developer.amazonwebservices.com/connect/thread.jspa?threadID=17692

I added the s3 class into lib\myTools.php
installed PEAR package: Crypt_HMAC and HTTP_Request

made 2 changes:
replace 'DATE_RFC822' with 'S3_DATE_RFC822' as my version of PHP (5.2.0) won't allow me to redefine this variable.
commented below out:
/*
        if ( strlen( $contenttypestring ) )

            $contenttypestring = $contenttypestring.",application/x-www-form-urlencoded";

        else if ( $verb == "PUT" )

            $contenttypestring = "application/x-www-form-urlencoded";
*/

Friday, May 02, 2008

symfony amazons3 plugin

this plugin is now on: http://trac.symfony-project.com/wiki/sfAmazonS3Plugin
but you cannot install it if you follow the instruction on the page.

to install it, refer to: http://www.mail-archive.com/symfony-users@googlegroups.com/msg04571.html

or do my way:
create an empty folder on desktop
right click and use svn to checkout
http://svn.symfony-project.com/plugins/sfAmazonS3FSPlugin

and save it as
plugins/sfAmazonS3FSPlugin

Wednesday, April 23, 2008

useful string trim function

/**
 * Cut string to n symbols and add delim but do not break words.
 *
 * Example:
 * <code>
 *  $string = 'this sentence is way too long';
 *  echo neat_trim($string, 16);
 * </code>
 *
 * Output: 'this sentence is…'
 *
 * @access public
 * @param string string we are operating with
 * @param integer character count to cut to
 * @param string|NULL delimiter. Default: '…'
 * @return string processed string
 **/

function neat_trim($str, $n, $delim='…') {
   $len = strlen($str);
   if ($len > $n) {
       preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
       return rtrim($matches[1]) . $delim;
   }
   else {
       return $str;
   }
}

Wednesday, April 16, 2008

how to user symfony sfAjaxUploaderPlugin

This is from symfony forum

http://www.symfony-project.org/forum/index.php/mv/msg/9279/0/40/

for more information, please check the post.




It looks to me like many people having problems using this plugin, and for good reasons. It is not the best plugin around and it was built very quickly, but it can be used.

To help you all I have made a small demo project which I friezed and attached.

The project was build by init a new project, then init an application called "test" and then init module called "test".


The index template contains the form with a file input field to be uploaded.



Theses are the changes done to various files:

filters.yml:


rendering: ~
web_debug: ~
security: ~

# generally, you will want to insert your own filters here
ajaxUploader:
class: AjaxUploaderFilter

cache: ~
common: ~
flash: ~
execution: ~




settings.yml:


prod:
.settings:
no_script_name: on

dev:
.settings:
error_reporting:

web_debug: on
cache: off
no_script_name: off
etag: off

test:
.settings:
error_reporting:
cache: off
web_debug: off
no_script_name: off
etag: off

all:
.settings:
enabled_modules: [default, ajaxUploader]




view.yml


default:
http_metas:
content-type: text/html

metas:
title: symfony project
robots: index, follow
description: symfony project
keywords: symfony, project
language: en

stylesheets: [main]

javascripts: [%SF_PROTOTYPE_WEB_DIR%/js/prototype, /sfAjaxUploaderPlugin/js/ajaxUploader]

has_layout: on
layout: layout





There is no code in the actions, only some templates.

The index template is a form with file field:




'myAjaxUploader()',
'update' => 'target_div',
'url' => 'test/upload',
)); ?>









and the response template just echos some info:


getParameter('name'))) {
echo "file " . $sf_request->getParameter('name') . " was uploaded";
} else {
echo "no file was uploaded";
}
?>





The AjaxUploaderHelper.php was buggy (as few of you have noticed). It should be:

url_for("ajaxUploader/uploader") . "?name=$name", "name"=>"ajaxUploader", "frameborder"=>0, "width"=>320, "height"=>25), true)
. tag("/iframe") . input_hidden_tag($name);
}

?>





And thats it, AJAX uploads!

symfony get insert_id

To get the last inserted record id in symfony, you can do as below:

$newHistory = new History();
$newHistory->setUpdateTime($now);
$newHistory->save();
$newHistory->getId()

Wednesday, April 02, 2008

Symfony Cheat Sheets Index

Cheat Sheets Index

This page lists all the know cheat cheets dealing with symfony.

Official

User-contributed

TopicAuthorEnglishPortuguêsEspañolFrançais Deutsch
Directory Structure and CLI Andréia BohnerJPG PDF JPG PDF JPG PDF JPG PDF JPG PDF
ViewAndréia BohnerPDF
View: Partials, Components, Slots and Component Slots Andréia BohnerPDF
Form HelpersAndréia BohnerJPG PDF JPG PDF
Javascript and Ajax HelpersAndréia Bohner PDFPDF
Server ValidationAndréia BohnerPDF PDF
ModelAndréia BohnerPDF
Model: SchemaAndréia BohnerPDF
Lime Unit & Functional TestingBenjamin MeynellPDF
ORMAndréia BohnerJPG PDF PDF
Criteria/Criterion/RSAndréia BohnerPDF

Tuesday, April 01, 2008

deploying a Symfony 1.0 project to a shared hosting envirnoment without Symfony installed

Deploying 1.0 To A Shared Host

This page describes a method of deploying a Symfony 1.0 project to a shared hosting envirnoment without Symfony installed.

Prerequisites

In order for this method to work, you need to meet the following conditions:

  • A Shared Host with PHP5
  • A functional copy of the project you plan to deploy in a local environment with Symfony 1.0 installed
  • An FTP account to the host you plan to deploy to.

Preparing Your Local Project

Several things need to be dealt with before beginning to upload.

  1. Update Symfony - Make sure that you're using the latest update of Symfony 1.0 (at the time of this writing the most recent update is 1.0beta1). For example, if you are using a pear install of Symfony 1.0beta1 on linux, you might execute this command:
    sudo pear upgrade symfony/symfony-beta
  2. Update Project - If you've recently updated your symfony install, be sure to update the project for the new version:
    symfony upgrade 1.0
  3. Freeze Project - Now comes the easy part. When you freeze a project, like we're about to do, Symfony automatically packages the current pear libraries into the project directories and updates the configuration to point to these internal libraries. This tool has several purposes, of which easing deployment is one of the most useful. So, just issue the command in your root project directory, and watch the magic happen:
    symfony freeze

You will then see a long list of things which Symfony is doing, most of which involve copying files to their new locations. Most of these will be in the lib/ and data/ directories, but there are a few in other places, such as the web/ directory.

Preparing Your Host Space

Directory Structure

Most shared hosting companies provide you with a base directory where you may upload your files. A standard layout for the subdirectory structure looks like this:

/
+-/public_ftp
+-/public_html
+-/tmp

There may be other folders, but they are not important to us.

Uploading the Files

Uploading the files is really quite easy, provided you know how to use an FTP client. If not, I would suggest you go read up on them, as they are very useful tools.

All you need to do is upload the following directories to the root folder of your webspace (Note: Do not upload the files into your public_html or similar folder. This is a severe security risk'''):

/
+-/apps
+-/cache
+-/config
+-/data
+-/lib
+-/log
+-/plugins (Optional, depending upon whether you have any plugins installed)

The next thing you need to do is upload the files in your project web/ directory into your remote public_html/ directory, or whatever directory you have that fulfills the function of holding your publically-viewable files.

/web/*    =>    /public_html/

Permissions

Now that you've uploaded the files, you need to ensure that the permissions of certain folders didn't get messed up while uploading.

symfony fix-perms
  • /cache : This folder should have world-writable permissions (777)
  • /log : This folder should have world-writable permissions (777)
  • All others: The other folders and file should be world-readable and executable (755)

Miscellaneous

There are a few other things you might want to do now that you're mostly finished.

Dev Controllers

I would definitely recommend that you deleted the dev controllers (/public_html/*_dev.php), since they are not needed and have the potential to deliver unwanted information to anyone attempting to hack your website.

Plugin Web Directories

Depending upon the method of installing your plugins and the platform you have developed your project on, the plugin web/ directories may need attending to. Generally if they worked on your local system, they'll work on your host, but if you encounter broken images and an absence of certain javascript files and stylesheets, then you may need to fix this. You have two options:

  1. If you are on a host that supports symlinks, you can create symlinks from the main public_html directory to the plugin web directories.
  2. The universal method of fixing a problem like this is to simply copy the contents of the plugin web/ directories into your main public_html/ directory.

Problems

Problem with stylesheet (css)

If the link to stylesheet doesn't work, add the following line to index.php:

$_SERVER['SCRIPT_NAME']='/index.php';

Based on this thread (OVH context).

Other

If you experience problems with this, simply ask on the forums or mailing list and you will most likely get an answer soon.

Wednesday, March 26, 2008

symfony simple blog plugin conflict

if you use symfony simple blog plugin ( sfSimpleBlog )
you cannot define your other php name as Job in schema, ie:

jobs:
_attributes: { phpName: Job, idMethod: native }

you can use jobs as below or change to something else

jobs:
_attributes: { phpName: Jobs, idMethod: native }

otherwise you will not be able to load the simple blog admin after you
rebuild the model

Thursday, March 20, 2008

how to deal with enum in symfony

type: enum

Simulating an enum column type in the model

As enum is a MySQL specific type, you cannot have a column of type
enum in your schema.yml (which is database-independent). One solution
to simulate it is to create another table to store the different
possible values. But the Model class offer an alternative solution
that is probably more elegant.

please see detail on: http://www.symfony-project.org/snippets/snippet/107

useful docs of symfony

URL http://andreiabohner.files.wordpress.com/2007/08/sfmodelfirstpartrefcard.pdf
this is about database model, the files, locations and etc

URL http://andreiabohner.files.wordpress.com/2007/09/sfmodelsecondpartrefcard.pdf
this is about database schema, it's a detailed example of schema.yml with explanation of  each item.

URL http://andreiabohner.files.wordpress.com/2008/01/sfmodelcriteriacriterionrsrefcard_enus.pdf
this is about the criteria / criterion / RS
full doc and example

useful docs of symfony

refer to http://pools.jp/2007/06/24/symfony-schema-yml-propel-%E6%8A%BD%E8%B1%A1%E8%A1%A8%E7%8F%BE/
source is Japanese, it's about how the schema.yml defines the column types. Simple form is copied from the source below, for more details, refer to the source.


mysql symfony(schema.yml)
varchar VARCHAR
tinyint TINYINT
text LONGVARCHAR
date DATE
smallint SMALLINT
mediumint SMALLINT
int INTEGER
bigint BIGINT
float FLOAT
datetime TIMESTAMP
timestamp TIMESTAMP
time TIME
year INTEGER
char CHAR
tinybolb BINARY
tinytext VARCHAR
blob VARBINARY
mediumbob VARBINARY
mediumtext LONGVARCHAR
longblob VARBINARY
longtext LONGVARCHAR
enum CHAR
set CHAR
bool TINYINT
decimal DECIMAL

Tuesday, March 11, 2008

symfony propel-load-data

symfony propel-load-data

Loading data from fixtures can be extremely useful to pre-populate
your database so you have something to test and code with. I
frequently use the propel-load-data task in two ways, the first when
altering the schema, and the second to add some new data on top of
whats in the database.

This will rebuild your db and model from schema.yml, insert the new
structure into your db, and load data from the fixtures in
/data/fixtures:

./symfony propel-build-all-load frontend

To load in additional data from a specific fixture file, you can use
this command:

./symfony propel-load-data frontend dev data/fixtures/[filename].yml append

Tuesday, March 04, 2008

symfony sfGuard

when install the plugin sfGuard, if you have problem when running
propel-load-data to import the init data.
use the following command:
symfony propel-load-data frontend

the common error is asking for the app name, but if you use your
project name you'll remain the error. so use frontend instead of you
project name.

Monday, February 18, 2008

symfony askeet tutorial

day 12

add

<?php echo link_to('Forgot your password?', '@user_require_password') ?>

to the login form, under wrong password div

at the end of the tutorial, you'll have the function not exist error:
Call to undefined function form_error()

you just need add <?php use_helper('Validation'); ?> to top of
user/passwordRequestSuccess.php

symfony askeet tutorial

on day8,

add <?php use_helper('Javascript') ?> right be4 </header>


then add

<div id="login" style="display: none">
<h2>Please sign-in first</h2>

<?php echo link_to_function('cancel', visual_effect('blind_up',
'login', array('duration' => 0.5))) ?>

<?php echo form_tag('user/login', 'id=loginform') ?>
nickname: <?php echo input_tag('nickname') ?><br />
password: <?php echo input_password_tag('password') ?><br />
<?php echo input_hidden_tag('referer', $sf_params->get('referer')
? $sf_params->get('referer') : $sf_request->getUri()) ?>
<?php echo submit_tag('login') ?>
</form>
</div>

right be4
<div id="content">

"Have the form appear when a non-authenticated user clicks an interested link"

askeet/lib/helper/UserHelper.php

should be

askeet/apps/frontend/lib/helper/UserHelper.php

on day9, "Modify the templates"

in showSuccess.php
change <?php echo $question->getBody() ?>
to <?php echo $question->getHtmlBody() ?>


in _list.php
change <?php echo truncate_text($question->getBody(), 200) ?>
to <?php echo truncate_text(strip_tags($question->getHtmlBody()), 200) ?>


day10

isInterestedIn() is created in askeet\lib\model\User.php

the refactoring is, in user/action

change

public function executeInterested()
{
$this->question =
QuestionPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($this->question);

$user = $this->getUser()->getSubscriber();

$interest = new Interest();
$interest->setQuestion($this->question);
$interest->setUser($user);
$interest->save();
}

to

public function executeInterested()
{
$this->question =
QuestionPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($this->question);

$this->getUser()->getSubscriber()->isInterestedIn($this->question);
}


another refactoring is, in UserHelper.php
change
return link_to_function('interested?', visual_effect('blind_down',
'login', array('duration' => 0.5)));
to
return link_to_login('interested?');

update modules/sidebar/templates/defaultSuccess.php
to
<?php use_helper('User') ?>

<?php echo link_to_login('ask a new question', '@add_question') ?>

<ul>
<li><?php echo link_to('popular questions', '@popular_questions') ?>
<li><?php echo link_to('latest questions', '@recent_questions') ?></li>
<li><?php echo link_to('latest answers', '@recent_answers') ?></li>
</ul>

symfony askeet tutorial

finally get the symfony ajax installation correctly.

this should be for day1 but i found the problem on day8 when i need ajax.

bascially 2 points: wamp has 2 php.ini files AND the pear path is point to c:\php5\pear\

more reference to read

http://www.symfony-project.org/forum/index.php?t=msg&&th=5339&goto=22910
http://trac.symfony-project.com/wiki/SymfonyOnWAMP

also, a chinese reference:
http://www.watir.cn/?p=18

Friday, February 15, 2008

symfony askeet tutorial

day 7 problem solved, seems i had problem in previous day 5. i did all from day 2-7, it's all fine.

got problem in day 8, after add the ajax, got fatal error.
solution is found in forum at:  http://www.symfony-project.org/forum/index.php/m/22875/
pay attention to the last reply, that's the solution i take. also found a bug report regarding to the fatal error, seems it's about the PK

--
Kindest Regards,

Zhen Sun

Thursday, February 14, 2008

symfony askeet tutorial

on day7, got problem to show the user profile. need sort out.

when 'we can also link to a user profile from a question', solve 'Don't forget to declare the use of the Date helper in _list.php.' by add <?php use_helper('Date', 'Global') ?> on top  of _list.php, I guess add <?php use_helper('Date') ?> would work too.

when add sidebar

on the view.yml

default:
components:
sidebar: [sidebar, default]


actually just need

components:
sidebar: [sidebar, default]

otherwise there's 2 default keywords in the yml file and get a non-css and non-sidebar page


the user profile problem remains, even after checked the askeet SVN repository. will need a further investigation later.

Wednesday, February 13, 2008

symfony askeet tutorial

this is the first day on the tutorial.

in the tutorial, day4 takes sometime to learn, a lot of reference to read.

day5's last piece is not correct. need rename the downloaded _question_list.php to _list.php, also you'd better copy the content from previous listSuccess.php and get rid of the <h1></h1> part to the _list.php

actually, just create the _list.php, then copy the content from listSuccess.php, delete the line of <h1></h1>

then change the listSuccess.php content to
<h1>popular questions</h1>

<?php echo include_partial('list', array('question_pager' => $question_pager)) ?>

day6,

when add the secureity.yml
all:
is_secure: on
credentials: subscriber

make sure you read the notes, and change on to off

public
function handleErrorLogin()
{
return sfView::SUCCESS;
}

don't forget to add this method to user actions.classe.php to handle the error.

Tuesday, February 12, 2008

learning symfony

follow the tutorial, build imagegallery db, and modify config/database.yml and propel.ini.

when run the last step symfony propel-generate-crud backend images Image

got error Unable to scafford unexistant model 'Image'

look like i didn't setup the Image model. so i leave this tutorial alone and go back to do the symfony site official tutorail on http://www.symfony-project.org/tutorial/1_0/my-first-project

called

My first symfony project

first problem when create the model, need enable extension=php_xsl.dll of PHP

still have the same error, but doesn't matter. seems the model is still created and

http://localhost/sf_sandbox/web/frontend_dev.php/pos
http://localhost/sf_sandbox/web/frontend_dev.php/comment

work fine.

when u add validation onto the comment form, the instruction is

Now to finish, open again the modules/comment/templates/editSuccess.php template and insert at the top:

actually, it means insert to the top of the table, right after <tbody>


on the change the URL aspect part, there's a little problem of modifying the template, tutorial is not totally correct, you'd better have a look the final result image and finger out how to modify the template. the part modify the table cells.

this example is completed finally, but it is far from master it.

learning symfony

i got the sandbox works first, that's no trick there. but finally i decided to use pear installation.

so 1st step is to install pear on my wamp, you need add php to the windows environment path variable  ie:c:\wamp\bin\php\php5.2.5\
then run go-pear.bat to install pear
then install symfony  pear package  follow the instruction on http://www.symfony-project.org/book/1_1/03-Running-Symfony

i did the test initial project on that page, now working on a tutorial on http://www.odeweb.com/2008/01/25/symfony-crud-a-how-to/