Here is the list of helpers in symfony 1.1.
But unlike upgrading to rails 1.2.6 to 2.0.2, there is one setting to make everything compatible. This difference talks a lot about the diffirence between symfony and Ruby on Rails.
Here is the list of helpers in symfony 1.1.
But unlike upgrading to rails 1.2.6 to 2.0.2, there is one setting to make everything compatible. This difference talks a lot about the diffirence between symfony and Ruby on Rails.
This function reference covers commonly used PHP libraries to their closest Ruby equivalents. The reference is structured very closely against the PHP reference library.
I’m sure I’m gonna visit this reference every single day.
A No Starch PHP recipe book added to O’reilly Safari.
O’Reilly - Safari Books Online:
Instead of starting at “Hello World,” Wicked Cool PHP assumes that you’re familiar with the language and jumps right into the good stuff. After you learn the FAQs of life-the most commonly wished for PHP scripts-you’ll work your way through smart configuration options and the art of forms, all the way through to complex database-backed scripts.
Helper tags in symfony is much like in other frameworks. Some of them are included by default, but other aren’t. You can indeed set all the helpers you need in settings.yml, but some (myself included) prefer to include the helpers only when necessary. The following snippets require you are in HTML scope.
For JavaScript:
<?php use_helper('Javascript') ?>
$0
For Validation:
<?php use_helper('Validation') ?>
$0
For Object:
<?php use_helper('Object') ?>
$0
For Text:
<?php use_helper('Text') ?>
$0
Set “Activation” to “Tab Trigger” “use”. Set “Scope Selector” to “text.html”.
Here a QuickTime movie (with no sound) that shows how these work. The way above doesn’t support using more than one helper at a time. You might very well have time you need more than one helpers. You can also add the following to make this process easier.
<?php use_helper('${1:helper}'$2) ?>
$0
There should be a better way to add the multiple helpers. I just can’t come up with a better solution now.
Recent PHP web apps like Drupal and frameworks like symfony recommend you not close the PHP tag in a PHP script. (In templates you need to open and close PHP tags a lot, of course.)
TextMate PHP Bundle comes with the following snippet with “Tab Trigger” as “php”. Inside an HTML scope, it works as <?php $0 ?> and inside in PHP scope, it works as ?>$0<?php.
When I write a PHP script, I open a blank document and set the language to “HTML”. (TextMate recommends that you use “HTML” instead of “PHP”.) Because I do not want to close the PHP tag, I only want to insert <?php.
In order to do so, I made the following snippets. The snippet itself is simple:
<?php
Set “Activation” to “Tab Trigger” “ph” and set “Scope Selector” to “text.html”. By using “ph” rather than “php”, you don’t see any conflict when you use the snippet.
Here are some of the snippets I use with TextMate.
This is an old school way, but I use var_dump() quite often. The following snippets works when you are editing an HTML file.
<?php echo "<pre>"; var_dump(\$${1:variable}); die(); // DEBUGPRINT ?>
Set “Activation” to Tab Trigger “debug”, and set “Scope Selector” to “text.html”
I have the snippet that works inside a PHP script.
echo "<pre>"; var_dump(\$${1:variable}); die(); // DEBUGPRINT
Set “Scope Selector” to “source.php”.
The reason I use // DEBUGPRINT to leave the snippet searchable. I often comment out the entire line just like:
// echo "<pre>"; var_dump($variable); die(); // DEBUGPRINT
You may be able to do the very similar thing in other text editors like Coda.
I didn’t know the <pre> tag makes the output very readable. Thanks to my colleague.
These forums are on Entropy.ch. Useful indeed.
For those who subscribe to Matz’s website, the PHP vs Ruby was a hot topic.
My background is:
I just spent a day with ruby. I started to feel the programmer’s happiness.
PHP Abastract Podcast introduces symfony framework, an MVC framework for PHP.
This documentatoin is still pre-alpha. If you find any error on this tutorial, please email me. Visit projects.
This article assumes you read my “Install PHP and MySQL via MacPorts on Mac OS X 10.5 Leopard”. This article tries to make a web server for a symfony project locally.
We install symfony via PEAR and make it work with the Ajax tutorial on symfony website.
Leopard, unlike its predecessors, doesn’t have PEAR pre-installed. You need to install it manually. We don’t use MacPorts here. PEAR also has an excellent documentatoin. Visit PEAR manual.
curl http://pear.php.net/go-pear > go-pear.php
This step downloads a file need to install pear. The file will be located under your home folder, and the file name is “go-pear.php”. (Note: We don’t use go-pear.org because go-pear.org is not longer available.)
sudo php -q go-pear.php
Follow the instruction. Default setting doesn’t cause any problem. Just your personal preference. (But, I installed the tool under /usr/local/bin. Concerning why, read the Dan Benjamin’s article.)
Now your have pear command tool installed.
Everytime you come across a setting problem, it’s always useful to check your currnt configuration. You can check your pear configuration by running
pear config-show
As I would like to install beta packages as well as stable ones, I set preferred package state to be beta.
You can do so by running
sudo pear config-set preferred_state beta
Here’s what I have:
Auto-discover new Channels auto_discover <not set>
Default Channel default_channel pear.php.net
HTTP Proxy Server Address http_proxy <not set>
PEAR server [DEPRECATED] master_server pear.php.net
Default Channel Mirror preferred_mirror pear.php.net
Remote Configuration File remote_config <not set>
PEAR executables directory bin_dir /usr/local/bin
PEAR documentation directory doc_dir /usr/local/share/pear/docs
PHP extension directory ext_dir ./
PEAR directory php_dir /usr/local/share/pear
PEAR Installer cache directory cache_dir /var/folders/qo/qoHKwm05H3eGEek47+j0Hk+++TI/-Tmp-//pear/cache
PEAR data directory data_dir /usr/local/share/pear/data
PEAR Installer download download_dir /usr/local/temp/download
directory
PHP CLI/CGI binary php_bin /usr/bin/php
php.ini location php_ini <not set>
PEAR Installer temp directory temp_dir /usr/local/temp
PEAR test directory test_dir /usr/local/share/pear/tests
Cache TimeToLive cache_ttl 3600
Preferred Package State preferred_state beta
Unix file mask umask 22
Debug Log Level verbose 1
PEAR password (for password <not set>
maintainers)
Signature Handling Program sig_bin /usr/local/bin/gpg
Signature Key Directory sig_keydir /private/etc/pearkeys
Signature Key Id sig_keyid <not set>
Package Signature Type sig_type gpg
PEAR username (for username <not set>
maintainers)
User Configuration File Filename /Users/takaaki/.pearrc
System Configuration File Filename /private/etc/pear.conf
Now to make pear work with PHP, you need to add the pear path in your PHP include path by editing php.ini file. The path you need to include is php_dir, in my case /usr/local/share/pear.
mate /opt/local/etc/php.ini
First of all, though not mandatory, but it is highly recommended that you not use magic quotes in PHP. To turn it off, look for “magic_quotes_gpc = On”, which is around line 440. And change it to
magic_quotes_gpc = Off
Next, add th PEAR directory path to include path. Find “include_path”, which is around line 470. Add your PEAR directory, which you can find by running pear config-show and remove the semicolumn (;) at the beginning of the line.
My one looks like this:
include_path = ".:/usr/local/share/pear"
Edit test.php file to check if PHP can work with PEAR.
Open test.php.
mate /opt/local/apache2/htdocs/
Write the following and save it.
<?php
if (require 'PEAR.php') {
echo "You can now use PEAR with PHP!";
} else {
echo "PEAR is not recoginzed with your PHP.";
}
?>
Visit localhost/test.php. If you get an error, include_path may very well be wrong.
Follow the symfony official guide. Find the “PEAR installation”
After installation, let’s check if symfony is properly installed or not. Type the following to get the version number of symfony.
symfony -V
(Note: this is capital/large V. symfony -v won’t work.)
If you see the version number of symfony, symfony is installed successfuly.
There are three ways to install symfony: a) The sandbox, b) Source Download and c) PEAR instllation. We are using PEAR installation approach. We are going to have a web server for a symfony project running. For other instllation, visit symfony’s documentation.
Our aim is to set up a webserver on a Mac for the Easy Ajax Tutorial on symfony documentaion.
Let’s make several settigs clear. Always keep what you try to do in mind:
/Users/[yourusername]/Sites/sfdemo. /web under the project directory is set to web root path. (So, browsers only access to /web directory.) /Users/[yourusername]/Sites/sfdemo/web when your broweser points http://localhost. (Note: Don’t add .com in the URL.)Before creating a symfony project, we change Apache configuration file (httpd.conf) so that our project works under localhost.
Open Apache configuration file (httpd.conf).
mate /opt/local/apache2/conf/httpd.conf
Add the following at the beginning. Replace [yourusername] with a real one. Also replace “/usr/local/share/pear/data” with your PEAR data directory path. You can find your by running pear config-show.
<VirtualHost localhost:80>
ServerName localhost
DocumentRoot "/Users/[yourusername]/Sites/sfdemo/web"
DirectoryIndex index.php
Alias /sf /usr/local/share/pear/data/symfony/web/sf
<Directory "/usr/local/share/pear/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory "/Users/[yourusername]/Sites/sfdemo/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Save the file and restart Apache web server.
sudo apachectl restart
You will see a warning as the following.
[warn] VirtualHost localhost:80 overlaps with VirtualHost localhost:80, the first has precedence, perhaps you need a NameVirtualHost directive
This means that you already have a setting for localhost:80 in your Apache configuration file. As this is a warning, not an error, let’s ingnore it for a second. You can tweak the configuration anytime when you learned more about Apache.
Let’s make a symfony project.
First, open Terminal and move to the Sites folder.
cd ~/Sites
And create a directory called “sfdemo” and move to the folder.
mkdir sfdemo
cd sfdemo
Create a project called “sfdemo” and make an application called “app” and a module called “cart”. What each command does is not explained here. Visit the tutorial.
symfony init-project sfdemo
symfony init-app app
symfony init-module app cart
Visit localhost/cart. If everything works fine, you will see a symfony page, saying “Module " cart" created”.