dongping1689 2010-11-28 10:06
浏览 103
已采纳

如何使用Doctrine YAML Schema设置自定义mutator?

I'm using this tutorial as the basis for a Code Igniter / Doctrine based project.

http://www.phpandstuff.com/articles/codeigniter-doctrine-scratch-day-3-user-signup-form

Instead of using the code as-is for the models, my project is using a YAML schema file to generate the models

I've hit a snag, in that I've got no idea how to represent the following using YAML:

$this->hasMutator('password', '_encrypt_password');

(this is from the User model code, under 'Adding Mutators') Specifically, I'm having trouble with the $this->hasMutator line

I've googled until blue, searched documentation for Doctrine, symfony (which I know uses Doctrine heavily) and even grep'd the codebase for references to mutators - I've come up empty

Is there a way to represent the line $this->hasMutator('password', '_encrypt_password'); using Doctrine YAML?

  • 写回答

3条回答 默认 最新

  • douzhi1879 2010-12-03 16:20
    关注

    (Just a note to clarify: we are talking about Doctrine 1.x here and not Doctrine 2.x) No, there is no a way to define mutators directly in your YAML schema. Are you sure you must register the mutator there?

    You could get around this limitation by creating you own doctrine behavior. Doctrine behaviors can be assigned to your models in the YAML schema. Read more here:

    http://www.doctrine-project.org/projects/orm/1.2/docs/manual/behaviors/pl

    In your case the behavior would look something like this:

    class EbonhandsTemplate extends Doctrine_Template
    {
        public function setUp()
        {
            $this->hasMutator('password', '_encrypt_password');
        }
    
        public function _encrypt_password
        ....
    }
    

    And in your yaml schema:

    EbonhandsModel:
      actAs: [EbonhandsTemplate]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化