MT4.x¥×¥é¥°¥¤¥óºîÀ®/¿·¤·¤¤¥â¥Ç¥ë¥ª¥Ö¥¸¥§¥¯¥È¤ÎºîÀ® http://www.ark-web.jp/sandbox/wiki/302.html

MT4.x¥×¥é¥°¥¤¥óºîÀ®/¿·¤·¤¤¥â¥Ç¥ë¥ª¥Ö¥¸¥§¥¯¥È¤ÎºîÀ®

[edit]

MT::Object¤ÈMT::Object¤ò·Ñ¾µ¤¹¤ëÍøÅÀ

MT¤Ç¤Ï¥¹¥È¥ì¡¼¥¸¡ÊDBM¥Õ¥¡¥¤¥ë¤äDB¡Ë¤Ë¥·¥ê¥¢¥é¥¤¥º¡¿Êݸ¤¹¤ë¤¹¤Ù¤Æ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ÏÁ´¤ÆMT::Object¤ò¥Ù¡¼¥¹¥¯¥é¥¹¤È¤·¤Æɽ¸½¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤¿¤È¤¨¤Ð¡¢¥¨¥ó¥È¥ê¡¼¤òɽ¤¹MT::Entry¤ÏMT::Object¤ò·Ñ¾µ¤·¤Æ¤¤¤Æ¡¢DB¤òÍøÍѤ·¤Æ¤¤¤ë¾ì¹ç¤Ç¤¢¤ì¤Ðmt_entry¥Æ¡¼¥Ö¥ë¤ËɳÉÕ¤±¤é¤ì¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ë¤è¤Ã¤Æ¡¢mt_entry¤Ë¤¢¤ë³Æ¥«¥é¥à¤ÎÃͤÏMT::Entry¤ò»È¤Ã¤Æ¼¡¤Î¤è¤¦¤Ë¥¢¥¯¥»¥¹¤Ç¤­¤Þ¤¹¡£

# entry_id=1¤Î¥¨¥ó¥È¥ê¡¼¤ò¼èÆÀ
my $entry = MT::Entry->load({id => 1});
# ¥¿¥¤¥È¥ë¤ò¼èÆÀ(DBÍøÍÑ»þ¤Ç¤¢¤ì¤Ðmt_entry.title¤ÎÃͤ¬¼èÆÀ¤µ¤ì¤ë¡Ë
$title = $entry->title; 
# ¥¿¥¤¥È¥ëÊѹ¹
$entry->title('¿·¤·¤¤¥¿¥¤¥È¥ë'); 
# Êѹ¹¤òÊݸ
$entry->save or die $entry->errstr;

¤³¤Î¤è¤¦¤ËMT::Object¤ò·Ñ¾µ¤·¤¿¥¯¥é¥¹·²¤ÏMT¤Ë¤ª¤¤¤ÆMVC¥â¥Ç¥ë¤Ë¤ª¤±¤ë¥â¥Ç¥ë¥¯¥é¥¹¡Ê¥â¥Ç¥ë¥ª¥Ö¥¸¥§¥¯¥È¡Ë¤ÎÌò³ä¤ò²Ì¤¿¤·¤Æ¤¤¤Þ¤¹¡£¤Þ¤¿¡¢MT::Object¤Ï¥æ¡¼¥¶¡Ê¤³¤³¤Ç¤Ï³«È¯¼Ô¡Ë¤ËÂФ·¤Æ¼¡¤ÎÍøÅÀ¤ò¤â¤¿¤é¤·¤Þ¤¹¡£

¤½¤·¤Æ¡¢¥æ¡¼¥¶¤ÏMT::Object¤ò·Ñ¾µ¤·¤¿¿·¤·¤¤¥â¥Ç¥ë¤òºîÀ®¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£
¤·¤«¤â¡¢¤³¤ÎÊýË¡¤ò»È¤¦¤³¤È¤Ç¥æ¡¼¥¶¤ÏDB¤ò»È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ç¤â¡¢DB¤òľÀÜÁàºî¤¹¤ë¤³¤È¤Ê¤¯¡¢¥Æ¡¼¥Ö¥ë¡¢¥«¥é¥à¤ÎÄɲá¢Êѹ¹¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¡¢DB¤Î¥¢¥Ã¥×¥°¥ì¡¼¥É¤â¼«Æ°¤Ç¹Ô¤¦¤è¤¦¤Ê»ÅÁȤߤòÍøÍѤǤ­¤Þ¤¹¡£

[edit]

¥â¥Ç¥ë¥ª¥Ö¥¸¥§¥¯¥È¤ÎºîÀ®

Îã¤È¤·¤Æ¡¢¾¦ÉʤȤ¤¤¦¥â¥Ç¥ë¤ÎºîÀ®¤ò¹Í¤¨¤Æ¤ß¤Þ¤¹¡£MT¥Ù¡¼¥¹¤ÎEC¥·¥¹¥Æ¥à¤Ê¤É¤ò¹Í¤¨¤ë¾ì¹ç¤ËºîÀ®¤µ¤ì¤½¤¦¤Ç¤¹¤Í^^

