ロリポップ シェル作成してcron設定

■シェル
#!/bin/sh

/usr/bin/mysql -uuser123 -ppass456 db789 -hmysql999.phy.lolipop.lan -e “delete from servers where id = 1 and ip = ‘127.0.0.1’;”
/usr/bin/mysql -uuser123 -ppass456 db789 -hmysql999.phy.lolipop.lan -e “delete from servers where id = 2 and ip = ‘127.0.0.1”;”

■cronから実行すると Permission denied と言われたので
chmod -R 777 sh

cakephp3 バリデーション

->add(‘zip’, [
    ‘num’ => [‘rule’ => [‘numeric’], ‘message’ => ‘郵便番号をご確認下さい’],
    ‘range’ => [‘rule’ => [‘lengthBetween’, 7, 7], ‘message’ => ‘郵便番号をご確認下さい’],
])

$validator
    ->add(‘username’, [‘len’ => [‘rule’ => [‘maxLength’, 50], ‘message’ => ‘文字数オーバー(50文字以内)’]])
    ->add(‘username’, ‘custom’, [‘rule’ => [$this, ‘checkUsername’], ‘message’ => ‘そのIDは既に登録されています’])
    ->requirePresence(‘username’, ‘create’)
    ->notEmpty(‘username’);

public function checkUsername($value, $context)
{
    if($this->find()->where([‘username’ => $value])->count() > 0){
        return false;
    }
    return true;
}

cakephp3 FormHelper

■control
$this->Form->control(‘item_category_id’, [‘label’ => [‘text’ => ‘カテゴリー選択’], ‘options’ => $itemCategories])

■input
$this->Form->input($key . ‘.no’, array_merge($input_set, [‘oninput’ => ‘input_set(‘ . $key . ‘)’]))

■hidden
$this->Form->hidden(‘chk_flg_’ . $key, [‘value’ => 0])

■checkbox
$this->Form->checkbox(‘all’, [‘style’=> ‘margin:0 0 0 0;’, ‘hiddenField’ => false, ‘checked’ => false, ‘onClick’ => ‘allchk(“item_chk[]”);’])

■image
$this->Html->image(“upload_img/” . $item->image, [‘style’ => ‘width:100px;height:auto;’])

■link
$this->Html->link(‘【カートを確認】’, [‘controller’ => ‘Carts’, ‘action’ => ‘index’])

