Hi there,

I have a problem with a has and belongs to many association, and I was
hoping that I could get some help, as none of the ones I have found so
far seem to be working.

I have a table, teasers, which is associated with another table,
articles.  Pretty standard connection

table:  articles_teasers
article_id
teaser_id

In my teaser view, I want the user to be able to define the articles
by means of a comma delimited list.  I'm populating this fine, by
using implode.  I am getting the array back from the list fine, by
using explode, in beforeSave.

My problem is now that I am having trouble actually getting this to
save.

I thought I had found a solution at the bakery
http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior.  I
still think this is probably the correct solution, but when I try to
use it, I get

Notice (8): Undefined property:  Teaser::$Teaser [APP\models
\teaser.php, line 70]

and can't work out how to fix this.  If I call the habtmAdd function
as $this->habtmAdd('Teaser', 'Article' etc, it doesn't throw an error,
but doesn't save either.

The relevant bits of my model are:

class Teaser extends AppModel {

  var $name = 'Teaser';
     var $actsAs = 'ExtendAssociations';
        var $belongsTo = array('Section');
        var $hasAndBelongsToMany = array(
        'Sections'=>array('className'=>'Section'),
        'Articles'=>array('className'=>'Article',
                        'joinTable' => 'articles_teasers',
                        'foreignKey' => 'teaser_id',
                        'associationForeignKey' => 'article_id',
                        'conditions'=>'`pub_status` = 1',
                        'order'=>'title'));
        var $order = 'title';

    function generateLinkedArticlesList($id = null) {
        $articleids = array();
        if (isset($this->data['Articles'])) {
            foreach ($this->data['Articles'] as $article) {
                array_push($articleids,
$article['id'] );
            }
        } else if (isset($this->data['Teaser']['articles'] )){
             return $this->data['Teaser']['articles'];
        }
        return implode(",", $articleids);

    }



   function beforeSave() {
       $articles =  explode(",", $_POST["data"]['Teaser']
["articles"]);
       $this->Teaser->habtmAdd('Article',  $this->data['Teaser']
['id'], $articles);
       return parent::beforeSave();
       //return false;

   }

Any ideas?

Thanks a lot

Di


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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