class AccessHelper extends Helper{
var $helpers = array("Session");
var $Access;
var $Auth;
var $user;
function beforeRender(){
App::import('Component', 'Access');
$this->Access = new AccessComponent();
App::import('Component', 'Auth');
$this->Auth = new AuthComponent();
$this->Auth->Session = $this->Session;
$this->user = $this->Auth->user();
}
function check($aco, $action='*'){
if(empty($this->user)) return false;
return $this->Access->checkHelper('User::'.$this->user['User']
['id'], $aco, $action);
}
function isLoggedin(){
return !empty($this->user);
}
}
?>
------------
This access.php file is saved in app/views/helpers
------------
In "Posts" Controller, I have added: var $helpers = array('Access');
So it can be accessed from the view.
My Posts index is here:
------------------------------
<h2>Welcome to my CakePHP Blog</h2>
<? foreach($posts as $post): ?>
<h3><a href="/posts/view/<? echo $post['Post']['id'] ?>"><? echo
$post['Post']['title'] ?></a></h3>
<p><? echo $post['Post']['content'] ?></p>
<? if($access->isLoggedin() && $access->check('Post')): ?>
<small><a href="/posts/edit/<? echo $post['Post']['id'] ?>">edit</a>
|
<? echo $html->link('delete', '/posts/delete/'.$post['Post']['id'],
NULL, 'Are you sure?'); ?></small>
<? endif; ?>
<hr />
<? endforeach; ?>
-----------------------------------
I got this error as I view Posts index:
-------------------
Fatal error: Class 'AccessComponent' not found in C:\wamp\www\cakephp
\app\views\helpers\access.php on line 10
-------------------
Line 10 points to this:
------------------------
$this->Access = new AccessComponent();
-------------------------
~~
What am I trying to accomplish ?
The edit and delete links can only be viewed when User is logged in.
If not logged in, only the Posts index and view page are viewable--
without displaying the edit and delete links to the Guest users.
~~
Is the method of doing wrong ? what is the suggested way ?
Thanks,
Maxim
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment