Re: search some duplicate data befor save data problem

2010-08-05 Thread gimmebucks
why not separate it to 2 model and set hasMany relationship. it will
be more easier.

On Aug 5, 3:19 pm, hoss7  wrote:
> i have this array:
>
> Array
> (
>     [Usercat] => Array
>         (
>             [subcat_id] => Array
>                 (
>                     [0] => 3
>                     [1] => 1
>                 )
>
>             [user_id] => 2
>             [group_id] => 5
>         )
>
> )
>
> i want befor save data in usercat table, search usercat table for
> duplicate subcat_id with user_id if subcat_id with user_id not exist
> store subcat_id with user_id,what i am must to do?
>
> example:
> i have subcat_id=1 with user_id=2 in usercat table,now i want only
> save subcat_id=3 with user_id=2 in usercat table.
>
> this is my function for save array subcat_id in usercat table in
> Usercat Model:
>
> 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 ...
>                         }
>                 }elseif (isset($data['Usercat']['subcat_id']) && !
> is_array($data['Usercat'] ['subcat_id'])){
>
>                                  $this->create();
>                                  $return = parent::save($data);
>                                 }
>                 return $return;
>         }

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


search some duplicate data befor save data problem

2010-08-05 Thread hoss7
i have this array:

Array
(
[Usercat] => Array
(
[subcat_id] => Array
(
[0] => 3
[1] => 1
)

[user_id] => 2
[group_id] => 5
)

)

i want befor save data in usercat table, search usercat table for
duplicate subcat_id with user_id if subcat_id with user_id not exist
store subcat_id with user_id,what i am must to do?

example:
i have subcat_id=1 with user_id=2 in usercat table,now i want only
save subcat_id=3 with user_id=2 in usercat table.

this is my function for save array subcat_id in usercat table in
Usercat Model:

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 ...
}
}elseif (isset($data['Usercat']['subcat_id']) && !
is_array($data['Usercat'] ['subcat_id'])){

 $this->create();
 $return = parent::save($data);
}
return $return;
}

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

2010-07-29 Thread hoss7
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

2010-07-29 Thread bogdanv
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

2010-07-29 Thread hoss7
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

2010-07-29 Thread hoss7
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

2010-07-29 Thread bogdanv
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

2010-07-29 Thread hoss7
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

2010-07-29 Thread bogdanv
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

2010-07-29 Thread bogdanv
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

2010-07-29 Thread hoss7
@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

2010-07-29 Thread bogdanv
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


save data problem

2010-07-29 Thread hoss7
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


Select box save data problem

2009-10-20 Thread kangur91

Hey. I just want to save data from select multiply, it's a select:

select('Files.name',$files,null, array
('multiple'=>true,'label'=>'Files:','class'=>'text ui-widget-content
ui-corner-all','style'=>'width: 700px'));
?>

Here data i send to controller:
Array ( [name] => Array ( [0] => cos1.pdf [1] => cos.pdf ) )

if i want to save this data using $this->Model->save($this->data) it
won't work. Because I must to change index number in keys to "name".

Anyone know how to do that?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---