ThinkPHP示例之字段映射

下面 的 例子 就 运用 了 字段 映射 定义. 请 注意 看 表单 名称 和 字段 的 对应 关系.

标题:
邮箱:
内容:
验证 码: 输入 对应 的 数字

示例源码

控制器IndexAction类

 <? Php
 klasse IndexAction breidt actie {
     / / 首页
     publieke functie index () {
         $ Formulier = D ("Vorm");
         $ List = $ form-> findall Hiermee kunt ();
         $ This-> toe te wijzen ('list', $ lijst);
         $ This-> display ();
     }
     / / 处理 表单 数据
     publieke functie insert () {
         $ Formulier = D ("Vorm");
         if ($ form-> create ()) {
             $ Form-> add ();
             $ This-> redirect ();
         } Else {
             header ("Content-Type: text / html charset = UTF-8");
             exit ($ form-> getError () "[<A HREF="javascript:history.back()"> 返 回 </ A>]".);
         }
     }

     / / 生成 验证 码
     publieke functie te controleren () {
         import ("ORG.Util.Image");
            Image :: buildImageVerify ();
     }
 }
 ?>

模型FormModel类

 <? Php
 klasse FormModel breidt Model {
     beschermd $ _map = array (
             'Naam' => 'Titel',
             'Mail' => 'email',
             'Opmerkingen' => 'content',
         );
     / / 自动 验证 设置
     beschermd $ _validate = array (
         array ('naam', 'nodig', '标题 必须!'),
         array ('mail', 'email', '邮箱 格式 错误!', 2),
         array ('opmerking', 'nodig', '内容 必须'),
         array ('controleren',, 'nodig' '验证 码 必须!'),
         array ('controleren', 'CheckVerify', '验证 码 错误', 0, 'callback'),
         );

     / / 自动 填充 设置
     beschermd $ _auto = array (
         array ('status', '1 ',' Add '),
         array ('create_time', 'tijd', 'ADD', 'functie'),
         );

     publieke functie CheckVerify () {
         terug te keren md5 ($ _POST ['verify']) == $ _SESSION ['verify'];
     }

 }
 ?>
Deel dit bericht:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Heerlijk BlinkList Opvouwen

No Responses to "ThinkPHP 示例 之 字段 映射"

Laat een reactie achter:

Naam (verplicht):
Mail (zal niet worden gepubliceerd) (verplicht):
Website:
Reactie (verplicht):
XHTML: Je kan deze tags gebruiken: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>