Posted in Symfony | By tarotoast | Tags: code, note, php, symfony, yaml
Symfony 的設定檔都是用 YAML 格式來搞定的,當然要用 ini 或者 xml 也是可以,不過 YAML 算是很簡單好用的選擇。選擇使用 YAML 的好處就跟選擇用 Python 寫程式差不多,好讀好編輯然後記得要用 space 不要用 tab。
# Never use tabs
all:
-> mail:
-> -> webmaster: webmaster@example.com
# Use blanks instead
all:
mail:
webmaster: webmaster@example.com
# All valid formats
error1: This field is compulsory
error2: ' This field is compulsory '
error3: 'Don''t leave this field blank' # Single quotes must be doubled
# Multiline
# Folded style, introduced by >
# Each line break is folded to a space
# Makes YAML more readable
accomplishment: >
Mark set a major league
home run record in 1998.
# Literal style, introduced by |
# All line breaks count
# Indentation doesn't appear in the resulting string
stats: |
65 Home Runs
0.278 Batting Average
# Shorthand syntax for arrays
players: [ Mark McGwire, Sammy Sosa, Ken Griffey ]
# Expanded syntax for arrays
players:
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Incorrect syntax, blanks are missing after the colon
mail: {webmaster:webmaster@example.com,contact:contact@example.com}
# Correct shorthand syntax for associative arrays
mail: { webmaster: webmaster@example.com, contact: contact@example.com }
# Expanded syntax for associative arrays
mail:
webmaster: webmaster@example.com
contact: contact@example.com
# Boolean Values
true_values: [ on, 1, true ]
false_values: [ off, 0, false ]
# Header
all:
.general: # Key starts with . is ignored, 完全是方便閱讀而存在
tax: 19.6
Read more |
No Comments » |
May 25th, 2008
Posted in Symfony | By tarotoast | Tags: code, note, php, symfony
Constant
sfConfig::set('key', 'value');
echo sfConfig::get('key');
Using External PHP Class
- Place in lib/ directory
- Provide __autoload() function
- Symfony will automatically load so include statement is unnecessary.
Passing Variables from Action to Template
In Action:
class mymoduleActions extends sfActions
{
public function executeMyAction()
{
$this->hour = $today['hours'];
}
}
In Template:
<p>It is already <?php echo $hour ?>.</p>
Form (with helper)
HTML Version:
<form method="post" action="/myapp_dev.php/mymodule/anotherAction">
<label for="name">What is your name?</label>
<input type="text" name="name" id="name" value="" />
<select name="cc_type" id="cc_type">
<option value="VISA">Visa</option>
<option value="MAST">MasterCard</option>
<option value="AMEX" selected="selected">American Express</option>
<option value="DISC">Discover</option>
</select>
<input type="submit" value="Ok" />
</form>
Symfony Version:
<?php echo form_tag('mymodule/anotherAction') ?>
<?php echo label_for('name', 'What is your name?') ?>
<?php echo input_tag('name') ?>
<?php $card_list = array(
'VISA' => 'Visa',
'MAST' => 'MasterCard',
'AMEX' => 'American Express',
'DISC' => 'Discover');
echo select_tag('cc_type, options_for_select($card_list, 'AMEX')); ?>
<?php echo submit_tag('Ok') ?>
</form>
Hyperlink (with helper)
HTML Version:
<a class="special_link" onclick="return confirm('Are you sure?');"
href="http://localhost/myapp_dev.php/mymodule/anotherAction/name/anonymous">
I never say my name</a>
Symfony Version:
<?php echo link_to('I never say my name', 'mymodule/anotherAction?name=anonymous',
'class=special_link confirm=Are you sure? absolute=true') ?>
Post/Get Data
In Action:
class mymoduleActions extends sfActions
{
...
public function executeAnotherAction()
{
$this->name = $this->getRequestParameter('name');
}
}
In Template:
<?php if ($sf_params->has('name')): ?>
<p>Hello, <?php echo $sf_params->get('name') ?>!</p>
<?php else: ?>
<p>Hello, John Doe!</p>
<?php endif; ?>
or
<p>Hello, <?php echo $sf_params->get('name', 'John Doe') ?>!</p>
Read more |
1 Comment » |
May 24th, 2008
Posted in College (UCSD), Footprints + Diary | By tarotoast | Tags: 50k, free food, ucsd

Event: $50K Top 5 Finalist Business Plan Presentations and Awards Ceremony
What: Free food and drinks (sorry, coffee or soda only). And also: Top 5 Finalists for the UCSD $50K Business Plan Competition will pitch to a round of judges live on stage. There will be a lunch session and the top 3 will be selected while judges are eating their specially selected food which stimulate their judging ability. Award ceremony to the top 3 will follow. There will be a bunch of people who have more knowledge and experience than you can ever imagine about business. You can talk to them.

When: Sat. May 31st. 9AM - 2PM
Where: CalIT2 Auditorium, Atkinson Hall. The map is pretty useless. It’s here because CalIT2 use it as their map link. Just go to the (Sony) Stone Dog Bear in Warren college at 9 AM on 5/31 and you will see a bunch of people in suits and you know you are at the right place.
Cost: Free
RSVP: Here
I’ve been in $50K for almost two years now, and this is going to be one event that I strongly recommend people going. Forget about the workshops that teach you how to write business plan. Forget about the mixers that introduce you to a network of entrepreneurs. This is about the selected few individuals that worked their way through three rounds of judging and present their ideas in a professional manner. Unless you’re thinking about working in a VC firm, how often do you see that?
Read more |
No Comments » |
May 22nd, 2008
Posted in Footprints + Diary | By tarotoast | Tags: babe, Wordpress
寶貝哈泥問我說要怎麼顯示所有 blog 裡面的文章,可是我也不記得我以前怎麼用了。印象中是用可以執行 PHP 的 Plugin 然後貼一小段程式碼,然後就讓他自己跑 query 列出全部。總之,沒有非常的簡單。
昨天在 rwiz 上不小心 (!?) 點了胸毛男的 blog 忽然間發現他家上有一頁 文件集 正是我在找的。馬上去問這頁怎麼生出來的,原來是 Smart Archives 這個 Plugin。配合好用的 Exec-PHP,Archives 頁終於生出來了 :D
Read more |
No Comments » |
May 21st, 2008
Posted in BSD+Linux, Ubuntu | By tarotoast | Tags: nx, remote desktop, vnc, vps

GDM over VNC was great, until I discovered FreeNX. FreeNX was based on NX technologies by NoMachine. Quoted from Wikipedia:
NX technology is a computer program that handles remote X Window System connections, and attempts to greatly improve on the performance of the native X11 protocol to the point that it can be usable over a slow link such as a dial-up modem.
You see that right, dial-up modem. It’s been three days now since I’ve installed FreeNX on the Hardy VPS on SliceHost. Result? Impressive. Not only there’s barely anything you have to configure, it also tunnels connections through ssh by default to give better security. What makes it a winning choice is that it does not get disconnected :) In the previous VNC setup, if I’m disconnected and server did not realize, I have to log in and do a kill-all-pid-by-user script to finish off all processes related to the dead x-session. Maybe there’s workaround (I’m pretty sure there is), but I didn’t bother looking it up. With NX, say byebye to disconnections and hello to the sweet working x-session. Installation instruction for Ubuntu Gusty and Hardy is availble here: Installing FreeNX in Ubuntu 7.10 Gutsy. Summary:
- Add apt-source and key:
deb http://www.datakeylive.com/ubuntu hardy main
deb-src http://www.datakeylive.com/ubuntu hardy main
wget http://www.datakeylive.com/ubuntu/dists/gutsy/wjeremy.key -O - | sudo apt-key add -
sudo apt-get update
- Install all necessary packages (seperately install X if you haven’t):
sudo apt-get install expect openssh-server tcl8.4 dbus-x11 libxcomp3 libxcompext3 libxcompshad nxlibs nxagent nxproxy nxclient freenx-server
- Make sure font path in /etc/X11/xorg.conf is set correctly like the following:
Section "Files"
# path to defoma fonts
FontPath "/usr/share/fonts/X11/misc"
FontPath "/usr/share/fonts/X11/100dpi/:unscaled"
FontPath "/usr/share/fonts/X11/75dpi/:unscaled"
FontPath "/usr/share/fonts/X11/Type1"
FontPath "/usr/share/fonts/X11/100dpi"
FontPath "/usr/share/fonts/X11/75dpi"
FontPath "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
EndSection
- Add user:
sudo nxserver --adduser xxxx
- Download Client
總之,很好用就是了 XD
Read more |
No Comments » |
May 20th, 2008
Recent Comments