เพิ่ม callback ให้กับ model ที่ใช้ plugin ยังไงครับ?

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ทำไมพักนี้ฝั่ง ruby เงียบเหงาจังเลย ผมถามซักหน่อยดีกว่า

ตอนนี้ผมกำลังเขียน plugin แนว acts_as_xxx อยู่ครับ
คราวนี้ ผมอยากให้ model ที่ใช้ plugin ของผม มี callback method
เพิ่มขึ้น ต้องทำยังไงอ่ะครับถึงจะอ้างอิงถึง callback ที่มีอยู่ใน modelนั้นได้
เช่นพวก after_create, etc...

>> ต้องทำยังไงอ่ะครับถึงจะอ้างอิงถึง callback ที่มีอยู่ใน modelนั้นได้

ขยายความตรงนี้หน่อยสิครับ

taiko_gogo's picture

คืออย่างนี้ครับ
สมมุติ ผมมี model ที่ไว้ใช้จัดการ memberอยู่ ชื่อว่า Member
แล้วก็มี model ที่ใช้จัดการ message ชื่อ Message
ผมเขียน plug in มาตัวหนึ่ง เพื่อเพิ่ม method เกี่ยวกับ
การรับส่ง message ชื่อว่า acts_as_messagable

ตัวMember โดด ๆเลย ผมไม่ได้ implement callback methodอะไรไว้ซักอย่าง

ผมอยากเพิ่ม callback after_destroy ให้กับ Member เพื่อให้สามารถ
ทำการลบ message ทุกตัวของ memberคนนั้น ๆ ได้
โดยimplement ไว้ใน plug in ปัญหาคือผมจะอ้างหา callback
after_destroy ของ Member ใน code plug in ที่ผมเขียนได้ยังไง

ตะกี้ผมลองเปิด codeของ acts_as_taggable ดู แล้วลอง
อ้างถึง after_destroy เลียนแบบในนั้นดู โดยอ้างอิง
after_destroy ข้างใน module ClassMethods ที่ implement
ไว้ใน plugin ปรากฎว่า เรียกได้ครับ ตอนนี้ผมเลยผ่านตรงนี้ไปได้แล้ว
ขอบคุณพี่ป๊อกมากครับ

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น