D
D
des1roer2015-04-01 11:56:07
Yii
des1roer, 2015-04-01 11:56:07

Yii creating an element in a module?

I do an admin panel in the module. created a model\crud.
when saving, it cannot pass the record id to the view. and the layout of the main site still puts. although the path is normal
../admin/page/id
it seems that he does not know his $model->id

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
arab789, 2015-04-01
@arab789

Output print_r($model);
And see if the id is there.

D
des1roer, 2015-04-01
@des1roer

did it but it's not right

public function actionCreate()
    {
        $model = new Role;
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);
        if (isset($_POST['Role']))
        {
            $model->attributes = $_POST['Role'];
            if ($model->save())
            {
                if (isset($_POST['im_id']))
                {
                    $command = Yii::app()->db->createCommand();
                    $maxOrderNumber = Yii::app()->db->createCommand()
                    ->select('max(id) as max')
                    ->from('t_role')
                    ->queryScalar();
                    $max = $maxOrderNumber ;
                    foreach ($_POST['im_id'] as $check)
                    {
                        $Ids = $_POST['im_id'];
                    };
                    for ($i = 0; $i < count($Ids); $i++)
                    {
                        $command->insert('t_haspage', array(
                            'id_role' => $max, ////
                            'id_page' => (int) $Ids[$i], ////
                        ));
                    }
                }
                $this->redirect(array('view', 'id' => $max));
            }
        }

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question