手順
git clone https://github.com/tukiyo/docker-php5.6-apache
cd docker-php5.6-apache
sh files/get_cakephp.sh
chmod -R 777 app/tmp
docker-compose up
docker-compose.yml
web:
image: tukiyo3/php5.6-apache
volumes:
- ./files/apache.conf:/etc/apache2/sites-available/000-default.conf
- ./files/php.ini:/usr/local/etc/php/php.ini
- ./cakephp/:/var/www/html
- ./logs/:/var/log/apache2/
ports:
- "8080:80"
#restart: always
以下CakePHP2のメモ
初期設定
- app/Config/core.php
- Security.salt
- Security.cipherSeed
- app/Config/database.php
- app/Config/routes.php
クラスの追加
- app/Model/Phone.php (db)
- app/Controller/PhonesController.php ($this->Phone->findとか)
- app/View/Phones/index.ctp (view)
app/Model/Phone.php
class Phone extends AppModel {
var $useTable = 'phone';
public $validate = array(
'number' => array(
'rule' => 'notEmpty'
),
);
}
app/Controller/PhonesController.php
class PhonesController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('phones', $this->Phone->find('all'));
}
}
app/View/Phones/index.ctp
<table>
<tr>
<th>Id</th>
<th>Number</th>
<th>Created</th>
</tr>
<?php foreach ($phones as $p): ?>
<tr>
<td><?php echo $p['Phone']['id']; ?></td>
<td><?php echo $p['Phone']['number']; ?></td>
<td><?php echo $p['Phone']['date']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($g); ?>
</table>
app/Config/routes.php
- Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
+ Router::connect('/', array('controller' => 'phones', 'action' => 'index'));
便利機能
-
alt + shift + f
: ソース整形 -
table名を複数形ではなく任意のものを指定する
app/Model/Phone.php(例)
class Phone extends AppModel {
var $useTable = 'phone';
}