D
D
des1roer2015-03-23 13:46:07
PostgreSQL
des1roer, 2015-03-23 13:46:07

Yii eadvancedarbehavior + postgres - how to connect?

I decided to create a project on postgres. But here I am trying to connect a many-to-many
connection des1roer.blogspot.ru/2015/03/yii-yii-for-dummies-c...
and I get
CDbCommand failed to execute SQL query: SQLSTATE[42601]: Syntax error: 7 ERROR : syntax error at or near "ignore"
LINE 1: insert ignore into t_mim(id_engine , id_book) values ​​('1', '...
^. The SQL statement executed was: insert ignore into t_mim(id_engine , id_book) values ​​( '1', '1'),('1', '2')
Naturally, there is no ignore in PG. It is neither skills nor desire to shovel for developers.
Has anyone used behavior in conjunction with postgrey? By the way, here is my eye- catching
bike _form.php

<?php echo CHtml::label('комплектность', 'complect'); ?>
        <?php
        $criteria = new CDbCriteria();
        $criteria->addInCondition('handbook_h_id', array('4'));
        $type_list = CHtml::listData(Handbook::model()->findAll($criteria), 'h_id', 'h_value');

        if (isset($model->e_id))
        {
            $arr = Mim::model()->findAll("engine_e_id=:id", array(':id' => $model->e_id));
        }

        if (isset($arr))
        {
            for ($i = 0; $i < count($arr); $i++)
            {
                $arr_bit[] = $arr[$i]->handbook_h_id;
            }
        }
        else
            $arr_bit = array();


        echo CHtml::checkBoxList('im_id', $arr_bit, $type_list, array(
            'template' => '{input} {labelTitle}',
            'class' => 'chclass',
                )
        ); //просто рисуем чекбокслитс из базы
        ?>

controller
public function actionCreate()
    {
        $model = new Engine;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if (isset($_POST['Engine']))
        {
            $model->attributes = $_POST['Engine'];
            if ($model->save())
            {                
                if (isset($_POST['im_id']))
                {
                    $command = Yii::app()->db->createCommand();
                    foreach ($_POST['im_id'] as $check)
                    {
                        $Ids = $_POST['im_id'];
                    };
                    for ($i = 0; $i < count($Ids); $i++)
                    {
                        $command->insert('mim', array(
                            'engine_e_id' => $model->e_id, ////
                            'handbook_h_id' => (int) $Ids[$i], ////
                        ));
                    }
                }

                $this->redirect(array('view', 'id' => $model->e_id));
            }
        }

        $this->render('create', array(
            'model' => $model,
        ));
    }

    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id the ID of the model to be updated
     */
    public function actionUpdate($id)
    {
        $model = $this->loadModel($id);

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);
        if (isset($_POST['Engine']))
        {
            $model->attributes = $_POST['Engine'];
           
            if ($model->save())
            {
                $command = Yii::app()->db->createCommand();
                $command->delete('mim', 'engine_e_id=:id', array(':id' => $model->e_id));
                if (isset($_POST['im_id']))
                {
                    foreach ($_POST['im_id'] as $check)
                    {
                        $Ids = $_POST['im_id'];
                    };
                    for ($i = 0; $i < count($Ids); $i++)
                    {
                        $command->insert('mim', array(
                            'engine_e_id' => $model->e_id, ////
                            'handbook_h_id' => (int) $Ids[$i], ////
                        ));
                    }
                }
                $this->redirect(array('view', 'id' => $model->e_id));
            }
        }

        $this->render('update', array(
            'model' => $model,
        ));
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question