yii2troller - vietnamese

Upload: hoang-vu

Post on 28-Feb-2018

233 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Yii2Troller - Vietnamese

    1/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    YII2

    TROLLER

    Object oriented programming and mother fucker

    Public: bacpham.wordpress.com

    Year: 2015

    Author : Longt8x

    upport !"pe: bacpd8#

    $mail: bacpham%n&gmail.com

    'u(n s)ch n*" d*nh cho ai +

    ',m ti-t thanh nin ch/a 18 tui c3 4 r6nh r7p %*o c)c trang action cah7t %* ch9 em ph n; %6 l4 do trong b*i h/u) nhi?u l@i tc tu %* bB" bC%6 thD nn !hEng !hu"Dn !hFch ch9 em ph n; %*o xem.

    'h9 em n*o %*o xem th6 c3 h*nh %i Gng xH c3 %In h3a c,m lIng mC t)c giJ l*

    thKng !h(n nCn d xm M . NO cJnh b)o cn c( t6nh %*o r)ng ch9u

    1 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

    mailto:[email protected]:[email protected]:[email protected]:[email protected]
  • 7/25/2019 Yii2Troller - Vietnamese

    2/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    X.1 Yu cu ti thiu:

    NQ hRc /Sc "ii 2 bCn cTn phJi c3 !iDn thGc %;ng %? l7p tr6nh h/

  • 7/25/2019 Yii2Troller - Vietnamese

    3/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    $. %&'() *+( ,- C-$ /0

    .1 Ci 34t 5ng d"ng

    NTu tin bCn tJi xampp %? UhoXc phTn m?m !h)c !- m_ bCn W sau 3 c*i Xt nextnext next `inish.

    iJ sH bCn ang \ $y:zxampp UnDu c*i mXc 9nh th6 %*o ':zprogram `iles `ile m* t6m

    W

    [Cn %*o trang ch "ii`ramewor!.com %* tJi bJn "ii 2 ho*nh tr)ng nh,t %?

    iJi nn "ii `ile %a tJi %? %* i tn `older "ii2 th*nh "iitroller.. %*o th/ mc :$y:zxamppzhtdocsz UNi $ th*nh /@ng d=n th/ mc c*i xampp hoXc ser%er !h)cUwwwW.

    0i#p theo ta t6o 7irtua8 ho9t:

    *o $:zzxamppzapachezcon`zhttp.con` m\ `ile n*" bKng notepad %* nh,n 'trl {U{indW Q `ind 2 t : rewrite %* %host nh< ind next cho t

  • 7/25/2019 Yii2Troller - Vietnamese

    4/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    irtualost "iitroller.com

    ocumentoot $:xampphtdocs"iitrollerbac!endweb

    er%erame bac!end."iitroller.com

    er%erAlias www."iitroller.com

    zirtualost

    0i#p theo mA BindoB trong C:==indoB9=DE9temF2=dri7er9=etc=ho9t9

    * chRn m\ b\i administrator nDu m)" bCn b7t phBn >u"?n thm dng sau %*o cu(i`ile:

    12.0.0.1 "iitroller.com www."iitroller.com

    12.0.0.1 bac!end."iitroller.com

    0hGc hiHn >ong re9tart apache trong >ampp

    4 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    5/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    iDp theo ta %*o th/ mc $:zzxamppzhtdocsz"iitrollerz tCo 2 th/ mc l* : `rontend %*bac!end trong cJ 2 th/ mc 3 tCo thm th/ mc web.

    |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    6/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    iDp theo ta tCo `ile index.php trong `rontendzweb c3 ni dung sau:

    L/u lCi %* %*o 9a chf "iitroller.com ta c3 !Dt >uJ sau

    iDp theo tCo `ile index.php trong bac!endzweb c3 ni dung sau:

    Vo backend.yiitroller.com

    ! |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    7/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    Au ia th7t !hEng thQ tin /Sc chFnh chng tEi cng !hEng thQ tin /Sc m6nh

    c3 thQ l*m /Sc nh/ %7" .

    Ci 34t 5ng d"ng tI command 8ine path

    [Cn tJi : https:zzgetcomposer.orgz'omposeretup.exe sau 3 setup t

  • 7/25/2019 Yii2Troller - Vietnamese

    8/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    'h@ n3 t^ sung s/

  • 7/25/2019 Yii2Troller - Vietnamese

    9/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    J. 06o *ataba9e

    au !hi ho*n th*nh xong %i-c l," code t "ii2 ta %*o localhostzphpm"admin %* tCodatabase gi(ng nh/ sau:

    'reate xong l* o! ta %*o "ii2zcommonzcon`igzmainlocal.php

    * tha" i %ng code lCi cho gi(ng nh/ sau:

    'd' ?> @ 'c!"##' ?> '$%%&d&Coec(%o'A 'd#' ?> ')$#*!+ho#(,!oc"!ho#(-d")e,$%%(.o!!e.'A '#e.")e' ?> '.oo('A 'p"##0o.d' ?> ''A 'ch".#e(' ?> '('ABA

    Ch6E Kigration:

    command promt window:

    $:

    'd xamppzhtdocsz"ii2

    'omposer install UJi g3i "iiso`tW

    au !hi tJi xong g : "ii migrate "es eas" to ma!e

    *o phpm"admin ta s th," 2 bJng m

  • 7/25/2019 Yii2Troller - Vietnamese

    10/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    ',u h6nh lCi %irtual host cho Gng dng m

  • 7/25/2019 Yii2Troller - Vietnamese

    11/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    12.0.0.1 bac!end."ii2.local

    *o compose.son i dngo0e.3"##e(3!%.".$lCi th*nh : 4o0e.3"##e(3!%.".$4: 45edo./o0e.4 6

    78o (.9h d$:( !8) ph;( ho8h (.; 8o"ii2.local

    ^c r >u) ^ s/.php 7 route trong PQL

    Ci `rondentzweb %* bac!endzweb thm ile .htaccess sau:

    11 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    12/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    ewrite$ngine Vn

    ewrite[ase z

    ewrite'ond $${qL$Aj$ `

    ewrite'ond $${qL$Aj$ d

    ewriteule U.~W+~ index.phpz1 LAy

    [Cn c3 thQ l," `ile .htaccess t "ii 1 sang.

    Ci `rontentzcon`igzmainlocal.php %* bac!endzcon`igzmainlocal.php thm oCn sau %*ocon`ig:

    con`ig

    components

    re>uest

    zz insert a secret !e" in the `ollowing Ui` it is empt"W this is re>uired b" coo!ie %alidation

    coo!iealidatione" Lm25{{artppmlau8knnlm

    y

    == Pr8Kanager

    Rur8KanagerR ST

    Rc8a99R ST REiiUBebUPr8KanagerRV

    == *i9ab8e inde>.php

    R9hoBDcript(ameR ST fa89eV

    == *i9ab8e rS route9

    Renab8eWrettEPr8R ST true

  • 7/25/2019 Yii2Troller - Vietnamese

    13/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    y

    y

    y

    *o lCi Login trong "ii2.local : "ii2.localzsitezlogin.

    $$. Lm 7iHc 7i P9er Kode8 7 phn ZuE[n u9er

    r/

  • 7/25/2019 Yii2Troller - Vietnamese

    14/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    h,n " Q th^c hi-n l-nh.

    Du !hEng g /Sc "ii migrate %* b)o li php.exe not recogniM.`uc! `uc! `uc!M th6%*o "ii2 `olderz "ii.bat %* tha" i oCn i` gi(ng d/

  • 7/25/2019 Yii2Troller - Vietnamese

    15/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    h,n " Q th^c hi-n cBu tru" %,n.

    $$.1 Ch\nh 9]a trong P9er Kode8

    hi chng ta O thm mt loCt c)c option h trS cho %i-c Ing !4 %* phBn >u"?n chngta cTn 9nh ngha %* !hai b)o rules cho chng trong model

    *o "ii2zcommonzmodelszser.php

    /*** User model** @property integer $id* @property string $username* @property string $password_hash* @property string $password_reset_token* @property string $email* @property string $auth_key* @property integer $status

    * @property integer $created_at* @property integer $updated_at* @property string $password write-only password* @property integer $role_id* @property integer $user_type_id* @property string $full_name* @property string $images* @property integer $gender* @property string $phone_number*/

    'hfnh sHa beha%iors t^ ng c7p nh7t ng*" gi@ hi-n tCi !hi tCo m

  • 7/25/2019 Yii2Troller - Vietnamese

    16/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    puli! "u#!$io# behaviors%&'

    re$ur# ()timestamp) *+ (

    )c,ass) *+ )iibehaviors/imestamp0ehavior))attributes) *+ (ctiveecord5657/05F95:7;5/ *+ ()createdat))updatedat)?/5 *+ ()updatedat)JIIBA @'e)"%!'A'.e*%.ed'BA @'e)"%!'A'e)"%!'BAB;

    B

    hm label cho atttributes

    /* Your model attribute labels */

    p!%c c(%o attrib#teKabels()E .e(. @ '#("(#'?>'F("(#'A '.o!e=%d'?>'7"% (.'A '#e.")e'?>'U#e.'A 'e)"%!'?>'E)"%!'A

    1! |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    17/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    'p"##0o.d=h"#h'?>'M( hJ'A '!!=")e'?>'HK 58 ('A 'ede.'?>'G%% (h'A 'phoe=)e.'?>'F P%: (hoQ%' B;H

    Co hKng s( cho c)c phTn tH roleidgender:

    co#( STATUS_E!ETE ?

  • 7/25/2019 Yii2Troller - Vietnamese

    18/62

  • 7/25/2019 Yii2Troller - Vietnamese

    19/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    public `unction attributeLabelsUW

    return

    usernamen Ing nh7p

    email$mail

    `ullnameR %* tn

    passwordj7t !hu

    imagesqmages

    genderi

  • 7/25/2019 Yii2Troller - Vietnamese

    20/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    'hfnh lCi %iew "ii2z`rontendz%iewzsignup.php tha" to*n b trong th di% %uan tBm mXc 9nh n3 c3 g6 ti %C Bu moa ch9u

    Od%5 c!"##,4co!3!34>

    Od%5 c!"##,4o.)3.op4>

  • 7/25/2019 Yii2Troller - Vietnamese

    21/62

  • 7/25/2019 Yii2Troller - Vietnamese

    22/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    hm 2 h*m sau Q th^c hi-n %i-c upload Jnh %")e; Fsfile->sae(Ftmp+nameAFpathitems.Fpath.Fformat!ame); Fffile@FiB?Fformat!ame; H .e(. (Fffile); HH

    22 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    23/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    a tCo params %alue Q sH dng tr| t

  • 7/25/2019 Yii2Troller - Vietnamese

    24/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    ')c bCn cG tCo ba %*i user !m l=n Jnh i nh< tCo thm cJ admin %* email l*admin&gmail.com manager guest Q hRc tiDp ch/]ng sau ! tCo phvng m_ ct

    %? >u )nh c) sau !hi tCo xong %*o phpm"admin xem !Dt >uJ t bJng usernDu bCn l*m %i-c chIm chf !hEng >ua" ta" ng g7t th6 s th," h*ng loCt user sau !hi

    tCo

    6C DEng nhiGn ,C ,ogin vCo thoHi con mI nJ mKi tu nhiGn D tMo phNnOuPn thQ mRi cKc SthKnhT hUc phVn tiWp theo vXi o,e 0ased ccess ontro, %0&.

    hEng tin hJM.s@ soCng.. thH coi bee eeee

    24 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

    mailto:[email protected]:[email protected]
  • 7/25/2019 Yii2Troller - Vietnamese

    25/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    $$.F Whn ZuE[n truE cp 7i QJC

    NXc bi-t ch 4 %uan trRng %6 thD nn ch)u n*o chQnh mJng th," n3 %E 4 ngha \ mt th@i iQm

    Uhai b)o nh/ng ch/a dngW ti-n ta" x3a i th6 %E cng chc mng %6 nh;ngphTn sau ?u lin >uan t

  • 7/25/2019 Yii2Troller - Vietnamese

    26/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    BAB;

    iDp theo bCn %*o command prompt U'jW window %* g l-nh sau Q !h\i tCodatabase rbac:

    h,n " Q n3 t^ chC" !hi %*o phpm"admin bCn s th," mt loCt bJng mu"?n ban Tu bao gm cho admin manager userM

    [Cn %*o migrate %* tCo m

  • 7/25/2019 Yii2Troller - Vietnamese

    27/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    c!"## mDIremoePll(); H

    2" |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    28/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    H[Cn update >uer" bKng c)ch g : "ii migrate %*o command promt %* nh,n " Q thi

    h*nh.au !hi th^c hi-n xong bCn s th," trong c)c bJng mu"?n

    a tCo tiDp mt migrate n;a Q th^c h*nh tCo tas!zpermission cho tng user:

    h,n " Q th^c hi-n >uer" %* chfnh lCi gi(ng nh/ sau %*o `ile m

  • 7/25/2019 Yii2Troller - Vietnamese

    29/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    H

    p!%c c(%o do4n() E echo 4)1f2f=]1]=c.e"(e=.o!e=5%e0="o( c"o( e.e5e.(ed6&4;

    .e(. "!#e; H

    H

    iDp theo bCn g "ii migrate %*o command prompt Q th^c hi-n cBu tru" %,n nh,n " Q

    th^c thi.

    iDp theo ta tCo `older rbac c3 chGa `ile Accessule.php rng trong common `older:

    Ci `ile m

  • 7/25/2019 Yii2Troller - Vietnamese

    30/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    o.e"ch (Fthis->.o!e# "# Frole) E

    % (F#ser->getRsu#est()) E Fa#th ? Xii::$app->"(hM""e.; Fpermissions ? Fa#th->getYermissions^yUser(F#ser->%d); Fpermission ? %##e((Fpermissions@'5%e0Re*e#('B)vFpermissions@'5%e0Re*e#('B->")e:''; H

    % (Frole ??? '?') E % (F#ser->getRsu#est()) E .e(. (.e; H H e!#e% (Frole ??? '^') E

    % (F#ser->getRsu#est()) E .e(. (.e; H // 'heck i! the user is logged in+ and the rolesmatch H e!#e% (F#ser->getRsu#est() ww Frole ??? F#ser->%de(%($->.o!e=%d) E .e(. (.e; H e!#e%(TXii::$app->#e.->can(Fpermission)) E .e(. (.e; H

    H .e(. "!#e; H

    H

    *o `rontendzcontrollerz ite'ontroller.php %* chfnh lCi h*m beha%iorsUW gi(ng d/

  • 7/25/2019 Yii2Troller - Vietnamese

    31/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    '.!e#' ?> @ @ '"c(%o#' ?> @'#%p'BA '"!!o0' ?> (.eA '.o!e#' ?> @'?'BA BA @ '"c(%o#' ?> @'"o('BA '"!!o0' ?> (.eA '.o!e#' ?>@User::"#!E_A%A&EAUser::"#!E_AI%BA BA @ '"c(%o#' ?> @'co("c('BA '"!!o0' ?> (.eA

    ')"(chC"!!"c' ?> c(%o() E .e(. TXii::$app->#e.->%de(%($->.o!e=%d>? User::"#!E_AI%; H

    BA @ '"c(%o#' ?> @'!oo('BA '"!!o0' ?> (.eA '.o!e#' ?>@'^'AUser::"#!E_AI%AUser::"#!E_USE"AUser::"#!E_A%A&EBA

    BA BA BA '5e.#' ?> @ 'c!"##' ?> VerbQilter::class,ame()A '"c(%o#' ?> @ '!oo(' ?> @'po#('BA BA BA B;H

    [B" gi@ anh em bvt Tu chec! h*ng tr/

  • 7/25/2019 Yii2Troller - Vietnamese

    32/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    route about tr/

  • 7/25/2019 Yii2Troller - Vietnamese

    33/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    'n admin %* manager %*o /Sc.

    *o http:zz"ii2.localzsitezcontactth6 user s c3 !Dt >uJ sau:

    ? !hoJn phBn >u"?n nDu bCn th," c)c role !iQu int !hEng bJo m7t bCn c3 thQ

    dng h*m static %* dng h*m randomU..MW random 2 ca nS admin %* manager

    trong 2 !hoJng thTn th)nhMJm bJo thKng n*o mu(n hac! role chf c3 !h3c tht .

    rn B" l* to*n b c)ch h/u"?n cho c)c bCn nDu c)c bCn mu(n t6mhiQu cXn ! h]n t bn ngo*i %*o bn trong Dn t7n bi!ini th6 m@i bCn %*o 9a chf :

    http:zzwww."ii`ramewor!.comzdoc2.0zguidesecurit"authoriation.html Q xem chot/@ng t7n bJn thBn m6nh cng !hEng dBm d lvm nn chf \ mGc c\i cc cho c)c bCn

    . 'n %i-c c)c bCn mu(n *o sBu h]n trong %ng n*" c3 l bCn c3 thQ dng g3iextension ca m," thKng In !hEng ngi ri trn mCng cn m6nh xin !iDu %6 >u) nhi?u

    %i-c xB" n(t cho c)c bCn chvc m6nh ra /@ng gia nh7p c)i bang >u) .

    qqq. Co jodels %

  • 7/25/2019 Yii2Troller - Vietnamese

    34/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    !hEng thQ tin ni . 'hFnh chng tEi cng !hEng thQ tin ni tCi sao m6nh c3 thQ b@

    r /Sc nh/ %7" .

    r/uan

    o*n thQM biDt miu tJ thD n*o nhQ mXt xinh da trvng n/

  • 7/25/2019 Yii2Troller - Vietnamese

    35/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    em ch/a c3 !hJ nIng thHM /Sc c)i nh6n 2 tr)i b/\i trvng mu(t cG ong /acng th," %ui mvtMtt m_ hDt cJ cJm xc l7p tr6nhM9nh xEng %*o xin s( th6Mt^ nhin

    em th," m) b9 s/ngM %* mt !huEn mXc c^c ! ho*nh tr)ngM ang ng]ng)c !hEng hiQu chu"-n g6 th6 mt giRng ga" c,t ln : *ng n*" l* h*ng ca b* x6 xinsert('.o!e#'A".."$( '.o!e=")e'?>'Ge#( cce##'A '.o!e=5"!e'?>< ));

    Fthis->insert('.o!e#'A".."$(

    3 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    36/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    '.o!e=")e'?>'U#e. cce##'A '.o!e=5"!e'?>D< )); Fthis->insert('.o!e#'A".."$( '.o!e=")e'?>'d)% cce##'A '.o!e=5"!e'?>J< )); Fthis->insert('.o!e#'A".."$( '.o!e=")e'?>'M""e. cce##'A '.o!e=5"!e'?>L< ));

    Fthis->addQoreignZey('=#e.=.o!e#'A'.o!e#'A'.o!e=5"!e'A'#e.'A'.o!e=%d'A'c"#c"de'A'c"#c"de');

    H

    h,n "ii migrate Q executeM

    *o phpm"admin xem lCi bJng roles:

    3! |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    37/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    $$$.2 06o Qo8e9 Kode8

    [B" ch l* hDt riMlCi m,t i-n @ m@ c)i l Mca%e n nh)"

    http:zzwww."ii2.localzgii%*o gii %* clic! %*o jodel generator.

    hm %*o setting gi(ng h6nh d/

  • 7/25/2019 Yii2Troller - Vietnamese

    38/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

  • 7/25/2019 Yii2Troller - Vietnamese

    39/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

  • 7/25/2019 Yii2Troller - Vietnamese

    40/62

  • 7/25/2019 Yii2Troller - Vietnamese

    41/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    /*** * return role_name * @param mi0ed $role_name1 */ p!%c #("(%c c(%o get[oleVal#e(Frole+name)E Fconnection?TXii::$app->d; FsCl?4Fe!ec( .o!e=5"!e AROM .o!e# WHERE.o!e=")e,+.o!e=")e4; Fcommand?Fconnection->createGommand(FsCl); Fcommand->bindVal#e(4+.o!e=")e4AFrole+name); Fres#lt?Fcommand->C#eryxne(); %(e)p($(Fres#lt))E .e(. Fres#lt@'.o!e=5"!e'B; He!#eE .e(. Fres#lt;

    H HH

    NQ sH dng elpers ta c3 thQ !hai b)o \ b,t !6 Bu !Q cJ %iew bKng %i-c sH dng :#e commonTmodelsTSataelpers;a %*o `rontendzcontrollerszite'ontroller.php thm use bn trn d/render('%de');H

    hi m\ tr6nh du"-t: http:zz"ii2.localz

  • 7/25/2019 Yii2Troller - Vietnamese

    42/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    3ng gCch sJn xu,t em b . ')c bCn hO" s)ng tCo hDt mGc Q /Sc tEn %inh gi(ng

    sJn phm n*"

    $$$. Lm 7iHc 7i P9er trong JackendPhJi cEng nh7n %uaM N/Sc mi em ngon th6 n3 theo bb| cuc ch]iMl?u %Oi sTuM

    [B" gi@ chng ta s l*m %i-c %

  • 7/25/2019 Yii2Troller - Vietnamese

    43/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    Ni?n thEng s( gi(ng d/

  • 7/25/2019 Yii2Troller - Vietnamese

    44/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    PhTn @idget =sed in :ndex >age c]a cH 2 bMn chUn List6iew tha vQ ^ridview.

    Co xong %*o chec! h*ng

    44 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    45/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    * chng ta th," 2 cc shit r,t toM.

    'hfnh sHa la"out main.php trong bac!endz%iewszla"outzmain.php

    W hm #e commonTmodelsTSataelpers; o list #se% (Xii::$app->#e.->%#Ge#( ww Xii::$app->#e.->%de(%($->.o!e=%d >? Fis+admin) E Fmen#Rtems@B ? @'!"e!' ?> 'U#e.#'A '.!' ?> @'#e./%de'BB; Fmen#Rtems@B ? @'!"e!' ?> 'Ro!e#'A '.!' ?>@'/.o!e#/%de'BB;H

    i@ Th) h8) #" 58o co))o/)ode!#/D"("He!pe.#+p!%c #("(%c c(%o get[oleWanagement()E

    Frole+admin?'d)% cce##';Frole+manager?'M""e cce##'; Fconnection?TXii::$app->d; FsCl?4Fe!ec( .o!e=5"!e AROM .o!e# WHERE.o!e=")e,+.o!e="d)% o. .o!e=")e,+.o!e=)""e4; Fcommand?Fconnection->createGommand(FsCl); Fcommand->bindVal#e(4+.o!e="d)%4AFrole+admin); Fcommand->bindVal#e(4+.o!e=)""e4AFrole+manager); Fres#lt?Fcommand->C#eryxne(); %(e)p($(Fres#lt))E .e(. Fres#lt@'.o!e=5"!e'B; He!#eE

    .e(. Fres#lt; HH

    W hm oCn sau %*o trong h*m php sau tag Od%5 c!"##,40."p4>Fis+admin?Sataelpers::check2anager&ole();

    au !hi ho*n th*nh Ing nh7p admin bCn s th," menu bar tha" i nh/ sau:

    'h 4 l* do !hEng hiQu sao h- th(ng b) %Oi !_c redirect 1 /@ng ra 1 no nn bCnphJi %*o bac!endzwebzbac!endz%iewsz Q lEi 2 `older user %* roles mua"lCi bac!endz%iewsz th6 m

  • 7/25/2019 Yii2Troller - Vietnamese

    46/62

  • 7/25/2019 Yii2Troller - Vietnamese

    47/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    r/

  • 7/25/2019 Yii2Troller - Vietnamese

    48/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    'phoe=)e.'A 'c.e"(ed="('A '#("(#'A

    @'c!"##' ?> '$%%&.%d&c(%oCo!)'BA BAB); ?>

    rong commonzcon`igzparamslocal.php chfnh lCi nh/ sau:

  • 7/25/2019 Yii2Troller - Vietnamese

    49/62

  • 7/25/2019 Yii2Troller - Vietnamese

    50/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    D?>'c(%5e'B;

    p!%c #("(%c $list_role?@ self::[xK+uU]\?>zuU]\zA #e!::"#!E_USE"?>'U#e.'A #e!::"#!E_AI%?>'d)%'A #e!::"#!E_A%A&E?>'M""e.'B;

    *o tr6nh du"-t g :http:zzbac!end."ii2.localzuserzindex clic! %*o biQu t/Sng Ei mvt Qxem %iew:

    [B" gi@ l* phTn c^c ! !h3 r,t !h3 %* >u) !h3 trong ' 3 l* delete %

  • 7/25/2019 Yii2Troller - Vietnamese

    51/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    *o bac!endz%iewzuserz`orm.php %* chfnh lCi ni dung trong th di% lCi nh/ sau:

    Od%5 c!"##,4#e.3o.)4>

    (.eB) ?>

    (.eB) ?>

  • 7/25/2019 Yii2Troller - Vietnamese

    52/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    P9er Dearch

    '] chD !hEng !h)c g6 "ii1 nDu bCn "Du "ii2 chf cTn >ua" lCi "ii1 chng tEi %E cng cJm

    ]n nDu bCn b| cEng b| %i-c Q t6m s)ch tEi %iDt

    q La"out hemes ender

    2 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    53/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    q.1 6m hiQu %? ender

    hi chng ta render c)c tham s( hoXc c)c biDn gi) tr9 t controller sang %iew chng tath/@ng c3 !iQu tru"?n th(ng t trong Action b,t ! :

    thisrenderUindexdatadataenderyW

    go*i ra chng ta cng c3 thQ tham chiDu tr^c tiDp thEng >ua gi) tr9 9nh danh hoXc c)cdirector" path:

    Yiiset,ias%_`toZen_ _some,esstempathtoapp,ication_&AYii\app-+view-+render%_`toZensubo,derview_&A

    '] chD render %iew nh/ sau:rootdirector+viewsdirector+ Zhi chng ta Dfnh nghaindex thQ mc Dfnh D hoCn toCn DEjc thiWt ,kp director vC contro,,er vC thERng chl gUi tGn

    action Zhi bMn cVn , 1 view t mt o,der ZhKc trong mt contro,,er ZhKc thQ chl cVn ,DERng dn thqc tXi ,e view DJ vXi cKc tham s D DEjc Dfnh ngha.

    /

  • 7/25/2019 Yii2Troller - Vietnamese

    54/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    ? c] chD la"out gTn nh/ !hEng tha" i trong action trong controller trong %iew t Yii1 %*o bac!endz%iewzla"outzmain.php chfnh sHa lCi oCn sau trong class container :

    Od%5 c!"##,4co("%e.4>

  • 7/25/2019 Yii2Troller - Vietnamese

    55/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    W L*m %i-c %

  • 7/25/2019 Yii2Troller - Vietnamese

    56/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    rong bac!end tCo componentszestkidget.php

  • 7/25/2019 Yii2Troller - Vietnamese

    57/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

  • 7/25/2019 Yii2Troller - Vietnamese

    58/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    h,n pre%iewzgenerate tiDp theo %*o bac!end con`ig mainlocal.php thm dng sau:

    ')od!e#' ?> @ '(e#(' ?> @ 'c!"##' ?> '"ced&)od!e#&(e#('A BABA

    *o tr6nh du"-t xem !Dt >uJ:

    http:zzbac!end."ii2.localztest

    'Eng %i-c cn lCi nh/ thm models crud trong modules gi(ng h-t nh/ "ii1 !hEng biDt

    thi %ui lng m\ lCi s)ch o m\ th6 thEi

    8 |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

    http://backend.yii2.local/testhttp://backend.yii2.local/test
  • 7/25/2019 Yii2Troller - Vietnamese

    59/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    '7p nh7t tin tGc: g*" hEm na" b)o cEng an nhBn dBn b)o an ninh th E b)o ph)plu7t %* @i s(ng Ing tJi % giDt ng/@i gh rSn ng/@i \ tfnh [6nh Ph/

  • 7/25/2019 Yii2Troller - Vietnamese

    60/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    iicachingFi,e?ependenc ?y ,izu cache ph{ thu}c vCo ,Vn modier trong hzthng.

    iicaching/ag?ependenc 7hJm cKc Di tEjng cache vCo tag. ~ng d{ng cJ thva,idate cached obects vXi cng tag gUi bi /ag?ependencinva,idate%\cache \group& vC trH vP ache component and tag DEjc Gu cVu

    iicachinghained?ependenc /his is a specia, Zind o dependencthat groups other dependencies together a,,owing ou to maZe comp,exconditions to inva,idate cached items. %LERi o mun dfch v&

    C)!4e !o-po#e#$ $ro#3 Yii 2 l5 -6$ !l)'' 78 $49) $9 ;ii!)!4i#3C)!4e< 5"r)-e%or7 !u#3 !=p > !)!4i#3 'olu$io#':

    iicachingpcache /his uses the APC >[> extension %see httpphp.netmanua,booZ.apc.php&.

    iicaching?bache ; d{ng bHng trong ;?L %0Mn cJ th thiWt ,kp ZWt ni ZhKctrong cong main app,ication)s&.

    iicaching?ummache

    iicachingFi,eache LEu try Di tEjng trong ,e thE m{c .

    iicachingemache ; d{ng memcache iicaching@inache @inache >[> extension %see

    httpwww.iis.netexpandwincacheorphp&. iicachingache /his uses ?C)!4e %see httpxcache.,ighttpd.net&. iicachingend?ataache /his uses the @e#1 D)$) C)!4e%seehttpwww.end.comenproductsserver& >[> extension

    7goCi ra bMn cJ th d{ng edis or mongo?0 nWu cVn thiWt

    & p4p !o-po'er.p4)r reuire **pre"er*1i'$ ;ii'o"$/;ii2*re1i'

    hai bKo thGm cache trong cong commoncongmain-,oca,.php

    !$ |Longt8x-Yiivn.com Forum - Learn more in bacpham.wordpress.com

  • 7/25/2019 Yii2Troller - Vietnamese

    61/62

    Yii2 Troller

    [LEARN MORE INHTTP://BACPHAM.WORDPRESS.COM]

    )components) *+ ()cache) *+ ()c,ass) *+ )iiredisache)

    )redis) *+ ()hostname) *+ ),oca,host))port) *+ !3"#)database) *+ $uer"VneUW

    6 th@i gian c3 hCn nn %u) b7n tu" nhin nDu bCn O hRc "ii1 ri th6!hi sang "ii2 m