Drupal 是一套開放源碼的內容管理平台,擁有多種實用的功能,可以用來建置從個人網誌到大型網路社群等各種類型的網站,例如華納唱片、紐約觀察報、Fast Company、Popular Science、SonyBMG、富比士、哈佛大學等網站,或是個人部落格(Tim Berners-Lee)、播客網站(TWIT.tv)、線上社群(SpreadFireFox.com)。
Drupal 是一套開放源碼的內容管理平台,擁有多種實用的功能,可以用來建置從個人網誌到大型網路社群等各種類型的網站,例如華納唱片、紐約觀察報、Fast Company、Popular Science、SonyBMG、富比士、哈佛大學等網站,或是個人部落格(Tim Berners-Lee)、播客網站(TWIT.tv)、線上社群(SpreadFireFox.com)。
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
typo ?
$node->field-final => $node->field_final
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
改了之後發現還是沒作用, 然後隨便打些一定不存在的指令 (就亂打一些 ooxx), 竟然也沒有錯誤訊息?
下面是 Rules debug 內容, 從 php_eval 旁邊的 edit 就可以跳到 php code 的編輯畫面.
看來 Rules 似乎是有去執行 php code, 但又好像什麼都沒執行到?
Rules debug information:
" Reacting on event Before saving content.
0 ms Reacting on event Before saving content.
12.607 ms Evaluating conditions of rule RULE_TEST. [edit]
13.194 ms The condition node_is_of_type evaluated to TRUE [edit]
13.209 ms AND evaluated to TRUE.
" Rule RULE_TEST fires. [edit]
0 ms Rule RULE_TEST fires.
0.357 ms Evaluating the action php_eval. [edit]
0.544 ms Rule RULE_TEST has fired.
13.802 ms Finished reacting on event Before saving content.
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
嗯 php_eval 只亂打一堆文字,有可能直出一堆文字,所以不會有錯
用 die() 這些就能中斷
試試
debug($node);
dpm($node);
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
我試了這幾個, 統統沒反應... 在 Drupal 7 裡面要使用 php code 有什麼特別的設定要打開嗎? 可是我有個 block 裡面寫 php 都正常啊.
die("xxx");
debug($node);
dpm($node);
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
沒有特別設定
exported code:
{ "rules_df" : {"LABEL" : "df",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "php", "rules" ],
"ON" : [ "node_presave" ],
"DO" : [ { "php_eval" : { "code" : "debug($node);\r\ndie();" } } ]
}
}
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
請問一下上面的 exported code 是怎樣才會顯示出來? 又, 我用 fopen() 去寫檔案, 結果沒有錯誤訊息, 也沒有檔案產生.
看來似乎是 php 程式完全被忽略, 不知道是什麼原因 :(
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
你不是用 Rules 嗎 ??
/admin/config/workflow/rules
tested version: 7.x-2.x-dev
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
啊, 查出來了, 是 condition 搞的鬼, 拿掉就會跑 php 程式了. 然後重新設定一次就可以了, 只是忘了備份原來的 condition, 沒法確定是不是之前寫錯了.
原來 Rules 可以直接 export code 出來, 我一直沒注意到旁邊那個 Export 的功能 :p
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
測了幾次看來是沒問題了, 下面的程式碼就可以了
$node->field_final['und'][0]['value'] = [node:field-a] + [node:field-b]
不過比較奇怪的是, 寫成 $node->field-final 沒作用也沒有錯誤訊息
Re: 把 node 在儲存前後的某個 field 拿來計算 (Rules or Trigger, Action?)
可能你關掉了