Drupal 7 rewrite settings.php

/**
 * Form callback.
 *
 * @param $form
 * @param $form_state
 */
function myform_submit(&$form, &$form_state) {

  global $databases;

  // Update settings.php.
  $inputs = $form_state['input'];

  require_once DRUPAL_ROOT . '/includes/install.inc';

  $settings['databases'] = array(
    'value'    => array('default' => array(
      'default' => $databases['default']['default'],
      'odbc' => array (
        'database' => $inputs['olm_mart_db_name'],
        'username' => $inputs['olm_mart_db_user'],
        'password' => $inputs['olm_mart_db_pass']['pass1'],
        'host' => $inputs['olm_mart_db_host'],
        'port' => $inputs['olm_mart_db_port'],
        'driver' => 'odbc',
        'prefix' => '',
      ),
    )),
    'required' => TRUE,
  );

  //  $settings['drupal_hash_salt'] = array(
  //    'value'    => drupal_random_key(),
  //    'required' => TRUE,
  //  );
  drupal_rewrite_settings($settings);
}

Docker configuration nginx,php7,mysql

Download php7, mysql, nginx

$ docker pull php:7-fpm-alpine
$ docker pull nginx
$ docker pull mysql

Run php

在这里必须挂载目录到php-fpm, nginx不会直接执行,它检测到php文件,会把php文件的路径发到php-fpm去,php-fpm再依据nginx发过来的路径找到代码并执行啊。

$ docker run -it --rm --name xphp --link xmysql:xmysql -v /Users/zhouitpro/www/docker_web:/usr/share/nginx/html php:7-fpm-alpine
# --link xmysql:xmysql 映射mysql

Install php ext

# 安装pdo_mysql
$ docker exec -it run xphp bash
Docker# docker-php-ext-install pdo_mysql
Docker# docker-php-ext-enable pdo_mysql

Run Nginx

nginx config file

server {
    listen       80;
    server_name  localhost;
    root /usr/share/nginx/html/;
    location ~ \.php$ {
        fastcgi_pass xphp:9000; # 这里对应上面的php-fpm别名, php-fpm端口默认是9000
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    location ~ /\.ht {
        deny  all;
    }
}
$ docker run -it --rm  --link xphp:xphp -v /Users/zhouitpro/www/docker_web:/usr/share/nginx/html  -v /Users/zhouitpro/www/docker/site.conf:/etc/nginx/conf.d/default.conf -p 9090:80  nginx

# -p 是转发端口 外部的 9090对应nginx提供的80端口
# --link 是映射上面的 php-fpm
# -v 是映射本地的web目录到nginx的www目录,和配置文件

Mysql

$ docker run -it --rm --name xmysql -e MYSQL_ROOT_PASSWORD=root mysql

PHP DatePeriod 周期

/**
 * DatePeriod
 *
 * 3rd component: https://github.com/briannesbitt/Carbon
 */


/**
 * DateInterval 表示到下一个周期的时间间隔.
 *
 * 2W表示两周.
 */
$interval = new DateInterval('P2W');
$start = new DateTime();

$periods = new DatePeriod($start, $interval, 3, DatePeriod::EXCLUDE_START_DATE);

foreach($periods as $nextDateTime) {
  var_dump($nextDateTime->format('Y-m-d'));
}