Yii2 ошибка model generator

Код: Выделить всё

file_put_contents(/Users/svetlanailina/Sites/shop/runtime/gii-2.0.15.1/yii-gii-generators-model-Generator.json): failed to open stream: Permission denied

Код: Выделить всё

drwxrwxrwx   3 svetlanailina  staff   102  4 июн 20:30 HTML
drwxrwxrwx  18 svetlanailina  staff   612  1 июл 19:18 cache
drwxrwxrwx  69 svetlanailina  staff  2346 18 июл 12:40 debug
drwxrwxrwx   5 svetlanailina  staff   170  4 июн 19:41 gii-2.0.15.1
drwxrwxrwx   3 svetlanailina  staff   102 22 апр 14:14 logs
drwxrwxrwx   4 svetlanailina  staff   136 29 май 19:31 mail

Код: Выделить всё



    1. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2-gii/src/Generator.php at line 247
    238239240241242243244245246247248249250251252253254255256

                            {
            $stickyAttributes = $this->stickyAttributes();
            $stickyAttributes[] = 'template';
            $values = [];
            foreach ($stickyAttributes as $name) {
                $values[$name] = $this->$name;
            }
            $path = $this->getStickyDataFile();
            @mkdir(dirname($path), 0755, true);
            file_put_contents($path, json_encode($values));
        }
     
        /**
         * @return string the file path that stores the sticky attribute values.
         * @internal
         */
        public function getStickyDataFile()
        {
            return Yii::$app->getRuntimePath() . '/gii-' . Yii::getVersion() . '/' . str_replace('\\', '-', get_class($this)) . '.json';
                    

    2. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2-gii/src/controllers/DefaultController.php at line 60 – yii\gii\Generator::saveStickyAttributes()
    54555657585960616263646566

                                $preview = Yii::$app->request->post('preview');
            $generate = Yii::$app->request->post('generate');
            $answers = Yii::$app->request->post('answers');
     
            if ($preview !== null || $generate !== null) {
                if ($generator->validate()) {
                    $generator->saveStickyAttributes();
                    $files = $generator->generate();
                    if ($generate !== null && !empty($answers)) {
                        $params['hasError'] = !$generator->save($files, (array) $answers, $results);
                        $params['results'] = $results;
                    } else {
                        $params['files'] = $files;
                    

    3. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – yii\gii\controllers\DefaultController::actionView()
    4. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array:{/Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/base/InlineAction.php:57}()
    5. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/base/Controller.php at line 157 – yii\base\InlineAction::runWithParams()
    6. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/base/Module.php at line 528 – yii\base\Controller::runAction()
    7. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/web/Application.php at line 103 – yii\base\Module::runAction()
    8. in /Users/svetlanailina/Sites/shop/vendor/yiisoft/yii2/base/Application.php at line 386 – yii\web\Application::handleRequest()
    9. in /Users/svetlanailina/Sites/shop/web/index.php at line 13 – yii\base\Application::run()
    78910111213

                        require __DIR__ . '/../vendor/autoload.php';
    require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
     
    $config = require __DIR__ . '/../config/web.php';
    require_once __DIR__ . '/../functions.php';
     
    (new yii\web\Application($config))->run();
                    

$_GET = [
    'r' => 'gii/default/view',
    'id' => 'model',
];

$_POST = [
    '_csrf' => 'KVZ45bZCmGRfAnnoYuYGj40h3nqGVDTQyJuUy_5rhURoOT2w2iOpVTJHSY8qnjTX-2iETewwAuaErfabvyficQ==',
    'Generator' => [
        'tableName' => 'product',
        'modelClass' => 'Product',
        'ns' => 'app\\modules\\admin\\models',
        'baseClass' => 'yii\\db\\ActiveRecord',
        'db' => 'db',
        'useTablePrefix' => '0',
        'generateRelations' => 'all',
        'generateRelationsFromCurrentSchema' => '1',
        'generateLabelsFromComments' => '0',
        'generateQuery' => '0',
        'queryNs' => 'app\\modules\\admin\\models',
        'queryBaseClass' => 'yii\\db\\ActiveQuery',
        'enableI18N' => '0',
        'messageCategory' => 'app',
        'useSchemaName' => '1',
        'template' => 'default',
    ],
    'preview' => '',
];

$_COOKIE = [
    '_ga' => 'GA1.1.1057812100.1523460938',
    '_identity' => '7d8ba21c070e4f7a3dc8c1e0e621bbc6e44546c9d5871cc57186d6e4d5500a1ba:2:{i:0;s:9:"_identity";i:1;s:46:"[1,"mkJL-07BRNtvoQIymDsxuL8nZISzfe2R",2592000]";}',
    '_ym_uid' => '15317451821059736191',
    '_ym_d' => '1531745182',
    'PHPSESSID' => 'b0n9b9jkh7v2r14p2jfuchelor',
    '_csrf' => 'ca356b4c11cf69f86836947f61749331e42067c61a3c02bca1926a9a6ab431f1a:2:{i:0;s:5:"_csrf";i:1;s:32:"AoEUla11mE0gHx2XvIZ7jd66L6bPALg5";}',
    'dcjq-accordion' => '20',
];

$_SESSION = [
    '__flash' => [],
    '__id' => 1,
    'cart' => [
        2 => [
            'qty' => 3,
            'name' => 'Утеплитель двигателя Klimat Premium №2',
            'price' => 1350.0,
            'img' => 'product2.jpg',
        ],
        3 => [
            'qty' => 3,
            'name' => 'Автомагнитола ACV AVS-1310G',
            'price' => 3120.0,
            'img' => 'product3.jpg',
        ],
        10 => [
            'qty' => 1,
            'name' => 'Шина всесезонная AMTEL VS-1 205/70 R14 ',
            'price' => 5000.0,
            'img' => 'product9.jpg',
        ],
        4 => [
            'qty' => 1,
            'name' => 'Навигатор автомобильный ACV PN-5016',
            'price' => 3870.0,
            'img' => 'product4.jpg',
        ],
        1 => [
            'qty' => 1,
            'name' => 'Утеплитель двигателя HeatShield L                 ',
            'price' => 1000.0,
            'img' => 'product1.jpg',
        ],
    ],
    'cart.qty' => 9,
    'cart.sum' => 23280.0,
];


Yii Framework Forum

Loading

Yii PHP Framework

  • Guide
  • API
  • Wiki
  • Forum
  • Community
    • Live Chat
    • Extensions
    • Resources
    • Members
    • Hall of Fame
    • Badges
  • More
    • Learn
    • Books
    • Resources
    • Develop
    • Download Yii
    • Report an Issue
    • Report a Security Issue
    • Contribute to Yii
    • About
    • What is Yii?
    • Release Cycle
    • News
    • License
    • Team
    • Official logo

Generate advanced rules:

public function generateRules($table)
    {
        $columns = [];
        foreach ($table->columns as $index => $column) {
            $isBlameableCol = ($column->name === $this->createdByColumn || $column->name === $this->updatedByColumn);
            $isTimestampCol = ($column->name === $this->createdAtColumn || $column->name === $this->updatedAtColumn);
            $removeCol = ($this->useBlameableBehavior && $isBlameableCol)
                || ($this->useTimestampBehavior && $isTimestampCol);
            if ($removeCol) {
                $columns[$index] = $column;
                unset($table->columns[$index]);
            }
        }

        $rules = [];

        //for enum fields create rules "in range" for all enum values
        $enum = $this->getEnum($table->columns);
        foreach ($enum as $field_name => $field_details) {
            $ea = array();
            foreach ($field_details['values'] as $field_enum_values) {
                $ea[] = 'self::'.$field_enum_values['const_name'];
            }
            $rules['enum-' . $field_name] = "['".$field_name."', 'in', 'range' => [\n                    ".implode(
                    ",\n                    ",
                    $ea
                ).",\n                ]\n            ]";
        }

        $rules = array_merge($rules, $this->rulesIntegerMinMax($table));

        // inject namespace for targetClass
        $modTable = clone $table;
        $intColumn = 'nonecolumn';
        foreach($modTable->columns as $key => $column){
            switch ($column->type) {
                case Schema::TYPE_SMALLINT:
                case Schema::TYPE_INTEGER:
                case Schema::TYPE_BIGINT:
                case Schema::TYPE_TINYINT:
                case 'mediumint':
                    $modTable->columns[$key]->type = Schema::TYPE_INTEGER;
                $intColumn = $column->name;
            }
        }
        $parentRules = parent::generateRules($modTable);
        $ns = "\\{$this->ns}\\";
        $match = "'targetClass' => ";
        $replace = $match.$ns;
        foreach ($parentRules as $k => $parentRule) {
            if(preg_match('#\'' . $intColumn . '\',.*\'string\', \'max\' => 5#',$parentRule)){
                unset($parentRules[$k]);
                continue;
            }
            if(preg_match('#\'integer\']$#',$parentRule)){
                unset($parentRules[$k]);
                continue;
            }
            $parentRules[$k] = str_replace($match, $replace, $parentRule);
        }

        $rules = array_merge($rules,$parentRules);
        $table->columns = array_merge($table->columns, $columns);

        return $rules;
    }
    /**
     * Generates validation min max rules.
     *
     * @param TableSchema $table the table schema
     *
     * @return array the generated validation rules
     */
    public function rulesIntegerMinMax($table): array
    {
        $UNSIGNED = 'Unsigned';
        $SIGNED = 'Signed';
        $rules = [
            Schema::TYPE_TINYINT . ' ' . $UNSIGNED => [
                [],
                'integer',
                'min' => 0,
                'max' => 255,
            ],
            Schema::TYPE_TINYINT . ' ' . $SIGNED => [
                [],
                'integer',
                'min' => -128,
                'max' => 127,
            ],
            Schema::TYPE_SMALLINT . ' ' . $UNSIGNED => [
                [],
                'integer',
                'min' => 0,
                'max' => 65535,
            ],
            Schema::TYPE_SMALLINT . ' ' . $SIGNED => [
                [],
                'integer',
                'min' => -32768,
                'max' => 32767,
            ],
            'mediumint' . ' ' . $UNSIGNED => [
                [],
                'integer',
                'min' => 0,
                'max' => 16777215,
            ],
            'mediumint' . ' ' . $SIGNED => [
                [],
                'integer',
                'min' => -8388608,
                'max' => 8388607,
            ],
            Schema::TYPE_INTEGER . ' ' . $UNSIGNED => [
                [],
                'integer',
                'min' => 0,
                'max' => 4294967295,
            ],
            Schema::TYPE_INTEGER . ' ' . $SIGNED => [
                [],
                'integer',
                'min' => -2147483648,
                'max' => 2147483647,
            ],
            Schema::TYPE_BIGINT . ' ' . $UNSIGNED => [
                [],
                'integer',
                'min' => 0,
                'max' => 0xFFFFFFFFFFFFFFFF,
            ],
            Schema::TYPE_BIGINT . ' ' . $SIGNED => [
                [],
                'integer',
                'min' => -0xFFFFFFFFFFFFFFF,
                'max' => 0xFFFFFFFFFFFFFFE,
            ],

        ];

        foreach ($table->columns as $column) {
            $key = $column->type . ' ' . ($column->unsigned? $UNSIGNED : $SIGNED);
            if(!isset($rules[$key])){
                continue;
            }

            $rules[$key][0][] = $column->name;
        }

        /**
         * remove empty rules
         */
        foreach($rules as $ruleName => $rule){
            if(!$rule[0]){
                unset($rules[$ruleName]);
                continue;
            }
            $rules[$ruleName] = '['
                . '[\'' . implode('\',\'',$rule[0]) . '\']'
                . ',\'integer\''
                . ' ,\'min\' => ' . $rule['min']
                . ' ,\'max\' => ' . $rule['max']
                . ']';
        }

        return $rules;


    }

I am trying to generate CRUD in yii2 using Gii. I have created a model class using Gii and it is created successfully. But When I try to create CRUD, it gives the following error:

Class 'app\models\UserRoles' does not exist or has syntax error.

Here is the screen shot of what I am filling the form with and error:
enter image description here
The class UserRoles exists and there is certainly no syntax error. I have tried this
and it doesn’t work either. Help would be highly appreciated.

Community's user avatar

asked Nov 7, 2016 at 6:59

Saani's user avatar

2

This because the class i gii can’t revolve properly the app\models\YourClassName (i have experienced because create most of models in common\models for share the models between frontend and backend)

be sure where you have save the models (could be in backend\models)

then set the proper value in

Model Class eg:

 backend\models\YourClassName  

or simply

 YourClassName 

And do the same for Search Model Class too

In viewpath you should use a proper alias so if you are in frontent

  @frontend\views\your-model-name

or (in some case) you can set the abolute path to the directory you need

answered Nov 7, 2016 at 7:18

ScaisEdge's user avatar

ScaisEdgeScaisEdge

132k10 gold badges92 silver badges107 bronze badges

8

On the Model geneneration page change the namespace to the appropriate application. ie, change from app\models to either backend\models or frontend\models.

change the namespace here

desertnaut's user avatar

desertnaut

57.7k27 gold badges140 silver badges167 bronze badges

answered Aug 7, 2017 at 16:39

Check namaspace of your model class.
add Model class

app\models\YourClassName  

add controller class

backend\controllers\Controller

view path

@backend/views/foldername

answered Dec 15, 2018 at 12:03

Nilesh Patil's user avatar

Nilesh PatilNilesh Patil

1381 gold badge1 silver badge10 bronze badges

I try to create crud in console with the following command:

php yii gii/crud --controllerClass=app\controllers\PostController --modelClass=app\models\Post

and get the same error. Finally, I run it successfully in this way:

php yii gii/crud --controllerClass=app\\controllers\\PostController --modelClass=app\\models\\Post

answered Aug 14, 2019 at 9:10

Vahid Almasi's user avatar

It’s Showing that your Model class does not exist in the Model folder so First Create Model By gii -> Model Generator

  1. Select Table Name (drop-down list will generate Automatically).
  2. Enter Model Class Name.
  3. Click on Preview -> generate

answered Jul 17, 2021 at 11:31

Deepu Bhasin's user avatar

I got this error when trying to access ‘model’ and ‘CRUD’ generator in gii.

CDbConnection failed to open the DB connection: SQLSTATE[42000] [1044]
Access denied for user ‘jivaindo_fin’@’localhost’ to database
‘jivaindo_finale’

The server is remote in other place. And using Cpanel to access it. the server name is ‘jivcom.com’.
(i edited the file using filezilla)

The database used is MySQL.
I have checked database name, database username and password. And all is match in the Cpanel.

This is the config/main.php in the web folder. i suspect this is where i get the error but i can’t find it.

'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=jivaindo_finale',
'emulatePrepare' => true,
'username' => 'jivaindo_fin',
'password' => 'j1v41nd0',
'charset' => 'utf8',
),

Can anybody help me for this problem? any solution to make it able to access the ‘model’ generator?

Понравилась статья? Поделить с друзьями:
  • Youtube произошла ошибка повторите попытку iphone
  • Yii2 ошибка 504
  • Yaskawa v1000 ol2 ошибка
  • Youtube ошибка 400 на планшете
  • Yii2 ошибка 403