Whenever I want to access a tables data from another controller that 
doesn't have a relationship with the other table I use:
class MyController extrends AppController {
    
    public function action() {
        App::uses('Choice', 'Model'); 
        $this->Article = ClassRegistry::init('Choice');
        $this->set('choices', $this->Choice->find('list'));
    }
}

I don't even think the App::uses is necessary when using 
ClassRegistry::init but I do it anyways.

On Monday, March 12, 2012 5:02:14 AM UTC-7, Graham wrote:
>
> Dear All. I would like some advice please. I am new to CakePHP and so far 
> I am loving it. I am keen to do things the “right way” so I am interested 
> in any comments.
>
>  
>
> What I describe in the following I have working. I am interested in 
> knowing if I have gone about it the right or wrong way.
>
>  
>
> I have a table with a varchar field that I want to complete with data from 
> another table – my choices table. There is no connection between the two 
> tables.
>
>  
>
> In my controller I have the following:
>
>  
>
>       App::import('Model', 'Choice');
>
>       $tmpChoice = new Choice();
>
>  
>
>       $titles = $tmpChoice->find('list', array(
>
>           'fields' => array('item', 'item'),
>
>           'conditions' => array('cat' => 'title'),
>
>           'recursive' => 0
>
>       ));
>
>       $this->set(compact('titles'));
>
>  
>
> I have this in my view:
>
>  
>
>      echo $this->Form->input('title', 
> array('type'=>'select','options'=>$titles));
>
>  
>
> Above, I needed to instantiate the Choice model class to make it available 
> to my code. When I used:
>
>  
>
> $titles = $this->MainTable->Choice->find('list',…
>
>  
>
> I received an error saying that I was trying to execute a function of an 
> object that isn’t a class. I resorted to my above code to resolve the error.
>
>  
>
> The “fields” array specifies “('item', 'item')”. This I did so that I 
> could have the value and the option the same – I didn’t want to insert the 
> id key into the database, I wanted the text. The “conditions” statement is 
> present so that I can select the appropriate category of choices.
>
>  
>
> Thanks for looking at this and making any comments about the code.
>
>  
>
> With regards
>
>  
>
> Graham Jones
>

-- 
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