yii2 mysql 版本_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' => 'yii\web\JsonParser', #支持json格式的请求

'text/json' => 'yii\web\JsonParser', #支持json格式的请求

],

]

控制器接收post方法

$request = Yii::$app->request;

$post = $request->post();

var_dump($post);

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

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

return [

'class' => 'yii\db\Connection',

'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

namespace app\models;

use yii\db\ActiveRecord;

class Product extends ActiveRecord

{

const STATUS_INACTIVE = 0;

const STATUS_ACTIVE = 1;

/**

* @return string AR 类关联的数据库表名称

*/

public static function tableName()

{

return '{{product}}';

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值