Yii Framework Forum: Matching String di Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Matching String di Yii Rate Topic: -----

#1 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 01 March 2012 - 08:43 PM

Mau tanya niy, para Master Yii.. Ada yang make fungsi substr atau preg_match dalam mencocokan (matching) strings ga? Kalo ada, bisa kasih contohnya ga? Butuh pencerahan niy.. :D
Thanks before
0

#2 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 01 March 2012 - 09:00 PM

gini bukan mba
di model rules tambahin
<?php

array('STRING_KE1','compare','compareAttribute'=>'STRING_KE2','operator'=>'=');

?>

Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#3 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 01 March 2012 - 09:17 PM

View Postputrilangit, on 01 March 2012 - 09:00 PM, said:

gini bukan mba
di model rules tambahin
<?php

array('STRING_KE1','compare','compareAttribute'=>'STRING_KE2','operator'=>'=');

?>



Thanks reply-nya..Mmmh,, kalo yang saya maksud c yang bakal dicocokin itu penggalan dari string_ke1-nya.. jadi ga semuanya/make array gitu..

Ada saran lain ga, gan?
0

#4 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 01 March 2012 - 09:21 PM

emang gak boleh pake substr ya mba?.
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#5 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 01 March 2012 - 09:30 PM

View Postputrilangit, on 01 March 2012 - 09:21 PM, said:

emang gak boleh pake substr ya mba?.


Bole banget Gan,, justru itu yang tadi saya tanyain.. saya nge-blank krn ga ada contoh.. tadi saya coba akalin dg sarannya agan kyk gini :

public $cekdigit=substr(($model->$string1),0,1);


trus di rulesnya
array('cekdigit','compare','compareAttribute'=>'kode_prop','operator'=>'=',
				  'message'=>''),


malah ngerror.. hehe
0

#6 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 01 March 2012 - 09:39 PM

bisa kasih contoh kasus gak mba, beserta tamble/field yang berkaitan.
agak bingung soalnya , itu "cekdigit" nama field juga ya? :)
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#7 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 01 March 2012 - 09:46 PM

View Postputrilangit, on 01 March 2012 - 09:39 PM, said:

bisa kasih contoh kasus gak mba, beserta tamble/field yang berkaitan.
agak bingung soalnya , itu "cekdigit" nama field juga ya? :)


oh,, ok.. jadi gini, katakan saya punya atribut $string1 (3gigit) dan $string2(2digit).
Saat pengisian form nantinya, 2 digit pertama dari $string1 harus sama dengan $string2. Makanya saya membuat $cekdigit itu sebagai parameter yang nantinya pengambil dua digit dari string1 (ex: string1[0], dan string1[1]).

gtu deh Gan.. :D v
0

#8 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 01 March 2012 - 10:04 PM

klo saya sih karena masih cupu , jadi kyk gini aja :D

<?php
if (isset($_POST["form-string"]){
 $string1 = $_POST["string1"];
 $string2 = $_POST["string2"];
 $sub_str1 = substr($string1,0,1);
 if ($sub_str1 == $string2){
   echo "string1 dan string2 sama";
 }else{
   echo "string1 dan string2 beda"
 }
}
?>


moga membantu ya mba, saya juga masih belajar ^_^
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#9 User is offline   __agus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 166
  • Joined: 22-April 10
  • Location:Yogyakarta, Indonesia

Posted 13 March 2012 - 12:52 PM

Boleh ikutan bantu mbak :D. buat custom validasi aja dimodelnya terus pas di rules-nya tinggal diterapkan
// Misalnya model ini terdapat attribut string1 dan string2
class NamaModel extends CActiveRecord
{
    ...
    // Terapkan custom validasi cekDigit dirules
    public function rules() {
        return array(
            ...
            array('string1', 'cekDigit'),
            ...
        );
    }

    // deklarasi custom validasi
    // Misalnya $string1 = 123 dan $string2 = 12
    public function cekDigit($attribute, $params) {
        if(substr($this->string1, 0, 2) != substr($this->string2, 0, 2) ) {
            $this->addError('string1',  'String 1 harus sama dengan string 2.');
        }else {
            return;
        }
    }
    ...
}

semoga membantu mbak :D

View Postmbaksri, on 01 March 2012 - 09:46 PM, said:

oh,, ok.. jadi gini, katakan saya punya atribut $string1 (3gigit) dan $string2(2digit).
Saat pengisian form nantinya, 2 digit pertama dari $string1 harus sama dengan $string2. Makanya saya membuat $cekdigit itu sebagai parameter yang nantinya pengambil dua digit dari string1 (ex: string1[0], dan string1[1]).

gtu deh Gan.. :D v

0

#10 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 199
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 13 March 2012 - 08:39 PM

nah atas ane lebih Yii bgt tuh... ;)
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users