PR

CakePHP – ACL再入門(7)

やっぱりACLは難しい。整理の意味も含めてもう一度入門しておく。(今回はCakePHP1.3.2です)

スポンサードリンク

pages_controller.phpをコピーして以下を追加しておく

 function beforeFilter() {
     parent::beforeFilter();
     $this->Auth->allowedActions = array('*');
     //$this->Auth->allow = array('*');
 }

テスト用のコントローラーも作っておく controllers/hoge_controller.php

<?php
class HogeController extends AppController {

 var $name = 'Hoge';
 var $helpers = array('Html', 'Form');
 var $uses = null;

 function beforeFilter() {
     parent::beforeFilter(); 
 }
 function index(){
  debug('test OK');
 }
 function indexa(){
  debug('admin only');
 }
 function indext(){
  debug('gid1 and gid2');
 }
}
?>

pages/home.ctp

<?php
	$this->set('title_for_layout', 'Home');

	if($isLogin){
		echo '<h2>Hello! ' . $userName . '</h2>';
		echo $this->Html->link(__('Logout', true), '/users/logout');
	}else{
		echo '<h2>Hello! Guest' . '</h2>';
		echo $this->Html->link(__('Login', true), '/users/login');
	}

	// test
	echo '<br /><br /><br /><h3>Test</h3>';
	echo $this->Html->link(__('test:Login', true), '/users/login')	. '<br />';
	echo $this->Html->link(__('test:Logout',true), '/users/logout')	. '<br />';
	echo $this->Html->link(__('test:Users', true), '/users')		. '<br />';
	echo $this->Html->link(__('test:Groups',true), '/groups')		. '<br />';
	echo $this->Html->link(__('test:Hoge/index',true), '/hoge')		. '<br />';
	echo $this->Html->link(__('test:Hoge/indexa',true), '/hoge/indexa')		. '<br />';
	echo $this->Html->link(__('test:Hoge/indext',true), '/hoge/indext')		. '<br />';
?>
<br /><br /><br />
TOP page, all users access ok.<br />

views/layout/default.ctp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php echo $this->Html->charset(); ?>
	<title>
		<?php __('TEST:'); ?>
		<?php echo $title_for_layout; ?>
	</title>
	<?php
		echo $this->Html->meta('icon');

		echo $this->Html->css('cake.generic');

		echo $scripts_for_layout;
	?>
</head>
<body>
	<div id="container">
		<div id="header">
			<h1><?php echo $this->Html->link(__('TEST', true) . '[Beta]', 'http://test.jp/'); ?></h1>
		</div>
		<div id="content">

			<?php echo $this->Session->flash(); ?>

			<?php echo $content_for_layout; ?>

		</div>
		<div id="footer">
		<?php echo "Version:" . Configure::version(); ?>
		</div>
	</div>

	<?php echo $this->element('sql_dump'); ?>
</body>
</html>

コメント

タイトルとURLをコピーしました