duanlumei5941 2011-08-29 18:54
浏览 11
已采纳

除了两个表 - 教义和symfony

i have two table:

News:
id
title
body

and

NewsCopy:
id
title
body

if i add new News i would like also add this same all data for table NewsCopy?

class News extends BaseNews
{
    public function save(Doctrine_Connection $conn = null)
    {

      return parent::save($conn);
    }
}

how can i make this simply?

  • 写回答

3条回答 默认 最新

  • douzou8074 2011-08-30 07:12
    关注

    Well, one possible way is to hook up into the Doctrine saving mechanism:

    class News{
        //..other declarations//
    
        //executed after Save
        public function postSave(){
            $newsCopy = new NewsCopy(); 
            //set the parameters manually
            $newsCopy->id = $this->id;
            $newsCopy->title = $this->title;
            $newsCopy->body = $this->body;
    
            //OR, even better, create a "cast constructor" the same idea
            //$newsCopy = new NewsCopy($this);
    
            $newsCopy->save();
        }
    }
    

    See "Event Listeners" chapter for more detailed explanation

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

报告相同问题?

悬赏问题

  • ¥15 pip安装pystan显示No module named 'Cython'的问题
  • ¥15 Fortran代码segment fault
  • ¥15 求一下解题思路,需完整的步骤和代码。
  • ¥15 苹果CMS搭建的视频网站首页打开为什么会自动跳转到色情页面?
  • ¥15 php,mysql的问题
  • ¥50 dac adc的检定规程
  • ¥20 MIT控制器能控制不稳定系统吗
  • ¥15 公司代码X对业务伙伴X无效,处理方法?
  • ¥15 微信内链接跳转到浏览器打开怎么实现
  • ¥15 三角波可以直接加施密特电路整形到矩形波吗实物