• Не открывается сгенерированный crud. Yii2?

    @darknet37 Автор вопроса
    Модель:
    <?php
    
    namespace common\models;
    
    use Yii;
    
    /**
     * This is the model class for table "offer_prise".
     *
     * @property integer $id
     * @property string $value
     * @property integer $id_tovar
     */
    class OfferPrise extends \yii\db\ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'offer_prise';
        }
    
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [['id_tovar'], 'required'],
                [['id_tovar'], 'integer'],
                [['value'], 'string', 'max' => 255],
            ];
        }
    
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'id' => 'ID',
                'value' => 'Value',
                'id_tovar' => 'Id Tovar',
            ];
        }
    }

    Контроллер:
    <?php
    
    namespace backend\controllers;
    
    use Yii;
    use common\models\OfferPrise;
    use common\models\OfferPriseSearch;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;
    use yii\filters\VerbFilter;
    
    /**
     * OfferPriseController implements the CRUD actions for OfferPrise model.
     */
    class OfferPriseController extends Controller
    {
        /**
         * @inheritdoc
         */
        public function behaviors()
        {
            return [
                'verbs' => [
                    'class' => VerbFilter::className(),
                    'actions' => [
                        'delete' => ['POST'],
                    ],
                ],
            ];
        }
    
        /**
         * Lists all OfferPrise models.
         * @return mixed
         */
        public function actionIndex()
        {
            $searchModel = new OfferPriseSearch();
            $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
    
            return $this->render('index', [
                'searchModel' => $searchModel,
                'dataProvider' => $dataProvider,
            ]);
        }
    
        /**
         * Displays a single OfferPrise model.
         * @param integer $id
         * @return mixed
         */
        public function actionView($id)
        {
            return $this->render('view', [
                'model' => $this->findModel($id),
            ]);
        }
    
        /**
         * Creates a new OfferPrise model.
         * If creation is successful, the browser will be redirected to the 'view' page.
         * @return mixed
         */
        public function actionCreate()
        {
            $model = new OfferPrise();
    
            if ($model->load(Yii::$app->request->post()) && $model->save()) {
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return $this->render('create', [
                    'model' => $model,
                ]);
            }
        }
    
        /**
         * Updates an existing OfferPrise model.
         * If update is successful, the browser will be redirected to the 'view' page.
         * @param integer $id
         * @return mixed
         */
        public function actionUpdate($id)
        {
            $model = $this->findModel($id);
    
            if ($model->load(Yii::$app->request->post()) && $model->save()) {
                return $this->redirect(['view', 'id' => $model->id]);
            } else {
                return $this->render('update', [
                    'model' => $model,
                ]);
            }
        }
    
        /**
         * Deletes an existing OfferPrise model.
         * If deletion is successful, the browser will be redirected to the 'index' page.
         * @param integer $id
         * @return mixed
         */
        public function actionDelete($id)
        {
            $this->findModel($id)->delete();
    
            return $this->redirect(['index']);
        }
    
        /**
         * Finds the OfferPrise model based on its primary key value.
         * If the model is not found, a 404 HTTP exception will be thrown.
         * @param integer $id
         * @return OfferPrise the loaded model
         * @throws NotFoundHttpException if the model cannot be found
         */
        protected function findModel($id)
        {
            if (($model = OfferPrise::findOne($id)) !== null) {
                return $model;
            } else {
                throw new NotFoundHttpException('The requested page does not exist.');
            }
        }
    }

    View/index.php
    <?php
    
    use yii\helpers\Html;
    use yii\grid\GridView;
    use yii\widgets\Pjax;
    /* @var $this yii\web\View */
    /* @var $searchModel common\models\OfferPriseSearch */
    /* @var $dataProvider yii\data\ActiveDataProvider */
    
    $this->title = 'Offer Prises';
    $this->params['breadcrumbs'][] = $this->title;
    ?>
    <div class="offer-prise-index">
    
        <h1><?= Html::encode($this->title) ?></h1>
        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    
        <p>
            <?= Html::a('Create Offer Prise', ['create'], ['class' => 'btn btn-success']) ?>
        </p>
    <?php Pjax::begin(); ?>    <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
    
                'id',
                'value',
                'id_tovar',
    
                ['class' => 'yii\grid\ActionColumn'],
            ],
        ]); ?>
    <?php Pjax::end(); ?></div>
    Ответ написан
  • Как правильно прогнать цикл?

    @darknet37 Автор вопроса
    Всем Спасибо, вот код который подходит под мои требования:
    $array = array('женские','костюмы','оптом','от производителя','в Иваново','купить','недорого');
    function depth_picker($arr, $temp_string, &$collect) {
        if ($temp_string != "")
            $collect []= $temp_string;
    
        for ($i=0; $i<sizeof($arr);$i++) {
            $arrcopy = $arr;
            $elem = array_splice($arrcopy, $i, 1); // removes and returns the i'th element
            if (sizeof($arrcopy) > 0) {
                depth_picker($arrcopy, $temp_string ." " . $elem[0], $collect);
            } else {
                $collect []= $temp_string. " " . $elem[0];
            }
        }
    }
    $collect = array();
    depth_picker($array, "", $collect);
    print_r($collect);
    ?>
    Ответ написан
    Комментировать