Re: save data problem
thanks Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
Yes, can you contact me on the email, and sorry I don't have facebook account. On Jul 30, 8:25 am, hoss7 wrote: > if i have other problem can i ask you in other time? > can i send you email? > are you in facebook,can you add me (http://www.facebook.com/hhoss)? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
if i have other problem can i ask you in other time? can i send you email? are you in facebook,can you add me (http://www.facebook.com/hhoss)? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
thank you, this function work for me, you are my hero Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
I hope this help you public function save($data = null, $validate = true, $fieldList = array()) { $return = false; if (isset($data['Usercat']['subcat_id']) && is_array($data['Usercat'] ['subcat_id'])) { foreach ($data['Usercat']['subcat_id'] as $subcat) { $saveData = array( 'user_id' => $data['Usercat']['user_id'], 'subcat_id' => $subcat, ); $this->create(); $return = parent::save($saveData); // here can add some tests ... } } return $return; } On Jul 29, 8:27 pm, hoss7 wrote: > i have this array and user can choice many subcat: > > Array > ( > [Usercat] => Array > ( > [subcat_id] => Array > ( > [0] => 3 > [1] => 1 > ) > > [user_id] => 7 > ) > > ) > > you say i can use this: > > function save($data = null, $validate = true, $fieldList = array()) { > put your code here <=what code? > then > > return parrent:: save($data, $validate, $fieldList) ; <= where? > or > put parrent:: save(..) into a cycle depending what you want to do. > > } > > but can you explain more about save function,i think you need more > information about my problem > > i have 2 table: 1.subcats 2.usercats this is sql: > > CREATE TABLE IF NOT EXISTS `subcats` ( > `id` int(11) unsigned NOT NULL AUTO_INCREMENT, > `cat_id` int(11) NOT NULL, > `title` varchar(255) COLLATE utf8_persian_ci NOT NULL, > `status` int(2) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci > AUTO_INCREMENT=4 ; > > -- > -- Dumping data for table `subcats` > -- > > INSERT INTO `subcats` (`id`, `cat_id`, `title`, `status`) VALUES > (1, 2, 'sub2-1', 0), > (2, 2, 'sub2-2', 0), > (3, 1, 'sub1-1', 0); > > -- > > -- > -- Table structure for table `usercats` > -- > > CREATE TABLE IF NOT EXISTS `usercats` ( > `id` int(11) NOT NULL AUTO_INCREMENT, > `user_id` int(11) NOT NULL, > `subcat_id` int(11) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci > AUTO_INCREMENT=11 ; > > -- > -- Dumping data for table `usercats` > -- > > INSERT INTO `usercats` (`id`, `user_id`, `subcat_id`) VALUES > (3, 1, 1), > (4, 6, 2), > (10, 7, 1); > > and my model: > subcat: > var $hasMany = array( > 'Usercat' => array( > 'className' => 'Usercat', > 'foreignKey' => 'subcat_id', > 'dependent' => false, > 'conditions' => '', > 'fields' => '', > 'order' => '', > 'limit' => '', > 'offset' => '', > 'exclusive' => '', > 'finderQuery' => '', > 'counterQuery' => '' > ) > ); > > and usercat: > > var $belongsTo = array( > 'Subcat' => array( > 'className' => 'Subcat', > 'foreignKey' => 'subcat_id', > 'conditions' => '', > 'fields' => '', > 'order' => '' > ) > ); > > and in my UsercatsController: > > function add() { > if (!empty($this->data)) { > $this->Usercat->create(); > if ($this->Usercat->save($this->data)) { > $this->Session->setFlash(__('yes', true)); > $this->redirect(array('action' => 'index')); > } else { > $this->Session->setFlash(__('no', true)); > } > }else { > $this->Session->setFlash(__('no', true)); > $this->redirect(array('controller' => > 'Subcats','action' => > 'usercat')); > > } > } > and in usercat view: > > i have multiple select for user can choice many values > > i want save all values in `usercats` with one user id, i can only save > one value but i want save all value,i think i must create some > function like you say,but i am new in cakephp,please help me step by > step Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
i have this array and user can choice many subcat: Array ( [Usercat] => Array ( [subcat_id] => Array ( [0] => 3 [1] => 1 ) [user_id] => 7 ) ) you say i can use this: function save($data = null, $validate = true, $fieldList = array()) { put your code here <=what code? then return parrent:: save($data, $validate, $fieldList) ; <= where? or put parrent:: save(..) into a cycle depending what you want to do. } but can you explain more about save function,i think you need more information about my problem i have 2 table: 1.subcats 2.usercats this is sql: CREATE TABLE IF NOT EXISTS `subcats` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `cat_id` int(11) NOT NULL, `title` varchar(255) COLLATE utf8_persian_ci NOT NULL, `status` int(2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci AUTO_INCREMENT=4 ; -- -- Dumping data for table `subcats` -- INSERT INTO `subcats` (`id`, `cat_id`, `title`, `status`) VALUES (1, 2, 'sub2-1', 0), (2, 2, 'sub2-2', 0), (3, 1, 'sub1-1', 0); -- -- -- Table structure for table `usercats` -- CREATE TABLE IF NOT EXISTS `usercats` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `subcat_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci AUTO_INCREMENT=11 ; -- -- Dumping data for table `usercats` -- INSERT INTO `usercats` (`id`, `user_id`, `subcat_id`) VALUES (3, 1, 1), (4, 6, 2), (10, 7, 1); and my model: subcat: var $hasMany = array( 'Usercat' => array( 'className' => 'Usercat', 'foreignKey' => 'subcat_id', 'dependent' => false, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => '' ) ); and usercat: var $belongsTo = array( 'Subcat' => array( 'className' => 'Subcat', 'foreignKey' => 'subcat_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); and in my UsercatsController: function add() { if (!empty($this->data)) { $this->Usercat->create(); if ($this->Usercat->save($this->data)) { $this->Session->setFlash(__('yes', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('no', true)); } }else { $this->Session->setFlash(__('no', true)); $this->redirect(array('controller' => 'Subcats','action' => 'usercat')); } } and in usercat view: i have multiple select for user can choice many values i want save all values in `usercats` with one user id, i can only save one value but i want save all value,i think i must create some function like you say,but i am new in cakephp,please help me step by step Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
Sorry parrent = parent :) On Jul 29, 7:58 pm, bogdanv wrote: > in the Usercat model create method save like in the cake/libs/model/ > model.php > > function save($data = null, $validate = true, $fieldList = array()) { > put your code here > then > > return parrent:: save($data, $validate, $fieldList) ; > or > put parrent:: save(..) into a cycle depending what you want to do. > > } > > Or maybe can use beforeSave() callbacks ... I don't know what you are > going to do ... > > On Jul 29, 5:24 pm, hoss7 wrote: > > > @bogdanv can you show me,i am new in cakephp,if you want more > > information just aks? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
in the Usercat model create method save like in the cake/libs/model/ model.php function save($data = null, $validate = true, $fieldList = array()) { put your code here then return parrent:: save($data, $validate, $fieldList) ; or put parrent:: save(..) into a cycle depending what you want to do. } Or maybe can use beforeSave() callbacks ... I don't know what you are going to do ... On Jul 29, 5:24 pm, hoss7 wrote: > @bogdanv can you show me,i am new in cakephp,if you want more > information just aks? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
@bogdanv can you show me,i am new in cakephp,if you want more information just aks? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Re: save data problem
You can override method save in the model. On Jul 29, 3:48 pm, hoss7 wrote: > i have this array: > > Array > ( > [Usercat] => Array > ( > [subcat_id] => Array > ( > [0] => 3 > [1] => 1 > ) > > [user_id] => 7 > ) > > ) > > if i have subcat array i cant use this for save all data for one user: > > $this->Usercat->create(); > if ($this->Usercat->save($this->data)) { > $this->Session->setFlash(__('اyes, true)); > $this->redirect(array('action' => 'index')); > } else { > $this->Session->setFlash(__('no', true)); > } > > and i want save all data for one user,what i am must to do? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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