というのができない……。なんでですか。
参考:http://linker.in/journal/2010/05/macautomator.php
Macなんだし。せっかくのUNIX環境と親切にもデフォルトでインストールされているApacheを使うことにしました。
そもそも以前も組み込みのApache使って開発していたのですが、httpd.confをいじってたらよくわからない事態になってしまって……えいや!っとXAMPPに逃げたわけです。はい。
前回の失敗を活かして慎重に進めることにより /Library/WebServer ディレクトリにまとめられました。
前まではlocalhostのルート直下に site01 とかディレクトリを作って各サイトのトップページにしてたんですが、これ美しくないですよね。というわけで命名規則を local で始まり、サイトの名称をつなげたバーチャルホスト毎に管理するようにしました。例えばブログを開発するなんてときは localblog とかにしてます。
ディレクトリは /Library/WebServer/localblog に app/ と public_html/ を設置。CakePHPの本体は /Library/WebServer/share/cake に置くようにしました。見通しが良くなって気持ちいいです。
バーチャルホストの設定は
# Virtual hosts #Include /private/etc/apache2/extra/httpd-vhosts.conf
# Virtual hosts Include /private/etc/apache2/extra/my-httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin sample@gmail.com
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
# ServerAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/localhost.error_log"
CustomLog "/private/var/log/apache2/localhost.access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin sample@gmail.com
DocumentRoot "/Library/WebServer/localblog/public_html"
ServerName localblog
ErrorLog "/private/var/log/apache2/localblog.error_log"
CustomLog "/private/var/log/apache2/localblog.access_log" common
<Directory "/Library/WebServer/localblog/public_html">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
と記述しました。これが一番きもちいい結果になりました。今までプロジェクトは cake と app01 と site01 てな感じで一つのサイトを開発してましたが、これが cake と localblog になったので快適です。しかも cake を直接見ることって殆ど無い(ソース上でF3押して出現場所にジャンプするのが便利)ですよね。
以上僕のローカル開発環境でした。
class Sample extends AppModel {
public $useTable = 'example';
}
function setDataSource($dataSource = null) {
$oldConfig = $this->useDbConfig;
if ($dataSource != null) {
$this->useDbConfig = $dataSource;
}
$db =& ConnectionManager::getDataSource($this->useDbConfig);
if (!empty($oldConfig) && isset($db->config['prefix'])) {
$oldDb =& ConnectionManager::getDataSource($oldConfig);
if (!isset($this->tablePrefix) || (!isset($oldDb->config['prefix']) || $this->tablePrefix == $oldDb->config['prefix'])) {
$this->tablePrefix = $db->config['prefix'];
}
} elseif (isset($db->config['prefix'])) {
$this->tablePrefix = $db->config['prefix'];
}
if (empty($db) || !is_object($db)) {
return $this->cakeError('missingConnection', array(array('code' => 500, 'className' => $this->alias)));
}
}
class News extends AppModel {
var $useTable = 'wp_posts';
public function setDataSource(){
parent::setDataSource();
$this->tablePrefix = '';
}
}