duanleiming2014 2014-01-15 14:14
浏览 61

如何添加,编辑,查看使用像belongsTo这样的模型关系的翻译行为,hasMany在cakephp中

How to add, edit, view using Translate Behavior with model relationship in Cakephp-2.0 ?

My code for add:

public function add() {

    if ($this->request->is('post')) {
        $this->Faq->create();        
        if ($this->Faq->saveMany($this->request->data)) {
            $this->Session->setFlash('The faq has been saved', 'default', array('class' => 'success'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The faq could not be saved. Please, try again.'));
        }
    }
        $languages = $this->Language->getlangs();
        if(is_array($this->{$this->modelClass}->belongsTo)) {
            foreach($this->{$this->modelClass}->belongsTo as $relation => $model) {
                foreach($languages as $lang){
                    $this->{$this->modelClass}->$model['className']->locale = $lang['Language']['language_locale'];
                    $faqCategories[$lang['Language']['language_locale']] = $this->Faq->FaqCategory->find('list', array('conditions' => array('FaqCategory.is_active' => 1), 'recursive' => 1));
                }
            }
        }
        $this->set(compact('faqCategories'));


}

My code for edit:

public function edit($id = null) {

    if (!$this->Faq->exists($id)) {
        throw new NotFoundException(__('Invalid faq'));
    }
    if ($this->request->is('post') || $this->request->is('put')) {
        if ($this->Faq->save($this->request->data)) {
            $this->Session->setFlash('The faq has been saved', 'default', array('class' => 'success'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The faq could not be saved. Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('Faq.' . $this->Faq->primaryKey => $id));
        $this->request->data = $this->Faq->find('first', $options);
    }
    $faqCategories = $this->Faq->FaqCategory->find('list', array('conditions' => array('FaqCategory.is_active' => 1)));
    $this->set(compact('faqCategories'));
}
  • 写回答

2条回答 默认 最新

  • duanrou5680 2014-01-24 05:56
    关注

    Cakebake is generally easy way in cake php. and it vey simple using from command line

    enter image description here

    make 2 tables

    1. departement and 2 is student so student table in dept id as foreign key relationships
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题