h2ospace

CakePHPã?§ã??ã?°ã?¤ã??ã?®ã??ã??ã?¿ã??ç°¡å??ã??ä??ã??

2010-01-13 12:18:04

CakePHPã??ã?¯ã??ã??Authã??ã?¨ã??ã??ã??ã??ã??ã??ã??ã??ã??ã??ã??ã??ã??ç°¡å??ã??ã??ã?°ã?¤ã??ã?®ã??ã??ã?¿ã??ä??ã??ã??ã?¨ã??ã?§ã??ã??ã??ã??

ã??ã??ã??ã??ã?ªã?¢ã??ã?®ã??ã??ã??ã?¢ã??ã??ã??ã??ã?®ã?§ã??ã??ã??ã??å??è??ã??ä??ã?£ã?¦ã?¿ã??ã??ã??ã??

DBã??ã??ã??ã??ã?®æº?å??

ã??ã??ã?¯ã??DBã??ã??ã??ã??ã??æº?å??ã??ã??ã??ã??ã??usernameã??ã?¨ã??passwordã??ã?¨ã??ã??ã??ã?£ã??ã??ã??ã?®ã??ã??ã??usersã??ã?¨ã??ã??ã??ã??ã??ã??ã??ä??æ??ã??ã??ã??ã??

CREATE TABLE users (
    id integer auto_increment,
    username char(50),
    password char(50),
    PRIMARY KEY (id)
);

ã??ã?°ã?¤ã??ç??é?¢ã?®ä??æ??

ç¶?ã??ã?¦ã??ã??/app/controllersã??ã??ã?©ã??ã??ã??ã??users_controller.phpã??ã??ä??æ??ã??ã?¦ã??次ã??ã??ã??ã??loginã?¨logoutã?¢ã?¯ã??ã?§ã??ã??å®?ç?©ã??

class UsersController extends AppController {
	var $name = 'Users';
	var $components = array('Auth');

	function login() {
	}

	function logout() {
		$this->redirect($this->Auth->logout());
	}
}

ã??ã??ã??ã??ã??/app/views/ã??ã??ã?©ã??ã??ã??ã??usersã??ã??ã?©ã??ã??ã??ä??ã?£ã?¦ã??ã??loginã??ã?¢ã?¯ã??ã?§ã??ã?®ã??ã??ã??ã??login.ctpã??ã??ä??ã??ã??ã??ã??

<?php $session->flash('auth'); ?>
<?php e($form->create('User', array('action'=>'login'))); ?>
<p class="label">ID</p>
<p><?php e($form->text('username', array('size'=>'35', 'maxlength'=>'1000'))); ?><?php e($form->error('Url.full_url')); ?></p>
<p class="label">ã??ã??ã?¯ã??ã??</p>
<p><?php e($form->password('password', array('size'=>'35'))); ?></p>
<?php e($form->submit('ã??ã?°ã?¤ã??')); ?>
<?php e($form->end()); ?>

ç??ã?¿è??ã?¿

å??ã?¯ã??èª?è¨?ã??ã??ã??ã??ã??ç??é?¢ã?®ã??ã??ã??ã??ã??ã?©ã??ã??次ã?®ã??ã??ã??è¨?è¿°ã??ã??ã??ã??

class XXXController extends AppController {
	var $name = 'XXX';
	var $components = array('Auth');
...

ã??ã??ã?§ã??ã??ã?®ã??ã??ã??ã??ã??ã?©ã??ã??ã?¢ã?¯ã??ã??ã??ã??ã??ã?¨ã??ã??ã?¨è?ªå??ç??ã??ã??ã?°ã?¤ã??ç??é?¢ã??ã?¸ã?£ã??ã??ã??ã??ã??ã??ã??ã??ã??

ã??ã??ã??ã??ã??ã??ã??ã??ã?©ã??ã?®ä¸?ã?§ç??å®?ã?®ã?¢ã?¯ã??ã?§ã??ã??ã??ã?¯ã?¢ã?¯ã??ã??ã?§ã??ã??ã??ã??ã??ã??ã??ã??å?´å??ã?¯ã??ã??beforeFilterã??ã?¤ã??ã??ã??ã?ªã?©ã?§æ¬¡ã?®ã??ã??ã??å®?ç?©ã??ã??ã??ã??

	function beforeFilter() {
		$this->Auth->allow('jump');
	}

ã??ã?°ã?¤ã??æ??å?±ã?®ä??æ??

æ??å??ã??ã??ã?¯ã??ã??ã??ä??ã?£ã??ã??usersã??ã??ã??ã??ã??ã??ã??ã?°ã?¤ã??æ??å?±ã??æ??ç´?ã??ã??ã??ã??ã??ã?®ã?¨ã??ã??ã??passwordã??ã??ã?¯æ??å??å??ã??ã??ã??ã??ã?¯ã??ã??ã??å??å??ã??ã?ªã??ã??ã?°ã?ªã??ã??ã??ã??ã??ã??ä??ã??å¿?è¦?ã??ã??ã??ã??ã??ã??

æ??ã??ç°¡å??ã?ªæ??æ??ã?¯ã??ã?¯ã??ã??ã??ã??/app/config/core.phpã??ã?®debugã?? 2ä??ä¸?ã??è¨?å®?ã??ã??ã??ã?¨ã?§ã??SQLã??ç??é?¢ã??表示ã??ã??ã?¦ã??ã?°ã?¤ã??ç??é?¢ã?§IDã?¨ã??ã??ã?¯ã??ã??ã??è¨?å??ã??ã??ã??ã??
ã??ã??ã?¨ã??ç??é?¢ä¸?ã?®SQLå?ºå??ã??æ??å??å??ã??ã??ã??ã??ã?¯ã??ã??ã??表示ã??ã??ã??ã?®ã?§ã??ã??ã??ã??ã??ã??ã??ã??ã?¦ã??ã??ã?¿ã??ã??ã??ã??æ?¿å??ã??ã??ã?¨è?¯ã??ã?§ã??ã??ã??ã??

å®?æ??

ã??ã??ã?§å®?æ??ã?§ã??ã??CakePHPã??ä?¿ã??ã?¨ã??æ?¬å??ã??ã?¡ã??ã?£ã?¨ã??ã??æ©?è??ã??ç°¡å??ã??ã?§ã??ã?¦ä?¿å?©ã?§ã??ã??ã??ã?£ã?¨ä?¿ã??ã??ã?ªã??ã?¦ã??ã??ã??ã??ã?ªã??ã??

※このエントリは ブロガーにより投稿されたものです。朝日インタラクティブ および ZDNet Japan編集部の見解・意向を示すものではありません。
  • 新着記事
  • 特集
  • ブログ
このサイトでは、利用状況の把握や広告配信などのために、Cookieなどを使用してアクセスデータを取得・利用しています。 これ以降ページを遷移した場合、Cookieなどの設定や使用に同意したことになります。
Cookieなどの設定や使用の詳細、オプトアウトについては詳細をご覧ください。
[ 閉じる ]