°Ê²¼¤ÎÀßÄê¤ÇºîÀ®¤·¤Þ¤¹¡£

¥â¥Ç¥ë̾Product
¥¯¥é¥¹MT::Product
¥Õ¥¡¥¤¥ë¥Ñ¥¹¡ÊMT¤Î¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê¤«¤é¤ÎÁêÂХѥ¹plugins/Product/lib/MT/Product.pm

¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òplugins¤ÎÇÛ²¼¤Ë¤·¤Æ¤¤¤Þ¤¹¤¬¡¢¤³¤ì¤ÏPlugin¤È¤·¤ÆºîÀ®¤¹¤ë¤³¤È¤Ç¡¢

»²¹Í¡§MovableType³ÈÄ¥¥×¥é¥°¥é¥ß¥ó¥°¤Ë´Ø¤¹¤ë10¤ÎÎɤ¤½¬´·¡£

¢¨ plugins/Product¤Î¥Ç¥£¥ì¥¯¥È¥ê̾¤Ï¤¿¤Þ¤¿¤Þ¥â¥Ç¥ë̾¤È°ìÃפµ¤»¤Æ¤¤¤Þ¤¹¤¬¡¢Â¾¤Î̾Á°¤Ç¤âÌäÂꤢ¤ê¤Þ¤»¤ó¡£¤³¤Î¥Ç¥£¥ì¥¯¥È¥ê̾¤Ï¥×¥é¥°¥¤¥ó̾¤Ë°ìÃפ¹¤ë¤Î¤Ç¡¢Î㤨¤Ð¥×¥é¥°¥¤¥ó̾¤òShop¤Ë¤¹¤ë¤Î¤Ç¤¢¤ì¤Ð¡¢Product¥â¥Ç¥ë¤Ïplugins/Shop/lib/MT/Product.pm¤ËºîÀ®¤¹¤ì¤ÐOK¤Ç¤¹¡£

Product¤Î¥Ç¡¼¥¿¹½Â¤¤ÏID¤È¾¦ÉÊ̾¡¢¾¦ÉÊÀâÌÀ¡¢ÈÎÇä²ÄǽÆü¡¢²Á³Ê¤È¤¤¤Ã¤¿¥·¥ó¥×¥ë¤Ê·Á¤Ë¤·¤Æ¤ß¤Þ¤¹¡£

¥×¥í¥Ñ¥Æ¥£·¿Â°À­Ì¾¡Ê°ÕÌ£¡Ë
idinteger not nullID
namestring(255) not null¾¦ÉÊ̾
descriptiontext not null¾¦ÉÊÀâÌÀ
available_atdatetimeÈÎÇä²ÄǽÆü
priceinteger not null²Á³Ê

·¿¤Ë¤ÏÏÀÍýÃͤò¼¨¤¹boolean¤ätimestamp¡¢smallint¡¢bigint¡¢float¡¢blobÅù¤¬»È¤¨¤Þ¤¹¡£

¢¨ lib/MT/ObjectDriver/DDL.pm¤Îdb2type()¤ò¸«¤ÆÄ´¤Ù¤Æ¤¤¤ë¤Î¤Ç¡¢¤¢¤ä¤Þ¤ê¤¬¤¢¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£¥É¥­¥å¥á¥á¥ó¥È¤¬¸«¤Ä¤«¤é¤º¡¦¡¦¡¦

°Ê¾å¤«¤é¡¢MT::Products¥¯¥é¥¹(plugins/Product/lib/MT/Product.pm)¤Ï¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£

 1:  package MT::Product;
 2:
 3:  use strict;
 4:
 5:  use MT::Object;
 6:  @MT::Product::ISA = qw(MT::Object);
 7:
 8:  __PACKAGE__->install_properties({
 9:          column_defs => {
10:                  'id' => 'integer not null',
11:                  'name' => 'string(255) not null',
12:                  'description' => 'text not null',
13:                  'available_at' => 'datetime',
14:                  'price' => 'integer not null',
15:          },
16:          indexes => {
17:                  'id' => 1,
18:                  'available_at' => 1,
19:          },
20:          audit => 1,
21:          datasource => 'product',
22:          primary_key => 'id'
23:  });
24:
25:  1;

install_properties¥á¥½¥Ã¥É¤Îkey = column_defs¤Ë¥Ç¡¼¥¿¹½Â¤¤ò¥×¥í¥Ñ¥Æ¥£ => ·¿¤Î¥Ï¥Ã¥·¥å¤Ç¥»¥Ã¥È¤·¤Þ¤¹¡£

indexes¤Ïindex¤ò¤Ï¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤷ¤Þ¤¹¡£index¤ËÂбþ¤·¤Æ¤¤¤ëDB¤Ç¤¢¤ì¤Ð¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£

[edit]

¥×¥é¥°¥¤¥ó¤ÎºîÀ®¤È¼«Æ°¥¢¥Ã¥×¥°¥ì¡¼¥É

ºîÀ®¤·¤¿¥â¥Ç¥ë¤òÍøÍѤ¹¤ë¥×¥é¥°¥¤¥ó¤òºîÀ®¤·¤Þ¤¹¡£

