Good Day,
Thank you for taking the time to read this discussion.
I am new to MVC design, and I need to understand how to create a view/
controller that will insert records into a model that uses the hasMany
association.
The table layout and code for the models is below:
MySQL DB Create Table
[solutions]
CREATE TABLE `solutions`
(
`id` int(11) NOT NULL
auto_increment,
`title` varchar(255) default
NULL,
`teaser`
text,
`user_id` int(11) default
NULL,
`status_id` int(11) default
NULL,
`created` datetime default
NULL,
`modified` datetime default
NULL,
PRIMARY KEY
(`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC
[sections]
CREATE TABLE `sections` (
`id` int(11) NOT NULL auto_increment,
`title` text,
`content` text,
`solution_id` int(11) default NULL,
`created` datetime default NULL,
`modified` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
Models
<?php
# /apps/models/solution.php
class Solution extends AppModel
{
var $name = 'Solution';
#Validations
var $validate = array (
'title' => array (
'rule' =>
'notEmpty'
),
'user_id' => array (
'rule' =>
'notEmpty'
),
'teaser' => array (
'rule' =>
'notEmpty'
),
'status_id' => array (
'rule' =>
'notEmpty'
)
);
#Associations
var $hasMany = array (
'Section' => array (
'className' =>
'Section',
'foreignKey' =>
'solution_id',
'order' =>
'Section.created ASC',
'dependent' => true
)
);
}
?>
++
<?php
# /apps/models/section.php
class Section extends AppModel
{
var $name = 'Section';
#Validations
var $validate = array (
'title' => array (
'rule' =>
'notEmpty'
),
'content' => array (
'rule' =>
'notEmpty'
),
'solution_id' => array (
'rule' =>
'notEmpty'
)
);
#Associations
var $belongsTo = array (
'Solution' => array (
'className' =>
'Solution',
'foreignKey' =>
'solution_id'
)
);
}
?>
Now, in my old and flawed method of coding, I would include a form
with a hidden field that includes the solution_id.
Since I am trying to understand MVC, I know I will need a view to
manage the input form for inserting a new section. But I am stuck on
the controller ... how do I ensure that the controller includes the
correct solution_id?
Thanks in advance for any assistance you can provide!
A Summer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---