Okay, so I solved this myself. Posting this as it might be of help to
a someone else starting out with Cake.

You can tell controller to use additional models using $uses var at
the beginning of your controller, but you have to specify the current
controller in the array:

In my case I have 2 models, Post and Category

In my Posts controller I put:

class PostsController extends AppController {
    var $name = 'Posts';
    var $uses = array('Post','Category');

This gives the Posts controller access to the resources of the
Category controller so that I can access the data from a function
within the Posts controller, eg:

function add() {
  $this->set('catlist', $this->Category->findAll());
  $this->set('catlist', $this->Category->generateList(
  null,
  "name ASC",
  null,
  "{n}.Category.id",
  "{n}.Category.name"
  )
  );


  if (!empty($this->data)) {
  if ($this->Post->save($this->data)) {
  $this->flash('Your post has been saved.','/posts');
  }
 }
}

This is what I learned today. Posting here in case it might be of use
to anyone else tearing their hair out with a similar beginners
problem. There's probably easier ways to do it, but it worked for me.

Thanks


On Jun 6, 8:17 pm, ReiToei <[EMAIL PROTECTED]> wrote:
> I have 2 tables, posts and categories, and 2 models, post and
> category.
>
> The posts table has a category_id field that links to the category
> table. I've used $belongsTo to link them and it works fine on my
> "index" view.
>
> What I am trying to do is create a form select in my posts "add" view
> that will display a dropdown list of all the categories (and
> associated ID's as the select values) in the categories table.
>
> I kind of feel like I'm halfway there with this, but just missing
> something really basic.
>
> Any help would be greatly appreciated. I've searched high and low
> through the manual and on this group for a simple example and had no
> luck.
>
> Thanks in advance.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to