¥¯¥é¥¹Ì¾¡¢¥Õ¥¡¥¤¥ë̾¤Ï²¿¤Ç¤â¤è¤¤¤Ç¤¹¤¬¡¢°Ê²¼¤ÎÀßÄê¤Ë¤·¤Æ¤ª¤­¤Þ¤¹¡£

¥¯¥é¥¹Ì¾MT::Plugin::Product
¥×¥é¥°¥¤¥óplugins/product.pl

¥×¥é¥°¥¤¥ó¤Ç¤Ï

use vars qw( $VERSION $SCHEMA_VERSION );
$SCHEMA_VERSION = '0.2';

¤Î¤è¤¦¤Ë$SCHEMA_VERSION¤òÄêµÁ¤·¡¢¥×¥é¥°¥¤¥ó¥ª¥Ö¥¸¥§¥¯¥È¤Înew¤Ç

my $plugin = new MT::Plugin::Product({
    name => '<MT_TRANS phrase=\'InquiryForm Plugin\'>',
     :
    schema_version => $SCHEMA_VERSION,
     :
    object_classes => [
        'MT::Product',
    ],
});

¤Î¤è¤¦¤Ëschema_version¤Èobject_classes¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤷ¤Þ¤¹¡£

object_classes¤Ë¤ÏÍøÍѤ¹¤ë¥â¥Ç¥ë¥¯¥é¥¹Ì¾¤òÇÛÎó¤Î»²¾È¤Ç»ØÄꤷ¤Þ¤¹¡£Ê£¿ô¤Î¥â¥Ç¥ë¥¯¥é¥¹¤Î»ØÄê¤â²Äǽ¤Ç¤¹¡£¤½¤·¤Æ¡¢schema_version¤Ë¤Ï¤³¤Î¥×¥é¥°¥¤¥ó¤ÎDB¥¹¥­¡¼¥Þ¡Ê¢âÍøÍѤ¹¤ë¥â¥Ç¥ë¥¯¥é¥¹¡Ë¤Î¥Ð¡¼¥¸¥ç¥ó¤òɽ¸½¤·¤Þ¤¹¡£

¸å¤Ï¡¢Ä̾ï¤Î¥×¥é¥°¥¤¥ó¤Èºî¤êÊý¤Ï²¿¤âÊѤï¤ê¤Þ¤»¤ó¡£¥×¥é¥°¥¤¥ó¤òºîÀ®¤·¤¿¸å¡¢mt.cgi¤Ë¥Ö¥é¥¦¥¶¤«¤é¥¢¥¯¥»¥¹¤¹¤ë¤È¡¢DB¥¢¥Ã¥×¥°¥ì¡¼¥É¤òÂ¥¤¹²èÌ̤¬É½¼¨¤µ¤ì¡¢¤½¤Î¤Þ¤Þ¥¢¥Ã¥×¥°¥ì¡¼¥É¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡£

¤Þ¤¿¡¢³«È¯¤ò¿Ê¤á¤Æ¤¤¤¯Ãæ¤Ç¡¢product.pl¤¬ÍøÍѤ·¤Æ¤¤¤ë¥â¥Ç¥ë¥¯¥é¥¹¤Î¥¹¥­¡¼¥Þ¤¬ÊѲ½¤·¤¿¤È¤·¤Þ¤¹¡£¤½¤Î»þ¤Ï¡¢product.pl¤Î$SCHEMA_VERSION¤ò¤¢¤²¤Æ¤ä¤ì¤Ð¡¢ºÆÅÙmt.cgi¤Ë¥¢¥¯¥»¥¹¤·¤¿»þ¤ËºÆ¤ÓDB¥¢¥Ã¥×¥°¥ì¡¼¥É¤òÂ¥¤¹²èÌ̤¬É½¼¨¤µ¤ì¤Þ¤¹¡£$SCHEMA_VERSION¤ËÍ¿¤¨¤ë¥Ð¡¼¥¸¥ç¥óÈÖ¹æ¤ÎºÎÈ֥롼¥ë¤Ï¼«Ê¬¤Ç·è¤á¤Æ¤è¤¤¤è¤¦¤Ç¤¹¡£¾¯¤Ê¤¯¤È¤â¿ôÃͤȤ·¤Æ¾å¤¬¤Ã¤Æ¤¤¤Ã¤¿¾ì¹ç¤Ë¤Ï¥Ð¡¼¥¸¥ç¥ó¥¢¥Ã¥×¤È¤ß¤Ê¤·¤Æ¡¢¥¢¥Ã¥×¥°¥ì¡¼¥É¤¬Áö¤ê¤Þ¤¹¡£

Åê¹Æ¼Ô¿ÊÃÏ | ¥Ñ¡¼¥Þ¥ê¥ó¥¯

| append.gif

¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS
Last-modified: 2007-11-22 (ÌÚ) 10:13:06 (6195d)

¥¢¡¼¥¯¥¦¥§¥Ö¤Î¥µ¡¼¥Ó¥¹¤ä¥½¥ê¥å¡¼¥·¥ç¥ó¤Ï¤³¤Á¤é