App::import() is basically a glorified file includer.

ClassRegistry::init() is a registry class and only works with models.
It internally calls App::import().

On Apr 6, 5:08 pm, adam_g2000 <[email protected]> wrote:
> Hi Guys,
>
> Before continuing, I have a basic understanding of what they do (and
> their syntax), but have hit upon something I find strange, and
> worrying.
>
> I needed to import a foreign model into a controller and initially
> tried this:
>
> App::import('Model','Category');
> $cat = new Category();
> $cats = $cat->find('all', array('conditions' =>
> array('Category.status' => '1')));
> $this->set('categories', $cats);
>
> What I discovered when I tried to access the data in a view (and
> debugging) was that $categories['Category']['title'] did not work, it
> failed. Debugging showed me that in fact it was being returned in
> lowercase, so I'd have to use $categories['category']['title'] (note
> lowercase c). This wasn't acceptable as I wanted to reuse an *element*
> I'd created for the original Category controller set and views.
>
> So after some searching I discovered and tried this:
>
> $cat = ClassRegistry::init('Category');
> $cats = $cat->find('all', array('conditions' =>
> array('Category.status' => '1')));
> $this->set('categories', $cats);
>
> ...which worked perfectly, however I'm using Cake 1.3 and the entry
> for this indicates (though I'm not 100% sure on this) that App::import
> is preferred, and that ClassRegistry may be deprecated.
>
> So have I screwed up App::import? Can I get a sanity check on the
> code?
>
> Should I be concerned about using ClassRegistry::init?
>
> Thanks in advance for any pointers,
>
> Adam.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to