Helpers

Helpers

这些功能也许应用于很多方面。

截获命令

Capture让你提取代码的部分放入实例的变量中,这些变量可硬在其他的template中使用,或者在layout文件中使用。

截取一块放入实例的变量中

<?php $capture_helper->begin (); ?> 
    [some html...] 
<?php $script = $capture_helper->end (); ?>

使用content_for在头部添加javascript

$capture_helper→content_for(“name”); is a wrapper for Capture which will store the fragment in an instance variable similar to $content_for_layout.

Example:
layout.tpl:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
        <title>layout with js</title> 
        <script type="text/javascript"> {content_for_script} </script> 
    </head> 
    <body> {content_for_layout} </body> 
</html>

view.tpl:
This page shows an alert box!

<?php $capture_helper->begin ('script'); ?>
    alert('hello world'); 
<?php $capture_helper->end (); ?>
Normal view text

distance_of_time_in_words

语法:
distance_of_time_in_words( $from_time, [ $to_time = 0], [ $include_seconds = false])
描述:
Reports the approximate difference in time between $from_time and $to_time in an ISO string translated to the current language:

Time Difference Message
< 20 seconds less than x seconds*
< 40 seconds less than half a minute*
< 60 seconds less than a minute
1 minute 1 minute
< = 45 minutes x minutes
< = 90 minutes about 1 hour
< = 1440 minutes about x hours
< = 2880 minutes 1 day
> 2880 minutes x days

* reported only if $include_seconds = true; otherwise “less than a minute”.

distance_of_time_in_words_to_now

语法:
distance_of_time_in_words_to_now ( $from_time, [ $include_seconds = false])
描述:
Reports the approximate difference in time between $from_time until now (the current time) in an ISO string translated to the current language:

Time Difference Message
< 20 seconds less than x seconds*
< 40 seconds less than half a minute*
< 60 seconds less than a minute
1 minute 1 minute
< = 45 minutes x minutes
< = 90 minutes about 1 hour
< = 1440 minutes about x hours
< = 2880 minutes 1 day
> 2880 minutes x days

* reported only if $include_seconds = true; otherwise “less than a minute”.

locale_date

语法:
locale_date( [ $iso_date ])
描述:
转换ISO date (format: yyyy-mm-dd)到当前的时间格式。如果$iso_date被省略,假设为当前的时间。

locale_date_time

语法:
locale_date_time( [ $iso_date_time = null])
描述:
Converts an ISO date/time (format: yyyy-mm-dd hh:mm:ss) to the current locale format. If $iso_date_time is omitted, the current date/time is assumed.

time_ago_in_words

语法:
time_ago_in_words ( $from_time, [ $include_seconds ])
描述:
Reports the approximate distance in time between $from_time and timestamp() (the current time) in an ISO string translated to the current language:

Time Difference Message
< 20 seconds less than x seconds*
< 40 seconds less than half a minute*
< 60 seconds less than a minute
1 minute 1 minute
⇐ 45 minutes x minutes
⇐ 90 minutes about 1 hour
⇐ 1440 minutes about x hours
⇐ 2880 minutes 1 day
> 2880 minutes x days

* reported only if $include_seconds = true; otherwise “less than a minute”.

_add_one

Syntax:
_add_one( $number)
Description:
Returns $number++ or $number+1

_leading_zero_on_single_digits

语法:
_leading_zero_on_single_digits( $number)
描述:
This returns

$number > 9 ? $number : "0$number";
 
helpers_cn.txt · Last modified: 2008/08/04 08:39 by liyh
 

The Akelos Framework was created by Bermi Ferrer and other contributors.
Potions of the code and documentation have been ported from Ruby on Rails.

The Akelos Framework is released under the LGPL license.

"Akelos", "Akelos Framework", and the Akelos logo are trademarks of Bermi Labs All rights reserved.

Wiki driven by DokuWiki