Re: Newbie to MVC and CakePHP question on CRUD / Associations
Whit the console, specifically with the bake shell, you can set up the database configuration, generate the models automatically from the tables, the controllers with crud actions and the views for this actions. Look at http://book.cakephp.org/view/108/the-cakephp-console, http://book.cakephp.org/view/113/Code-Generation-with-Bake and http://www.archive.org/details/SettingUpTheCakephpConsoleOnWindows if you are in windows. On Mar 7, 12:11 am, A Summer wrote: > Thank you for your response. > > Do you mean use the cake bake scaffold thingy to generate a scaffold? > > On Fri, Mar 6, 2009 at 11:17 AM, Xoubaman wrote: > > Use the console to generate basic crud actions for your models. You > > can generate the models also. The code will be simple enough to get a > > idea about how cake works. > > > On Mar 6, 4:53 pm, a_summer wrote: > > > 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 > > > > > > > # /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 > > > ) > > > ); > > > > } > > > > ?> > > > > ++ > > > > > > > # /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' > > >
Re: Newbie to MVC and CakePHP question on CRUD / Associations
Thank you for your response. Do you mean use the cake bake scaffold thingy to generate a scaffold? On Fri, Mar 6, 2009 at 11:17 AM, Xoubaman wrote: > Use the console to generate basic crud actions for your models. You > can generate the models also. The code will be simple enough to get a > idea about how cake works. > > On Mar 6, 4:53 pm, a_summer wrote: > > 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 > > > > > > > # /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 > > ) > > ); > > > > } > > > > ?> > > > > ++ > > > > > > > # /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 s
Re: Newbie to MVC and CakePHP question on CRUD / Associations
Use the console to generate basic crud actions for your models. You can generate the models also. The code will be simple enough to get a idea about how cake works. On Mar 6, 4:53 pm, a_summer wrote: > 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 > > > # /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 > ) > ); > > } > > ?> > > ++ > > > # /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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---