Ïðåäûäóùàÿ òåìà :: Ñëåäóþùàÿ òåìà |
Àâòîð |
Ñîîáùåíèå |
TyurinP
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 20 Îêò 2008 13:36:01 Ñîîáùåíèÿ: 11 Îòêóäà: Kiev
|
Äîáàâëåíî: 20 Îêò 2008 13:57:38 Çàãîëîâîê ñîîáùåíèÿ: Ðåäàêòèðîâàíèå Ì, êîãäà ÷àñòü íåîáõîäèìûõ ïîëåé îòñóòñòâóåò? |
|
|
Äîáðûé äåíü!
Íåäàâíî îñâàèâàþ cakePHP, ñèñòåìà íðàâèòüñÿ íî âîçíèêàþ âîïðîñû, ìîæåò òå, ó êîãî îïûò ïîáîëüøå ïîäñêàæóò.
cakephp 1.2
èìååì ìîäåëü User c òàêîé âàëèäàöèåé
Êîä: | var $validate = array(
'username' => array(
'username1' => array(
'rule' => array('custom', '/[a-zA-Z0-9_]/'),
'required' => true,
'message' => 'Username cannot be empty'
),
'username2' => array(
'rule' => 'isUnique',
'message' => 'This username has already been taken.'
)
),
'email' => array(
'rule' => 'email',
'required' => true,
'message' => 'Please enter a valid email'
),
'password' => array(
'passwordSimilar' => array(
'rule' => 'checkPasswords',
'message' => 'Different password re entered.'
)
),
'password2' => array(
'long' => array(
'rule' => array('between', 5, 15),
'message' => 'Passwords must be between 5 and 15 characters long.'
)
)
); |
ò.å. íåîáõîäèìûå ïîëÿ username è email
äîïóñòè ÿ äåëàþ ôóíêöèþ ñìåíû ïàðîëÿ è ïîëÿ email ó ìåíÿ â ôîðìå íåò. Ïðè ïîïûòêå Êîä: | $this->User->save($this->data); | ìíå âûäàåòñÿ îøèáêà, ÷òî ìîë íåò çíà÷åíèÿ email, óäîâëåòâîðÿþùåãî óñëîâèÿì. Ïîêà ÷òî âûâîæó email â ñêðûòîì ïîëå, íî ýòî æå íåâåðíûé ïîäõîä. Êàê èçáåæàòü ïðîâåðêè îòñóòñòâóþùèõ â ôîðìå ïîëåé?
Ñïàñèáî |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
michas
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 28 ßíâ 2008 11:28:31 Ñîîáùåíèÿ: 123
|
Äîáàâëåíî: 20 Îêò 2008 15:30:47 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
Êîä: |
var $validate = array(
'fieldName1' => array(
'rule' => 'ruleName', // or: array('ruleName', 'param1', 'param2' ...)
'required' => true,
'allowEmpty' => false,
'on' => 'create', // or: 'update'
'message' => 'Your Error Message'));
|
Öèòàòà: |
The ‘on’ key can be set to either one of the following values: ‘update’ or ‘create’. This provides a mechanism that allows a certain rule to be applied either during the creation of a new record, or during update of a record.
If a rule has defined ‘on’ => ‘create’, the rule will only be enforced during the creation of a new record. Likewise, if it is defined as ‘on’ => ‘update’, it will only be enforced during the updating of a record.
The default value for ‘on’ is null. When ‘on’ is null, the rule will be enforced during both creation and update.
|
|
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
TyurinP
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 20 Îêò 2008 13:36:01 Ñîîáùåíèÿ: 11 Îòêóäà: Kiev
|
Äîáàâëåíî: 20 Îêò 2008 15:51:06 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
Ñïàñèáî michas
íî âîò âîïðîñ, åñëè ÿ ïîñòàâëþ äëÿ email 'on' => 'create'
òî íàïðèìåð ïðè ðåäàêòèðîâàíèè ïðîôèëÿ, ïîëüçîâàòåëü ñìîæåò óäàëèòü ñâîé óêàçàííûé ïðè ðåãèñòðàöèè email è íèêàêèõ ñîîáùåíèé îá îøèáêàõ íå ïîëó÷èò? |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
michas
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 28 ßíâ 2008 11:28:31 Ñîîáùåíèÿ: 123
|
Äîáàâëåíî: 20 Îêò 2008 16:44:22 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
íó çàäàâàéòå òîãäà ïðàâèëà âàëèäàöèè èç êîíòðîëëåðà. äëÿ êàæäîãî ýêøèíà - ñâîé _________________ Âñå ñàìîå èíòåðåñíîå â ðåàëüíîì âðåìåíè - xmpp:cakephp@conference.jabber.ru |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
TyurinP
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 20 Îêò 2008 13:36:01 Ñîîáùåíèÿ: 11 Îòêóäà: Kiev
|
Äîáàâëåíî: 20 Îêò 2008 17:01:58 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
michas ïèñàë(à): | íó çàäàâàéòå òîãäà ïðàâèëà âàëèäàöèè èç êîíòðîëëåðà. äëÿ êàæäîãî ýêøèíà - ñâîé |
äà êîíå÷íî! ýòî âàðèàíò, íî ÿ äóìàë, ÷òî åñòü åùå êàêîé-òî âûõîä èç òàêîé ñèòóàöèè |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
michas
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 28 ßíâ 2008 11:28:31 Ñîîáùåíèÿ: 123
|
Äîáàâëåíî: 20 Îêò 2008 18:18:28 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
äóìàþ âðÿòëè åñòü äðóãîé âàðèàíò â âàøåì ñëó÷àå _________________ Âñå ñàìîå èíòåðåñíîå â ðåàëüíîì âðåìåíè - xmpp:cakephp@conference.jabber.ru |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
michas
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 28 ßíâ 2008 11:28:31 Ñîîáùåíèÿ: 123
|
Äîáàâëåíî: 21 Îêò 2008 10:24:02 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
ïî÷èòàë ìàíóàë, ïðè ñîñòàâëåíèè ïðàâèëà äëÿ âàëèäàöèè ïîëÿ åñòü ïàðàìåòð 'required' åñëè ïàðàìåòð óñòàíîâëåí â ïîëîæåíèå "true', òîãäà îíî îáÿçàòåëüíî âàëèäèðóåòñÿ åñëè 'false' òî âàëèäàöèÿ äîëæíà ïðîñèõîäèòü òîëüêî â òîì ñëó÷àå êîãäà ïîëå ïðèñóòñòâóåò â ìàññèâå data. ïîïðîáóéòå òàê ñäåëàòü _________________ Âñå ñàìîå èíòåðåñíîå â ðåàëüíîì âðåìåíè - xmpp:cakephp@conference.jabber.ru |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
TyurinP
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 20 Îêò 2008 13:36:01 Ñîîáùåíèÿ: 11 Îòêóäà: Kiev
|
Äîáàâëåíî: 21 Îêò 2008 15:19:14 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
Î! áîëüøîå ñïàñèáî, ïîïðîáóþ ýòî èìååíî òî, ÷òî íàäî |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
DeeperMD
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 08 Ôåâ 2008 15:04:11 Ñîîáùåíèÿ: 144 Îòêóäà: $Ìîëäîâà->Êèøèí¸â->Áóþêàíû()
|
Äîáàâëåíî: 28 Îêò 2008 21:35:42 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
À åñëëè ïîéòè îò äðóãîãî... ïðîñòî ñäåëàòü unset òåì ñâîéñòâàì ìîäåëè êîòîðûå íå íóæíû â äàíûé ìîìåíò. |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
TyurinP
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 20 Îêò 2008 13:36:01 Ñîîáùåíèÿ: 11 Îòêóäà: Kiev
|
Äîáàâëåíî: 29 Îêò 2008 16:30:13 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
DeeperMD ïèñàë(à): | À åñëëè ïîéòè îò äðóãîãî... ïðîñòî ñäåëàòü unset òåì ñâîéñòâàì ìîäåëè êîòîðûå íå íóæíû â äàíûé ìîìåíò. |
Ïîõîæå íà òî, ÷òî ýòîò âàðèàíò ìíå ïîäõîäèò äàæå áîëüøå.
Ñïàñèáî!!!
ò.å. ÿ ìîãó íàïèñàòü
Êîä: |
unset($this->User->validate['email']);
|
÷òîá îòìåíèòü âàëèäàöèþ email äëÿ User ??? |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
DeeperMD
öèòèðîâàòü
Çàðåãèñòðèðîâàí: 08 Ôåâ 2008 15:04:11 Ñîîáùåíèÿ: 144 Îòêóäà: $Ìîëäîâà->Êèøèí¸â->Áóþêàíû()
|
Äîáàâëåíî: 29 Îêò 2008 22:50:43 Çàãîëîâîê ñîîáùåíèÿ: |
|
|
ÿ íå ïðîáîâàë íî â ïðèíöèïå äîëæíî ïðîêàòèòü.. ýòî æå îáû÷íîå ñâîéñòâî îáû÷íîãî êëàññà.. |
|
Âåðíóòüñÿ ê íà÷àëó |
|
|
|