declare(ticks=1);
// A function called on each tick event
function tick_handler()
{
if ( (time()-$nextWeek) > $CheckInterval)
{
echo "R";
$nextWeek = time();
}
}
如何close issue
指令有createIssue,但卻沒有close issue這指令
看了官網提的,應該是用progressWorkflowAction中的參數action將設為close
以下是官網的範例,用ruby寫的 # Close the issue with a resolution of "Fixed".
action = "2" # 2 = "Close". Note how this is actually a string, not an integer.
resolution_type = "1" # 1 = "Fixed". Also a string.
issue = soap.progressWorkflowAction(token, issue.key, action, [{ :id => "resolution", :values => resolution_type }])
判斷是否正確 $captcha = $request->getPost('captcha');
$captchaId = $captcha['id'];
// And here's the user submitted word...
$captchaInput = $captcha['input'];
// We are accessing the session with the corresponding namespace
// Try overwriting this, hah!
$captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_'.$captchaId);
// To access what's inside the session, we need the Iterator
// So we get one...
$captchaIterator = $captchaSession->getIterator();
// And here's the correct word which is on the image...
$captchaWord = $captchaIterator['word'] ;
// Now just compare them...
if ($captchaInput == $captchaWord)
echo "valid";
else
echo "invalid";
圖文表示
ex.
注意事項
要給ttf字型檔
$this->view->captcha = new Zend_Form_Element_Captcha(
'captcha', // This is the name of the input field
array('label' => 'Write the chars to the field',
'captcha' => array( // Here comes the magic...
// First the type...
'captcha' => 'Image',
// Length of the word...
'wordLen' => 4,
// Captcha timeout, 5 mins
'timeout' => 300,
// What font to use...
'font' => 'captcha/arial.ttf',
// Where to put the image
'imgDir' => 'captcha/tmp/',
//<img src="?" > 的位置
'imgUrl' => 'http://' . $this->_request->getHttpHost() . $this->_request->getBaseUrl() . '/captcha/tmp/'
)
)
);
不要點及線只要在建構子下... $captcha = new Zend_Form_Element_Captcha(
'captcha', // This is the name of the input field
array(
...
'lineNoiseLevel' => 0,
'dotNoiseLevel' => 0,
...
)
)
);
如果不要扭曲的字型,那就把_generateImage方法的內容改成以下程式碼 protected function _generateImage($id, $word)
{
if (!extension_loaded("gd")) {
require_once 'Zend/Captcha/Exception.php';
throw new Zend_Captcha_Exception("Image CAPTCHA requires GD extension");
}
if (!function_exists("imagepng")) {
require_once 'Zend/Captcha/Exception.php';
throw new Zend_Captcha_Exception("Image CAPTCHA requires PNG support");
}
if (!function_exists("imageftbbox")) {
require_once 'Zend/Captcha/Exception.php';
throw new Zend_Captcha_Exception("Image CAPTCHA requires FT fonts support");
}
$font = $this->getFont();
if (empty($font)) {
require_once 'Zend/Captcha/Exception.php';
throw new Zend_Captcha_Exception("Image CAPTCHA requires font");
}
Every day, a small ant arrives at work very early and starts work immediately.
每天,小螞蟻很早來上工,並且一來就開始做事。
She produces a lot was happy.
她的生產力很高,並且工作愉快。
The Chief, a lion,
was surprised to see that the ant was working without supervision.
身為老闆的獅子,非常驚奇螞蟻能自行工作而不須監督。
He thought if the ant can produce so much without supervision, wouldn’t she produce even more if she had a supervisor!
他認為在沒有監督下的螞蟻生產力是如此的好,如果有人監督的話她的生產力應該會更好才對!
So he recruited a cockroach
who had extensive experience as supervisor and who was famous for writing excellent reports.
因此他招募了有豐富經驗的蟑螂作為監督員,蟑螂以擅長撰寫優良報告而聞名。
The cockroach’s first decision was to set up a clocking in attendance system.
蟑螂的第一個決定是設立了打卡計時系統。
He also needed a secretary to help him write and type his reports and …
他也需要一個秘書幫助他繕寫和鍵入報告和……
... he recruited a spider, who managed the archives and monitored all phone calls.
他招募了蜘蛛,負責管理檔案和監管所有電話。
The lion was delighted with the cockroach's reports
and asked him to produce graphs to describe production rates and to analyse trends, so that he could use them for presentations at Board‘s meetings.
獅子對蟑螂的報告非常高興並要求他用圖表描述生產率和分析趨勢變化,因而他能在董事會上用這些資料來報告。
So the cockroach had to buy a new computer and a laser printer and ...
因此蟑螂必須買一臺新的電腦和雷射印表機和…
... recruited a fly
to manage the IT department.
.. 並招募蒼蠅來管理資訊部門。
The ant, who had once been so productive and relaxed, hated this new plethora of paperwork and meetings which used up most of her time…!
曾經是很有生產力和輕鬆的螞蟻,恨透了這些耗盡她大多數時間的過多文書作業和會議…!
The lion came to the conclusion that it was high time to nominate a person in charge of the department where the ant worked.
獅子做出結論這是提名螞蟻工作部門負責人的時候了。
The position was given to the cicada, whose first decision was to buy a carpet and an ergonomic chair for his office.
這個位置被賦予給了蟬,蟬的第一個決定是為他的辦公室買一張地毯和一把符合人體工學的椅子。
The new person in charge, the cicada, also needed a computer and a personal assistant, who he brought from his previous department, to help him prepare a Work and Budget Control Strategic Optimisation Plan …
新的人負責,蟬,也需要一部電腦和一位從他原先部門帶來的個人助理,來幫助他準備工作和預算控制策略優化計劃…
The Department where the ant works is now a sad place, where nobody laughs anymore and everybody has become upset...
螞蟻工作的部門現在是一個哀傷的地方,不再有人會笑,而且大家變得抓狂…
It was at that time that the cicada convinced the boss , the lion, of the absolute necessity to start a climatic study of the environment .
就是那時蟬說服獅子上司,強調要開始進行組織氣候調查的绝對必要性。
Having reviewed the charges for running the ant’s department , the lion found out that the production was much less than before.
在審查了螞蟻的部門運作費用後,獅子發現生產力比以前大幅減少。
So he recruited the owl , a prestigious and renowned consultant to carry out an audit and suggest solutions.
所以他招募了貓頭鷹,一位有名望和顯耀的顧問來執行稽核工作並建議解決之道。
The owl spent three months in the department and came up with an enormous report , in several volumes,
that concluded :
“ The department is overstaffed ...”
貓頭鷹在部門待了三個月並且產生了一份有數冊之多的巨大的報告,結論是:「部門成員人數過多…」
Guess who the lion fires first?
猜猜獅子首先解雇誰?
The ant , of course, because she
“showed lack of motivation and had a negative attitude".
當然,是螞蟻,因為她「顯現出缺乏做事的動機並且態度消極」。
The characters in this fable are fictitious; any resemblance to real people or facts within the Corporation is pure coincidence…
這個寓言裡的人物是虛擬的; 若與公司內部任何的人物或情事雷同係純屬巧合
dynamically load jquery if 'jQuery' does not exist function initJQuery() { //if the jQuery object isn't available
if (typeof(jQuery) == 'undefined') {
if (typeof initJQuery.jQueryScriptOutputted == 'undefined') { //only output the script once..
initJQuery.jQueryScriptOutputted = true; //output the script (load it from google api)
document.write("");
}
setTimeout("initJQuery()", 50);
} else {
(function($){ // CLOSURE -> save to use $
$.fn.foo = function(input) {
alert("foo:" + input) ;
} ;
})(jQuery) ;
}
window.onload = function() {
$('body').foo("bar") ; // won't necessarily fire if jQuery loads after document load
}
}
initJQuery();
PHP is a _____ scripting language based on the ____ engine. It is primarily used to
develop dynamic _____ content, although it can be used to generate ____ documents
(among others) as well.
A.Dynamic, PHP, Database, HTML
B.Embedded, Zend, HTML, XML
C.Perl-based, PHP, Web, Static
D.Embedded, Zend, Docbook, MySQL
E.Zend-based, PHP, Image, HTML
Result: B
Looking at the answers, the only one that makes sense for every blank is B. PHP is a
scripting language based on the Zend Engine that is usually embedded in HTML code. As
such, it is primarily used to develop HTML documents, although it can be used just as nicely to develop other types of documents, such as XML.
16.Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?
A.When the parameter is Boolean
B.When the function is being declared as a member of a class
C.When the parameter is being declared as passed by reference
D.When the function contains only one parameter
E.Never
Answer:
When a parameter is declared as being passed by reference you cannot specify a default
value for it, since the interpreter will expect a variable that can be modified from within the
function itself. Therefore, Answer C is correct.
17.The ____ operator returns True if either of its operands can be evaluated as True, but not both.
Answer: xor
用法$result = ($A xor $B);
19. Which of the following expressions multiply the value of the integer variable $a by 4?
(Choose 2)
$a *= pow (2, 2);
$a >>= 2;
$a <<= 2;
$a += $a + $a;
None of the above
Result: A,C 嗯 是往左... 我怎麼會想成往右...
Open for reading only; place the file pointer at the
beginning of the file.
'r+'
Open for reading and writing; place the file pointer at
the beginning of the file.
'w'
Open for writing only; place the file pointer at the
beginning of the file and truncate the file to zero length.
If the file does not exist, attempt to create it.
'w+'
Open for reading and writing; place the file pointer at
the beginning of the file and truncate the file to zero
length. If the file does not exist, attempt to create it.
'a'
Open for writing only; place the file pointer at the end of
the file. If the file does not exist, attempt to create it.
'a+'
Open for reading and writing; place the file pointer at
the end of the file. If the file does not exist, attempt to
create it.
'x'
Create and open for writing only; place the file pointer at the
beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and
generating an error of level E_WARNING. If
the file does not exist, attempt to create it. This is equivalent
to specifying O_EXCL|O_CREAT flags for the
underlying open(2) system call.
'x+'
Create and open for reading and writing; otherwise it has the
same behavior as 'x'.
'c'
Open the file for writing only. If the file does not exist, it is
created. If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails (as is
the case with 'x'). The file pointer is
positioned on the beginning of the file. This may be useful if it's
desired to get an advisory lock (see flock())
before attempting to modify the file, as using 'w' could truncate the file before the lock
was obtained (if truncation is desired, ftruncate() can be used after the lock is
requested).
'c+'
Open the file for reading and writing; otherwise it has the same
behavior as 'c'.
如果檔案不存在,用w,w+,a, and a+會自動建立新檔
如果檔案已存在,用x及x+會產生E_WARNING fgets reads a line -- i.e. it will stop at a newline.
fread reads raw data -- it will stop after a specified (or default) number of bytes, independantly of any newline that might or might not be present.
SEEK_CUR - Set position to current location plus offset.
SEEK_END - Set position to end-of-file plus offset.
範例
<?php
$fp = fopen('somefile.txt', 'r');
// read some data
$data = fgets($fp, 4096);
// move back to the beginning of the file
// same as rewind($fp);
fseek($fp, 0);
?>
Simple File Functions
get data
// Old Way
$file = implode("\r\n", file("myfile.txt"));
// New Way
$file = file_get_contents("myfile.txt");
The error code associated with this file. A value of
UPLOAD_ERR_OK indicates a successful transfer, while any other
error indicates that something went wrong (for example, the
file was bigger than the maximum allowed size).
String Basics
單引號用在"Simple strings" //almost all characters are used literally
雙引號用在"Complex strings" //alow for special escape sequences Variable Interpolation //單、雙引號差別
$who = "World";
echo "Hello $who\n"; // Shows "Hello World" for followd by new line
echo 'Hello $who\n'; // shows "Hello $who\n"
//無空格連接
$me = 'Davey';
echo "There cannot be more than tw {$me}s!"; //s緊連接在$me後
Returning Values
function可以call by reference
但回傳值就必需有變數
//example 1
function &query($sql)
{
$result = mysql_query($sql);
return $result; //return variable
}
//example 2, incorrect and will cause PHP to emit a notice when called
function &getHollo()
{
return "Hello World"; //非variable
}
//example 3 also cause the warning to be issued when called
function &test()
{
echo 'This is a test';
}
Passing Arguments
function hello($who = "World")
{
echo "Hello $who";
}
hello(); //pass in no argument and $who is assigned "World" by default
Arrays
Array Basic
$x[] = 10;
$x['aa'] = 11;
echo $x[0]; //Outputs 10
//continue, what if
$x[0]=12; //
echo $x[0]; //Outputs 12, 蓋掉了
另外新增元素會從Array中最大的數值增加
$a = array(2 => 5);
$a[] = 'a'; //This will have a key of 3
$b = array( '4' => 5,'a' => 'b');
$a[] = 44; //This will have a key of 5<$/code>
//匯出
select * into outfile '/mdr/data/UNLOAD/檔名.sql' from [TableName] where ITEM='409667';
//匯入
load data infile '/mdr/data/UNLOAD/檔名.sql' into table [TableName]
Author - You name, and the name of anyone who helped or who's work you modified
Version - What version of the script is this? 1.0? 2.3? etc....
Installation Time - An idea of how long it will take the user to be up and running.
Included Files / Edited Files - This is a list of files that are part of your script, and in the case of a mod, files that will need to be edited.
Licensing - Make sure it's clear how the user may and may not use your script.
History - History of the mod including the change log of all previous versions.
Other Notes - Any other information you want to include about your script, including your support website (if you have one) or other information that may be useful
var obj = { "date": "2009-03-05", "amount": "0.1" };
var clonedObj = JSON.clone(obj);
A more elegant browser independent solution comes from Marijn Haverbeke (Elegant JavaScript): function clone(o) {
function OneShotConstructor(){}
OneShotConstructor.prototype = o;
return new OneShotConstructor();
}
最後查一下jQuery本身的方法
利用extend的方法來當成一個新的
雖然感覺...怪怪的...
不過也算是簡單的達到目的了 var shot = {id:1,x=2,y=3};
//Method 2 jQuery.extend( [ deep ], target, object1, [ objectN ] ) v1.1.4
var newShot = jQuery.extend(true, {}, shot); //沒有target,而是直接return
Zend_Translate is Zend Framework's solution for multilingual applications.
In multilingual applications, the content must be translated into several languages and display content depending on the user's language. PHP offers already several ways to handle such problems, however the PHP solution has some problems
designed to simplify access to, and use of , configuration data within applications.
Multiple Environs
PHP Array <?php
//Given an array of configuration data
$configArray = array(
'webhost' => 'ww.example.com',
'database' => array(...
)
);
//Create the object-oriendted wrapper upon the configuration dataconsumption
require_once 'Zend/Config.php';
$config = new Zend_Config(configArray );
//Print a configuration datum (results in 'ww.example.com')
<?php
//Configuration consumption
require_once 'Zend/Config.php';
$config = new Zend_Config(require 'config.php');
//Print a configuration datum (results in 'ww.example.com')
echo $config->webhost;
Zend_Config實作了Countable及Iterator interfaces,因此可用count()及foreach
Two Zend_Config objects can be merged into a single object using the merge() function
$config = new Zend_Config_Ini('/path/to/config.ini'),'staging');
echo $config->database->params->hosts;
[staging:production] //staging繼承production的變數
不要把變數內容值用單引號包起來,會把單引號當成值
Zend_Config_Xml
$config = new Zend_Config_Xml('/path/to/config.xml'),'staging');
echo $config->database->params->hosts;
Bootstrap File
Config Objects
Zend_Exception
Purpose: recover from the failure <?php
try{
Zend_Loader::loadClass('nonexistantclass');
}catch (Zend_Exception $e){
echo "Caught exception: " . get_class($e) . "\n";
echo "Message: " . $e->getMessage() . "\n";
//other code to recover from the failure;
}
Zend_Registry
Purpose: a container for storing objects and values in the application space.
Constructing a Registry <?php
$registry = new Zend_Registry(array('index' => $value));
Initializing the Static Registry <?php
Zend_Registry::setInstance(array('index' => $value));
The setInstance() method throws Zend_Exception if the static registry has already been initialized
Zend_Loader
Purpose: includes methods to help you load files dynamically
Zend_Loader::loadFile($filename,$path,$once) is a wrapper for the PHP function include() and throws Zend_Exception on failure.
limit: $filename argument can only contain alphanumeric characters, hyphens("-"), or periods("."), and must not contain any path information.
$once is boolean, if TRUE, equals include_once(), otherwise include() is used.
Zend_Session
Purpose: helps manage and preserve session data, a logical complement of cookie data, across multiple page requests by the same client.
Zend_Session_Namespace
就是PHP中的$_SESSION $sess = new Zend_Session_Namespace();
$sees->tree = $tree;
Operation
當第一個session被requested時,Zend_Session就自動啟動PHP session,不必等到Zend_Session::start().
The PHP session will use defaults from Zend_Session, unless modified by Zend_Session::setOptions().
寫法(from 官網) class FooController extends Zend_Controller_Action
{
public function barAction()
{
// Add two actions to the stack
// Add call to /foo/baz/bar/baz
// (FooController::bazAction() with request var bar == baz)
$this->_helper->actionStack('baz',
'foo',
'default',
array('bar' => 'baz'));
// Add call to /bar/bat
// (BarController::batAction())
$this->_helper->actionStack('bat', 'bar');
用法 // Query
$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
mysql_real_escape_string($user),
mysql_real_escape_string($password));