Wednesday, December 29, 2010

Re: HELP NEEDED with Auth "Component" in Views; Fatal error: (While using Auth component inside a helper)

Thanks Amit,

Yes, the first undefined: is solved, I posted a post before yours. I
ran the DB sql scripts with no error. The sql is as follow:

~~~~

CREATE TABLE acos (
id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
parent_id INTEGER(10) DEFAULT NULL,
model VARCHAR(255) DEFAULT '',
foreign_key INTEGER(10) UNSIGNED DEFAULT NULL,
alias VARCHAR(255) DEFAULT '',
lft INTEGER(10) DEFAULT NULL,
rght INTEGER(10) DEFAULT NULL,
PRIMARY KEY (id)
);

CREATE TABLE aros_acos (
id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
aro_id INTEGER(10) UNSIGNED NOT NULL,
aco_id INTEGER(10) UNSIGNED NOT NULL,
_create CHAR(2) NOT NULL DEFAULT 0,
_read CHAR(2) NOT NULL DEFAULT 0,
_update CHAR(2) NOT NULL DEFAULT 0,
_delete CHAR(2) NOT NULL DEFAULT 0,
PRIMARY KEY(id)
);

CREATE TABLE aros (
id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
parent_id INTEGER(10) DEFAULT NULL,
model VARCHAR(255) DEFAULT '',
foreign_key INTEGER(10) UNSIGNED DEFAULT NULL,
alias VARCHAR(255) DEFAULT '',
lft INTEGER(10) DEFAULT NULL,
rght INTEGER(10) DEFAULT NULL,
PRIMARY KEY (id)
);


~~~

On Dec 29, 5:56 pm, Amit Badkas <amit.sanis...@gmail.com> wrote:
> Hi,
>
> About 'Undefined index: content' error, you should already know how to fix
> it.
>
> About 'DbAcl::check() - Failed ARO/ACO node lookup in permissions check'
> error, are the ACL tables (aros, acos and aros_acos) populated correctly?
>
> Amit Badkas
>
> PHP Applications for E-Biz:http://www.sanisoft.com
>
> On Wed, Dec 29, 2010 at 2:56 PM, John Maxim <goog...@gmail.com> wrote:
> > Hi Amit, Thanks...!
>
> > I just put it in the controllers components--access.php:
> > ----------
> > <?
> > class AccessComponent extends Object{
> >        var $components = array('Acl', 'Auth');
> >        var $user;
>
> >        function startup(){
> >                 $this->user = $this->Auth->user();
> >        }
>
> >        function check($aco, $action='*'){
> >                 if(!empty($this->user) && $this->Acl->check('User::'.$this-
> > >user['User']['id'], $aco, $action)){
> >                        return true;
> >                } else {
> >                        return false;
> >                }
> >        }
>
> >        function checkHelper($aro, $aco, $action = "*"){
> >                App::import('Component', 'Acl');
> >                $acl = new AclComponent();
> >                return $acl->check($aro, $aco, $action);
> >        }
> > }
> > ?>
> > --------------
>
> > Now the errors are:
> > ~~
>
> > Notice (8): Undefined index: content [APP\views\posts\index.ctp, line
> > 7]
> > ~~
> > Warning (512): DbAcl::check() - Failed ARO/ACO node lookup in
> > permissions check.  Node references:
> > Aro: User::44
> > Aco: Post [CORE\cake\libs\controller\components\acl.php, line 273]
> > ~~
>
> > Regards,
> > Maxim
>
> > On Dec 29, 4:43 pm, Amit Badkas <amit.sanis...@gmail.com> wrote:
> > > Hi,
>
> > > Have you had AccessComponent class defined in
> > > app/controllers/components/access.php?
>
> > > Amit Badkas
>
> > > PHP Applications for E-Biz:http://www.sanisoft.com
>
> > > On Wed, Dec 29, 2010 at 1:30 PM, John Maxim <goog...@gmail.com> wrote:
> > > > <?php
> > > > 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 sitehttp://cakeqs.organdhelp
> > 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<cake-php%2Bunsubscribe@googlegroups.com>
> > <cake-php%2Bunsubscribe@googlegroups.com<cake-php%252Bunsubscribe@googlegroups.com>>For
> > more options, visit this group at
> > > >http://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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<cake-php%2Bunsubscribe@googlegroups.com>For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en

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: