zoukankan      html  css  js  c++  java
  • yii2 basic版本的一些配置

    1.nginx配置 重写规则 修改访问模式为 http://wh.store/admin/index

    文件位置: /home/wwwroot/default/yii2-app-basic/config/web.php

    'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
    ],
    ],

    文件位置: /usr/local/nginx/conf/vhost/yz.store.conf

    server
    {
    listen 80;
    #listen [::]:80;
    server_name yz.store ;
    index index.html index.htm index.php default.html default.htm default.php;
    root /home/wwwroot/default/yii2-app-basic/web;

        include none.conf;
        #error_page   404   /404.html;
    
        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*.php$ { deny all; }
    
        include enable-php.conf;
    
        access_log  /home/wwwroot/default/yii2-app-basic/vagrant/nginx/log/y.net.access.log;
        error_log   /home/wwwroot/default/yii2-app-basic/vagrant/nginx/log/y.net.error.log;
    
        location / {
          # Redirect everything that isn't a real file to index.php
          try_files $uri $uri/ /index.php$is_args$args;
        }
    
       # deny accessing php files for the /assets directory
       location ~ ^/assets/.*.php$ {
         deny all;
       }
    
       location ~ .php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
       }
    
       location ~* /. {
        deny all;
       }        
    
    }
    

    2. FastCGI sent in stderr: "PHP message: PHP Warning: require(): open_basedir restriction in effect.

    修改nginx 配置 /usr/local/nginx/conf/fastcgi.conf # 禁用 重启服务器

    #fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
    

    3.post方式不能访问 post 400 csrf json请求不到

    禁用csrf 配置json请求

    文件地址:/home/wwwroot/default/yii2-app-basic/config/web.php

    'request' => [
                // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
                'cookieValidationKey' => 'mark453100',
                "enableCsrfValidation"=>false, #禁用csrf
                "parsers" => [
                   'application/json' => 'yiiwebJsonParser',   #支持json格式的请求
                   'text/json' => 'yiiwebJsonParser', #支持json格式的请求
                ],
    
            ]
    

    控制器接收post方法

    $request = Yii::$app->request;
    $post = $request->post();
    var_dump($post);
    

    4.如何配置数据库和建立模型类

    文件地址:/home/wwwroot/default/yii2-app-basic/config/db.php

    <?php
    return [
        'class' => 'yiidbConnection',
        'dsn' => 'mysql:host=192.168.1.125;dbname=h5_store',
        'username' => 'root',
        'password' => 'root',
        'charset' => 'utf8',
        'tablePrefix' => 'h5_', #表前缀
        // Schema cache options (for production environment)
        //'enableSchemaCache' => true,
        //'schemaCacheDuration' => 60,
        //'schemaCache' => 'cache',
    ];
    
    

    Model类

    文件位置:/home/wwwroot/default/yii2-app-basic/models/Product.php

    <?php
    
    namespace appmodels;
    
    use yiidbActiveRecord;
    
    class Product extends ActiveRecord
    {
        const STATUS_INACTIVE = 0;
        const STATUS_ACTIVE = 1;
    
        /**
         * @return string AR 类关联的数据库表名称
         */
        public static function tableName()
        {
            return '{{product}}';
        }
    }
    
    
  • 相关阅读:
    计算字符串相似度算法——Levenshtein
    信息检索参考网站
    文献检索
    【BZOJ】1684: [Usaco2005 Oct]Close Encounter(暴力+c++)
    【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)
    【BZOJ】1644: [Usaco2007 Oct]Obstacle Course 障碍训练课(bfs)
    【BZOJ】1652: [Usaco2006 Feb]Treats for the Cows(dp)
    【BZOJ】1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(dp/线段树)
    Codeforces Round #265 (Div. 2)
    中秋节模拟赛之冷月葬花魂(被虐瞎)
  • 原文地址:https://www.cnblogs.com/foreversun/p/8797518.html
Copyright © 2011-2022 走看看