I think you're mixing up Models and Helpers. Your Collection model has
an association with Categories.Category, using the alias Category, so
you can do $this->Collection->Category->whatever()

But, you can't call model methods in the view. You can, but you
shouldn't. From the view's perspective, $this->SomeClass is a call to
a helper. And to do that you need to include it in the controller's
$helpers array.

The simplest solution would be to just make the call to the model from
the controller action and set the returned string as a view var:

$this->set('path', $this->Collection->Category->catFullPath(...));

Better yet, create an afterFind() method in the model and add the full
path to your data array.

On Sat, Feb 9, 2013 at 11:42 AM, Larry Lutz <lut...@swbell.net> wrote:
> I'm attempting to use the CakeDC Categories plugin in CakePHP 2.3.0.
> Unfortunately, CakeDC's documentation is notoriously vague and incomplete,
> and my knowledge of Cake is very elementary. The problem is that, when
> dealing with hierarchical categories, Category.name is very unhelpful. For
> instance, in the cases of CakePHP > Views > Forms and HTML > Forms,
> Category.name would be "Form" in both instances. To deal with that, I have
> the following function in my Categories.Category model:
>
> public function catFullPath($id = NULL) {
> $models = $this->getPath($id);
> $path   = '';
> foreach ($models as $model) {
> $path .= $model['Category']['name'] . ' ยป ';
> }
> $path = substr($path, 0, strlen($path) - 3);
>
> return $path;
> }
> (That function came from a very helpful person on this group.) That works
> great when I'm dealing with a Categories view. Where it breaks down is when
> I attempt to use it in an associated model. To start with, I have this in my
> Category model:
>
> public $hasMany = array(
> 'ChildCategory' => array(
> 'className'  => 'Categories.Category',
> 'foreignKey' => 'category_id',
> 'dependent'  => FALSE
> ),
> 'Collection'    => array(
> 'className'  => 'Collection',
> 'foreignKey' => 'category_id',
> 'dependent'  => FALSE
> )
> );
>  In my Collection model, I've got:
>
>   public $belongsTo = array(
> 'Type'     => array(
> 'className'  => 'Type',
> 'foreignKey' => 'type_id',
> 'order'      => 'Type.name',
> ),
> 'User'     => array(
> 'className'  => 'User',
> 'foreignKey' => 'user_id',
> 'order'      => 'User.username',
> ),
> 'Category' => array(
> 'className' => 'Categories.Category',
> 'order'     => 'Category.name',
> )
> );
>
> However, when I try this in a Collections view, it throws a "missing helper"
> error:
>
> echo
> $this->Collection->Category->catFullPath($collection['Category']['id']);
> I've tried several variations, including:
>
> echo
> $this->Collection->Categories.Category->catFullPath($collection['Category']['id']);
> echo
> $this->Collection->Categories/Category->catFullPath($collection['Category']['id']);
> echo $this->Category->catFullPath($collection['Category']['id']);
> Of course, none of those worked. (And they shouldn't be needed since the
> path to the Category class is defined in the blongsTo association.) I even
> tried adding app::import('Categories.Category'); in the view which didn't
> work either.
>
> I'm stumped. The "missing CollectionHelper" error message seems to imply
> that Cake can't find the catFullPath() function. I can't seem to find
> anything on using functions from associated plugin models.
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to