
CakePHP 1.2 Cheatsheet
http://cakephp.org/files/Resources/CakePHP-1.2-Cheatsheet.pdf
$this->Email->charset = 'utf-8';
$this->Email->from = '블루비 <blog @ blueb . net>';
$this->Email->to = '블루비 <blog @ blueb . net>';
$this->Email->subject = 'CakePHP Email Test';
$this->Email->template = 'test'; //views/elements/email/html/test.ctp
$this->Email->sendAs = 'both'; // text, html or both
$this->Email->send();


<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule CSS" stopProcessing="true">
<match url="^css(.*)$" ignoreCase="false" />
<action type="Rewrite" url="webroot/css{R:1}" />
</rule>
<rule name="Imported Rule JS" stopProcessing="true">
<match url="^js(.*)$" ignoreCase="false" />
<action type="Rewrite" url="webroot/js{R:1}" />
</rule>
<rule name="Imported Rule IMG" stopProcessing="true">
<match url="^img(.*)$" ignoreCase="false" />
<action type="Rewrite" url="webroot/img{R:1}" />
</rule>
<rule name="Imported Rule Images" stopProcessing="true">
<match url="^images(.*)$" ignoreCase="false" />
<action type="Rewrite" url="webroot/images{R:1}" />
</rule>
<rule name="Imported Rule Flash" stopProcessing="true">
<match url="^flash(.*)$" ignoreCase="false" />
<action type="Rewrite" url="webroot/flash{R:1}" />
</rule>
<rule name="Imported Rule Files" stopProcessing="true">
<match url="^files(.*)$" ignoreCase="false" />
<action type="Rewrite" url="webroot/files{R:1}" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="php5" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" resourceType="Unspecified" />
</handlers>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>

Configure::write('Config.language', 'kor');
Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}'));
class AppController extends Controller {
function beforeFilter(){
$this->_setLanguage();
}
function _setLanguage() {
if ( $this->Cookie->read('lang') && !$this->Session->check('Config.language')){
$this->Session->write('Config.language', $this->Cookie->read('lang'));
}
else if( isset($this->params['language'] ) && ($this->params['language'] != $this->Session->read('Config.language')) ){
$this->Session->write('Config.language', $this->params['language']);
$this->Cookie->write('lang', $this->params['language'], true, '20 days');
}
else if ( !isset($this->params['language']) && isset($this->params['named']['language']) && ($this->params['named']['language'] != $this->Session->read('Config.language'))) {
$this->Session->write('Config.language', $this->params['named']['language']);
$this->Cookie->write('lang', $this->params['named']['language'], true, '20 days');
}
else if( !isset($this->params['language']) && !isset($this->params['named']['language']) && $this->Cookie->read('lang') != Configure::Read('Config.language') ){
$this->Session->write('Config.language', Configure::Read('Config.language'));
$this->Cookie->write('lang', Configure::Read('Config.language'), true, '20 days');
}
}
}//end of class AppController
msgid "num"/app/locale/kor/LC_MESSAGES/default.po
msgstr "No"
msgid "file"
msgstr "File"
msgid "num"
msgstr "번호"
msgid "file"
msgstr "파일"
<?=__("num");?> >> 번호
<?=$this->link(__("num",true),array('/'));?> >> <a href="/">번호</a>
http://blueb.net/controller/action (kor language)
http://blueb.net/eng/controller/action (eng language)
if (Auth_OpenID::arrayGet($q, $key) != $value) {
on line 922 with
if ($key != 'url' && Auth_OpenID::arrayGet($q, $key) != $value) {
public $components = array('Openid');
Login form (app/views/users/login.ctp):
<?php
if (isset($message)) {
echo '<p class="error">'.$message.'</p>';
}
echo $form->create('User', array('type' => 'post', 'action' => 'login'));
echo $form->input('OpenidUrl.openid', array('label' => false));
echo $form->end('Login');
?>
And the controller (app/controllers/users_controller.php):
<?
class UsersController extends AppController {
public $components = array('Openid');
public $uses = array();
public function login() {
$returnTo = 'http://'.$_SERVER['SERVER_NAME'].'/users/login';
if (!empty($this->data)) {
try {
$this->Openid->authenticate($this->data['OpenidUrl']['openid'], $returnTo, 'http://'.$_SERVER['SERVER_NAME']);
} catch (InvalidArgumentException $e) {
$this->setMessage('Invalid OpenID');
} catch (Exception $e) {
$this->setMessage($e->getMessage());
}
} elseif (count($_GET) > 1) {
$response = $this->Openid->getResponse($returnTo);
if ($response->status == Auth_OpenID_CANCEL) {
$this->setMessage('Verification cancelled');
} elseif ($response->status == Auth_OpenID_FAILURE) {
$this->setMessage('OpenID verification failed: '.$response->message);
} elseif ($response->status == Auth_OpenID_SUCCESS) {
echo 'successfully authenticated!';
exit;
}
}
}
private function setMessage($message) {
$this->set('message', $message);
}
}
?>
$this->Profile->validate = Set::merge($this->Profile->validate, array(
'name'=>array(
'required'=>true,
'rule'=>array('alphaNumeric')
)
));
$this->Board->bindModel(array(
'hasOne'=>array('[ClassName]'=>array('foreignKey'=>'id'))
));
$this->Board->bindModel(array(
'hasOne'=>array('[ClassName]'=>array('foreignKey'=>'id'))
),false);
$form->input('Model.field',array (
'legend'=>false,
'type'=>'radio',
'options'=>array(
'val1'=>'label1',
'val2'=>'label2'
),
'default'=>'val2')))
제가 블로그를 티스토리로 옮겼어요. 그래서 하위 디렉토리 tc 없이 그냥 글번호를 붙여주면 그 글로 갑니다. ^^
http://anjella.co.kr/tc/283
=> http://anjella.co.kr/283
var $default = array(
'driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'id',
'password' => 'passwd',
'database' => 'dbname',
'encoding' => 'UTF8',
'prefix' => ''
);
class BoardsController extends AppController {
var uses = array('Upload');
function upload(){
$this->Upload->setSource('board_files'); //board_files 테이블을 Upload 모델 테이블로 셋팅
$this->Upload->save($this->data);
}
}
class ProductsController extends AppController {
var uses = array('Upload');
function upload(){
$this->Upload->setSource('product_files'); //product_files 테이블을 Upload 모델 테이블로 셋팅
$this->Upload->save($this->data);
}
}
CakePHP 에서 다중 데이터 베이스에 접근을 이용하기 위한 방법입니다...
In this tutorial we will see how you can grab your data from different/multiple DB connections in the same application.
This is particularly usefull if you need to integrate your application with an existing system: let's immagine for example that your application needs to retrieve users data, and that the users data are shared by the general system you are integrating to in a different DB.
Let's get more real. The general application runs on a DB called DB_2, while your CakePHP application runs on DB_1. Users data are in DB_2, while all your app data are in DB_1.
First of all you need to specify 2 (or more DB connections) in app/config/database.php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'your_host',
'login' => 'your_login_1',
'password' => 'your_password_1',
'database' => 'DB_1',
'prefix' => ''
);
var $general_syst = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'your_host',
'login' => 'your_login_2',
'password' => 'your_password_2',
'database' => 'DB_2',
'prefix' => ''
);
}
?>
By default CakePHP uses the 'default' connection in your models, if it exists in your database.php configuration.
An important thing is that if you use multiple DB connections in your models you should not set their connection as persistent: namely the 'persistent' key of your dB_connection array should be set to false.
This avoids that your application will use persistently the last connection you switched to in your models.
The key variable that will switch DB config in your models is: $useDbConfig
But let's build our User model and our Post model. They will respectively use:
User model (in app/models/user.php):
class User extends AppModel {
var $name = 'User';
var $useDbConfig = 'general_syst';
//your code here
//....
}
Post model (in app/models/post.php):
class Post extends AppModel {
var $name = 'Post';
var $useDbConfig = 'default';
//your code here
//....
}
In the Post model it wasn't really necessary to specify the $useDBconfig variable, because we CakePHP uses the 'default' DB config if nothing else is specified, but I specified it just to make the example clearer.
Right! Noe every time you will use in your controllers:
출처 : http://www.4webby.com/blog/posts/view/6/cakephp_models_using_multiple_db_connections
<?php
# app/controllers/uploads_controller.php
class UploadsController extends AppController {
var $name = 'Uploads';
var $components = array('SwfUpload');
var $helpers = array('Html', 'Javascript');
function beforeFilter() {
if ($this->action == 'upload') { //upload Action 에서만 반응 하도록 처리
$this->Session->start(); //SwfUpload 의 세션정보를 유지하기 위한 코드
}
parent::beforeFilter();
}
function upload() {
if (isset($this->params['form']['Filedata'])) {
// process your upload in here
// and you can read from or write to the session
// as you would normally
}
?>
}
}
?>
$conditions = array('date BETWEEN ? AND ?' =>..
array(
date('Y-m-d', strtotime('-1 weeks')),
date('Y-m-d', strtotime('now'))
)
);
$this->findAll($conditions);
more..
more..
more..