Drupal 是一個CMS, 它除了有很多 PHP 的函數 可以調用之外,
還有在頁面的 javascript 加了一些常用的變數, 函數
你可以在 firebug 或者 chrome 的 developer console內,
用 Drupal.* 找到它們
例如 PHP 函數<?php base_path()?> 可以在 Drupal.settings.basePath 內找到
所以 AJAX 的要求路徑便可以隨網站路徑自動改變了
Drupal 是一個CMS, 它除了有很多 PHP 的函數 可以調用之外,
還有在頁面的 javascript 加了一些常用的變數, 函數
你可以在 firebug 或者 chrome 的 developer console內,
用 Drupal.* 找到它們
例如 PHP 函數<?php base_path()?> 可以在 Drupal.settings.basePath 內找到
所以 AJAX 的要求路徑便可以隨網站路徑自動改變了
我的code 很簡單, 做test driven development 寫test的時候
pass in 的data 很多時候都要重用
只是其中一個field 的值修改, 其餘的都不變
所以:
<?php
function testSubmit(){
//init. data
$data = array(
'user' => 'abc',
'password' => 'def',
);
//copy array
$test = array_merge($data);
//change value
$test['user'] = '';
//test
$this->assertTrue(foo($test));
//copy again
$test = array_merge($data);
//change value
unset($test['user']);
//test
$this->assertTrue(foo($test));
}
?>那我便可以方便的修改pass in 的data (只修改一個地方)
重點是, array 的複製要使用 array_merge()...