■postLink
$this->Form->postLink(‘削除’, [‘action’ => ‘delete’, $item->id], [‘confirm’ => __(‘削除します # {0}?’, $item->name)])

■button
$this->Form->button(‘戻る’, [‘name’ => ‘back’, ‘style’ => ‘margin-right:1rem;’])

■element
$this->element(‘menu/menu’)

■親テーブルの値
h($item->item_category->name)

■create
<?= $this->Form->create(null, [‘url’ => [‘action’ => $act], ‘name’ => ‘index’]) ?><?= $this->Form->end() ?>

■foreach
<?php foreach ($items as $key => $item): ?><?php endforeach; ?>

■if
<?php if ($item->flg == 0): ?>あり<?php else: ?>なし<?php endif; ?>

cakephp3 クエリビルダ

■find

$this->paginate = [
    ‘limit’ => 10,
    ‘order’ => [‘Items.no’ => ‘desc’]
];

$items = $this->Items->find();
$items->select($this->Items);
$items->select($this->Items->ItemCategories);
$items->select([‘cart’ => ‘ IF(Carts.id IS NULL, 0, 1) ‘]);
$items->leftJoin([‘Carts’ => ‘carts’], [‘Carts.user_id = ‘ . $this->Auth->user(‘id’), ‘Carts.item_id = Items.id’, ‘Carts.flg = 0’]);
$items->contain([‘ItemCategories’]);
$items->where([‘Items.name like’ => ‘%’. $this->request->data[‘search_txt’] . ‘%’]);

$items = $this->paginate($items);

■countとfirst

$this->Users->find()->where([‘role’ => ‘user’])->count()
$this->Users->find()->where([‘role’ => ‘user’])->order([‘Users.modified’ => ‘ASC’])->first()

■updateAll

$this->Carts->updateAll([‘flg’ => 1], [‘user_id’ => $this->Auth->user(‘id’)]);

cakephp3 ログイン処理

■AppControllerのinitialize()に

$this->loadComponent(‘Auth’,[
    ‘authorize’ => [‘Controller’],
    ‘authenticate’ => [
        ‘Form’ => [
            ‘fields’ => [
                ‘username’ => ‘username’,
                ‘password’ => ‘password’
            ]
        ]
    ],
    ‘loginRedirect’ => [
        ‘controller’ => ‘Users’,
        ‘action’ => ‘index’
    ],
    ‘logoutRedirect’ => [
        ‘controller’ => ‘Users’,
        ‘action’ => ‘login’,
    ],
    ‘loginAction’ => [
        ‘controller’ => ‘Users’,
        ‘action’ => ‘login’
    ],
    ‘authError’ => false,
]);

■UsersControllerに

public function isAuthorized($user = null){
    if(in_array($this->request->params[‘action’], [‘index’, ‘delete’])){
        if(in_array($user[‘role’], [‘admin’, ‘super’])) {
            return true;
        }
    }
    if(in_array($this->request->params[‘action’], [‘edit’])){
        if(in_array($user[‘role’], [‘admin’, ‘super’, ‘user’, ‘sp’])) {
            return true;
        }
    }

    return false;
}

public function beforeFilter(\Cake\Event\Event $event) {
    parent::beforeFilter($event);
    $this->Auth->allow([‘add’, ‘confirm’, ‘logout’]);
}

public function login()
{
    $this->viewBuilder()->setLayout(‘nohead’);

    if($this->request->is(‘post’)){
        $user = $this->Auth->identify();
        if($user){
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error(‘ユーザー名かパスワードが間違えています。’);
    }
}

public function logout()
{
    $this->Flash->success(‘ログアウトしました’);
    return $this->redirect($this->Auth->logout());
}

■login.ctp

<div class=”users form columns content”>
    <p style=”text-align:center;border-bottom:1px solid #555;”>Login</p>
    <?= $this->Form->create() ?>

    <?= $this->Form->input(‘username’) ?>
    <?= $this->Form->input(‘password’) ?>
    <?= $this->Form->button(‘Login’) ?>

    <p style=”clear:right;float:right;”><?= $this->Html->link(“ユーザー登録はこちらから”, [‘action’ => ‘add’]) ?></p>

    <?= $this->Form->end() ?>
</div>

■Model User

use Cake\Auth\DefaultPasswordHasher;

protected $_hidden = [
    ‘password’
];

protected function _setPassword($password)
{
    if (strlen($password) > 0) {
        return (new DefaultPasswordHasher)->hash($password);
    }
}

■SQL

CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(255) NOT NULL,
`role` varchar(20) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
)

VirtualBox + vagrant

vagrant box add Ubuntu-12.10-Quantal-x86_64 https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box
ホームフォルダに『.vagrant.d』

vagrant box list
一覧が表示(あれば、上のbox addはいらない?)

cd \xampp\htdocs
mkdir ztest
cd ztest
vagrant init puphpet/centos65-x64
(vagrant box listで出てくるやつのどれか)

Vagrantfile修正(下記コメントアウト解除)
config.vm.network “private_network”, ip: “192.168.33.10”

vagrant up

tera termとかで接続
127.0.0.1
2222
id pass ⇒ vagrant

接続はhttp://192.168.33.10/test.html
(/var/www/html/にtest.htmlを置いておく)

wkhtmltopdf

sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm
sudo yum install xorg-x11-fonts-75dpi.noarch
sudo yum install -y xorg-x11-fonts-Type1
sudo rpm -ivh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

http://ipafont.ipa.go.jp/node26#jpから、フォントZIPファイル取得

unzip IPAexfont00301.zip
sudo mv IPAexfont00301 /usr/share/fonts

wkhtmltopdf /var/www/es1.on-test.co.jp/html/www.test.co.jp/html/dev/public/adm1/files/Component.IrComponent.html zzz.pdf