Thanks for all of the feedback. I wanted to post the resolution. I
hate when people ask questions, get resolution, but fail to post what
they did to help answer the issue for other people who might be having
the same problem.
So, when I baked the view, I discovered something interesting. All of
the 'letter_content' sections where being published with the variable
$openings. This is why when I stated above all of the content was
openings only. So when I changed the variables to the appropriate
content type (i.e. $middles, $endings) in the view, the drop downs
worked!
Zonium, I think your solution is the best of all the comments posted.
I appreciate everyone who added comments to the post and the help
offered. But the reason I like Zonium's solution is because it keeps
the number of models to a minimum and the code easier to read. I am
able to accomplish the goal of providing various types of content from
one table (i.e. Openings, Middles, Ends) and from 1 model by the
letter_section flag. This is great, I just wish cake would support it
in scaffolding. Oh well.
Here is the final solution:
** LETTER CONTENT (model) **
<?php
class LetterContent extends AppModel {
var $name = 'LetterContent';
var $hasMany = array(
'Opening' =>
array('className' => 'Letter',
'conditions' => 'Opening.opening_id = id',
'order' => '',
'foreignKey' => 'id'
),
'Middle' =>
array('className' => 'Letter',
'conditions' => 'Middle.middle_id = id',
'order' => '',
'foreignKey' => 'id'
),
'Ending' =>
array('className' => 'Letter',
'conditions' => 'Ending.ending_id = id',
'order' => '',
'foreignKey' => 'id'
),
);
}
?>
** LETTERS (model) **
<?php
class Letter extends AppModel {
var $name = 'Letter';
var $belongsTo = array(
'Opening' =>
array('className' => 'LetterContent',
'conditions' => "`Opening`.`letter_section` =
'Opening'",
'order' => '',
'foreignKey' => 'opening_id'
),
'Middle' =>
array('className' => 'LetterContent',
'conditions' => "`Middle`.`letter_section` =
'Middle'",
'order' => '',
'foreignKey' => 'middle_id'
),
'Ending' =>
array('className' => 'LetterContent',
'conditions' => "`Ending`.`letter_section` =
'Ending'",
'order' => '',
'foreignKey' => 'ending_id'
),
);
}
?>
** LETTERS (controller) **
<?php
class LettersController extends AppController {
var $name = 'Letters';
var $uses = array('Letter', 'LetterContent');
var $helpers = array('Html', 'Form' );
function index() {
$this->Letter->recursive = 0;
$this->set('letters', $this->Letter->findAll());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash('Invalid id for Letter.');
$this->redirect('/letters/index');
}
$this->set('letter', $this->Letter->read(null, $id));
}
function add() {
if (empty($this->data)) {
$this->set('openings', $this->Letter->Opening-
>generateList(array('letter_section'=>'Opening')));
$this->set('middles', $this->Letter->Middle-
>generateList(array('letter_section'=>'Middle')));
$this->set('endings', $this->Letter->Ending-
>generateList(array('letter_section'=>'Ending')));
$this->render();
} else {
$this->cleanUpFields();
if ($this->Letter->save($this->data)) {
$this->Session->setFlash('The Letter has been
saved');
$this->redirect('/letters/index');
} else {
$this->Session->setFlash('Please correct errors
below.');
$this->set('openings', $this->Letter->Opening-
>generateList(array('letter_section'=>'Opening')));
$this->set('middles', $this->Letter->Middle-
>generateList(array('letter_section'=>'Middle')));
$this->set('endings', $this->Letter->Ending-
>generateList(array('letter_section'=>'Ending')));
}
}
}
function edit($id = null) {
if (empty($this->data)) {
if (!$id) {
$this->Session->setFlash('Invalid id for
Letter');
$this->redirect('/letters/index');
}
$this->data = $this->Letter->read(null, $id);
$this->set('openings', $this->Letter->Opening-
>generateList(array('letter_section'=>'Opening')));
$this->set('middles', $this->Letter->Middle-
>generateList(array('letter_section'=>'Middle')));
$this->set('endings', $this->Letter->Ending-
>generateList(array('letter_section'=>'Ending')));
} else {
$this->cleanUpFields();
if ($this->Letter->save($this->data)) {
$this->Session->setFlash('The Letter has been
saved');
$this->redirect('/letters/index');
} else {
$this->Session->setFlash('Please correct errors
below.');
$this->set('openings', $this->Letter->Opening-
>generateList(array('letter_section'=>'Opening')));
$this->set('middles', $this->Letter->Middle-
>generateList(array('letter_section'=>'Middle')));
$this->set('endings', $this->Letter->Ending-
>generateList(array('letter_section'=>'Ending')));
}
}
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash('Invalid id for Letter');
$this->redirect('/letters/index');
}
if ($this->Letter->del($id)) {
$this->Session->setFlash('The Letter deleted: id
'.$id.'');
$this->redirect('/letters/index');
}
}
}
?>
** LETTERS (edit view) **
<h2>Edit Letter</h2>
<form action="<?php echo $html->url('/letters/edit/'.$html-
>tagValue('Letter/id')); ?>" method="post">
<div class="optional">
<?php echo $form->labelTag('Letter/opening_id', 'Opening');?>
<?php echo $html->selectTag('Letter/opening_id', $openings, $html-
>tagValue('Letter/opening_id'), array(), array(), true);?>
<?php echo $html->tagErrorMsg('Letter/opening_id', 'Please select the
Opening.') ?>
</div>
<div class="optional">
<?php echo $form->labelTag('Letter/middle_id', 'Middle');?>
<?php echo $html->selectTag('Letter/middle_id', $middles, $html-
>tagValue('Letter/middle_id'), array(), array(), true);?>
<?php echo $html->tagErrorMsg('Letter/middle_id', 'Please select the
Middle.') ?>
</div>
<div class="optional">
<?php echo $form->labelTag('Letter/ending_id', 'Ending');?>
<?php echo $html->selectTag('Letter/ending_id', $endings, $html-
>tagValue('Letter/ending_id'), array(), array(), true);?>
<?php echo $html->tagErrorMsg('Letter/ending_id', 'Please select the
Ending.') ?>
</div>
<?php echo $html->hidden('Letter/id')?>
<div class="submit">
<?php echo $html->submit('Save');?>
</div>
</form>
</ul>
Thanks again for all of the input.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---