mocapapa
(Mocapapa)
January 24, 2009, 9:46am
1
This question relates to the code in the discussion as below:
http://www.yiiframew…14.html#msg3314 .
My code in the function rules() is actually like:
array('user', 'uniqueInForum', 'on'=>'insert'),
Obviously, I would not want to validate the parameter on 'delete' action.
On the other hand, the document says:
Quote
You may thus specify a rule with the 'on' option so that it is applied only to insertion or updating.
Then I found this is expected, but I still would not want to validate it on 'delete' action.
BTW, I am doing in the 'delete' action as below.
if (isset($_POST['user'])) {
$user->attributes=$_POST['user'];
if ($user->validate() && $user->delete())
Is there any solution for this?
qiang
(Qiang Xue)
January 24, 2009, 12:20pm
2
Do you mean the 'insert' rule is applied when you call $user->validate()? That shouldn't happen? Could you please double check it? If so, please create a ticket with a reproducible example. Thank you!
mocapapa
(Mocapapa)
January 24, 2009, 4:36pm
3
Hi Qiang,
Yes, I mean this rule for a 'insert' applies to a 'delete' as well. as I thought this may be an expected behavior according to the document. But if it is not expected, I am going to create a ticket.
mocapapa
(Mocapapa)
January 24, 2009, 4:56pm
4
jonah
(Poppitypop)
January 24, 2009, 10:03pm
5
Try this:
<?php
if (isset($_POST['user'])) {
$user->attributes=$_POST['user'];
if ($user->validate('delete') && $user->delete())
It might skip the insert scenario rules that way. Not sure
mocapapa
(Mocapapa)
January 25, 2009, 6:13am
6
Thanks Jonah,
if ($user->validate('delete') && $user->delete())
It may work though I replaced Yii to that in SVN according to Qiang's comment saying:
Quote
This issue has been fixed in SVN. In 1.0.1, if you do not specify 'on' when calling
validate(), all validators will be invoked. This is not reasonable as shown in your
example. Thanks.
And my application is working fine.
Thanks!