mvc php persian
TRANSCRIPT
-
7/25/2019 Mvc Php Persian
1/28
Model View Contorol
:
php
mvc :
Www.gata-co.ir
1391
Part 1MVC
http://www.gata-co.ir/http://www.gata-co.ir/ -
7/25/2019 Mvc Php Persian
2/28
3 Model View Contoroler4
5 httaccess
! "#$%
MVC
-
7/25/2019 Mvc Php Persian
3/28
Model View Contoroler
&' (! )*%+, .- /0 )+1$&! &2 . )2/ !(%* &$%
)2/. 67//&! .8)9 :;&2)%*=>% 2+% php)?
-
7/25/2019 Mvc Php Persian
4/28
$P
! Q
O
>
>R%
"
)S
&
&.
Cars .N("O Q"TU6#ItemContoroler"#!/+!V TU"QO )%;/+! N.
W Citem view php "#
2
XE
Y
!
%
httaccess
Chtaccess 6%)/
02 6= . .
2.RewriteEngine on
3.RewriteRule ^$ /public [ ]L
4.RewriteRule .!" /public $ [ ]L
#. /< IfModule>
;(= &. =! )'*Z. !
.
$2.RewriteEngine On
$3.
$4. %& ' ()RewriteCond REQUE!_"ILE#ME f$#. %& ' ()RewriteCond REQUE!_"ILE#ME d
$*.
4
MVC
-
7/25/2019 Mvc Php Persian
5/28
$+. .!" . ,RewriteRule ^ $ inde% p&p'url $ [ - ](! L
$.
$. /< IfModule>
6%)2 >( ');L%&/0 ! !+(. %&7IXE
C [index php?url
'&
-
7/25/2019 Mvc Php Persian
6/28
2 Whitespaces/*/& @%U. (8=S S.
Cbootstrap php
.
-
7/25/2019 Mvc Php Persian
7/28
*.
+./!! !!/C&ec2 for M-gic Quote1 -nd remo3e t&em
..function " &1tripl-1&e1*eep $3-lue
2$.$3-lue, " -i1_-rr-0 $3-lue ' -rr-0_m-p )1tripl-1&e1*eep)
" 0 "$3-lue 1trip1l-1&e1 $3-lue ,
2.return$3-lue,
22.'
23.24.function " &remo3eM-gicQuote1
2#.if " " &get_m-gic_/uote1_gpc
2*.$_.E! , 1tripl-1&e1*eep $_.E! ",
2+.$_(O! , 1tripl-1&e1*eep $_(O! ",
2.$_COO4IE, "1tripl-1&e1*eep $_COO4IE ,
2.'3$.'
3.
32./!! !!/C&ec2 regi1ter glob-l1 -nd remo3e t&em
33.
34.function " &unregi1ter.lob-l1
3#.if "" &ini_get )regi1ter_glob-l1)3*.$-rr-0, - - - --rr-0 )_EIO#) )_(O!) )_.E!) )_COO4IE)
- - - ")_REQUE!) )_ERVER) )_E#V) )_"ILE) ,
7
MVC
-
7/25/2019 Mvc Php Persian
8/28
3+.fore-c&$-rr-0-1 " &$3-lue
3.fore-c& [ ]$.LO5L $3-lue -1$2e0, " &> $3-r
3.if$3-r,,, [ ]" &$.LO5L $2e04$. [ ]"un1et $.LO5L $2e0 ,
4.'
42.'
43.'
44.'
4#.'4*.
4+./!! !!/M-in C-ll "unction
4.
4.function " &c-ll6oo2
#$.glob-l$url,
#.#2.$urlrr-0, "-rr-0 ,
#3.$urlrr-0, / - "e%plode 7 7 $url ,
#4.
##.$controller, [$]$urlrr-0 ,
#*. "-rr-0_1&ift $urlrr-0 ,
#+.$-ction, [$]$urlrr-0 ,#. "-rr-0_1&ift $urlrr-0 ,
#.$/uer0tring, $urlrr-0,
8
MVC
-
7/25/2019 Mvc Php Persian
9/28
*$.
*.$controller#-me, $controller,
*2.$controller, "ucword1 $controller ,*3.$model, - "rtrim $controller )1) ,
*4.$controller., )Controller),
*#.$di1p-tc&, new - -$controller $model $controller#-me
"$-ction ,
**.
*+.if " - "" &int met&od_e%i1t1 $controller $-ction*. - "-c-ll_u1er_func_-rr-0 -rr-0 $di1p-tc& $-ction
"$/uer0tring ,
*.' el1e&
+$./! !/Error .ener-tion Code 6ere
+.'
+2.'+3.
+4./!! !!/utolo-d -n0 cl-11e1 t&-t -re re/uired
+#.
+*.function " &__-utolo-d $cl-11#-me
++.if . .file_e%i1t1 ROO! * )libr-r0). .*
" . . . "" &1trtolower $cl-11#-me ) cl-11 p&p)+. . .re/uire_once ROO! * )libr-r0). .*
" . . . "1trtolower $cl-11#-me ) cl-11 p&p) ,
9
MVC
-
7/25/2019 Mvc Php Persian
10/28
+.' el1eif . .file_e%i1t1 ROO! * )-pplic-tion). .* )controller1)
. . " . . "" &* 1trtolower $cl-11#-me ) p&p)
$. . .re/uire_once ROO! * )-pplic-tion). .* )controller1).. " . . "* 1trtolower $cl-11#-me ) p&p) ,
.' el1eif . .file_e%i1t1 ROO! * )-pplic-tion). .* )model1).
. " . . "" &* 1trtolower $cl-11#-me ) p&p)
2. . .re/uire_once ROO! * )-pplic-tion). .* )model1). .*
" . . "1trtolower $cl-11#-me ) p&p) ,
3.' el1e&4./! !/Error .ener-tion Code 6ere
#.'
*.'
+.
. "1etReporting ,
. "remo3eM-gicQuote1 ,$. "unregi1ter.lob-l1 ,
. "c-ll6oo2 ,
_`SetReporting
Z/ ')' %%) )+1$&! . %
[[DEVELOPMENT_ENVIRONMENT true]
N
.
'
-
! a
)
N
.
- c&2 ]%( b 0!- U8N. )5
0
MVC
-
7/25/2019 Mvc Php Persian
11/28
C W W W oursite com controllerName actionName !uerString
2
>
L%&
^
b
N
. $%
RP Y
'
-
&2
)/
d dCCCC"contoroler "action )+! )S Cin#e$ php ]) !+( % _`callhoo%N
.
%
+
"#
,
e C W W W e gata co ir items view &irst item
eController ' items
eMo#el ' item
eView ' #eletee(ction ' #elete
e e)uer String '&irst item
2
f!
/2
'
(
)S (
)5
;
/+! ]f!
)/
$.
-
7/25/2019 Mvc Php Persian
12/28
FFC e [$this >_controller $controller;
FC e [$this >_action $action;
F3C e [$this >_model $model;F4C
F5C e$this >$model[amp; new$model;
FC e [$this >_template amp; new _ d `!emplate $controller $action ;
FiC
FjCl
FkCgCfunction _ d ` hset $name $value
FC e e _ d `$this >_template >set $name $value ;
Cl
3C
4Cfunction _` h__destruct
5C e e _`$this >_template >render ;Cl
iC
jCl
L%&(" )//0 )2US>)+'mA.^]f!
Y+! )- .ren#erN%L%&6%S - !]f( )-)")
]f!
/2
)5
=O
Cmo#el class
MVC
-
7/25/2019 Mvc Php Persian
13/28
$._model /et_class $this ;
gkC e [ _ e `C$this >_table strtolower $this >_model 0s0;FgCl
FFC
FCfunction _` h__destruct
F3Cl
F4Cl
)2A>>R% b,A.J+)2 _`s1l1uer ]f! (/8 n! ")]f!
)+! D%. %RmA.$,.If f! ). . S&2 -/%'(
C CS"#"uer class php
$.
-
7/25/2019 Mvc Php Persian
14/28
g5Cprotected$_result;
gC
giCWoo ooWConnects to databasegjC
gkCfunction _ d d d ` hconnect $address $account $pwd $name
FgC e [ _ d d$this >_db'andle 2ms1l_connect $address $account
`$pwd ;
FFCif_ e p[ g` h$this >_db'andle
FCif_ _ d e `` hms1l_select_db $name $this >_db'andleF3CreturnF;
F4Cl
F5Celseh
FCreturng;
FiCl
FjClFkCelseh
gCreturng;
FCl
Cl
3C
4CWoo ooW%isconnects from database5C
Cfunction _` hdisconnect
4
MVC
-
7/25/2019 Mvc Php Persian
15/28
iCif_ _ e ` p[ g` h2ms1l_close $this >_db'andle
jCreturnF;
kCl elseh3gCreturng;
3FCl
3Cl
33C
34Cfunction _` hselect-ll
35C$1uer[ o C e C3select from 43 $this >_table 343;3Creturn e _ `$this >1uer $1uer ;
3iCl
3jC
3kCfunction _ ` hselect $id
4gC$1uer[ o C e C3select from 43 $this >_table 34 where 4id4
[ C _ `C533 ms1l_real_escape_strin/ $id 3533;4FCreturn e _ d F`$this >1uer $1uer ;
4Cl
43C
44CWoo ooWCustom S"# "uer
45C
4Cfunction _ d1uer $1uer $sin/le+esult[ g` h4iC
4jC e [ _ d e `$this >_result ms1l_1uer $1uer $this >_db'andle ;
5
MVC
-
7/25/2019 Mvc Php Persian
16/28
4kC
5gCif_ _ W W d `` hpre/_match 0 select i0 $1uer
5FC$result[ _`arra ;5C$table[ _`arra ;
53C$field[ _`arra ;
54C$temp+esults[ _`arra ;
55C$num(f6ields[ _ e `ms1l_num_fields $this >_result ;
5Cfor_$i[ g; $i VV ` h7 $num(f6ields; $i
5iC _ d _ e d ``arra_push $table ms1l_field_table $this >_result $i ;5jC _ d _ e d ``arra_push $field ms1l_field_name $this >_result $i ;
5kCl
gC
FCwhile_$row[ _ e `` hms1l_fetch_row $this >_result
Cfor_$i[ g;$i VV ` h7 $num(f6ields; $i
3C q r [ _ _ q r`d `$table $i trim ucfirst $table $i 0s0 ;4C q q rrq q rr [ q r$temp+esults $table $i $field $i $row $i ;
5Cl
Cif_$sin/le+esult[[ F` h
iC _ e `ms1l_free_result $this >_result ;
jCreturn$temp+esults;
kCligC _ d `arra_push $result $temp+esults ;
iFCl
6
MVC
-
7/25/2019 Mvc Php Persian
17/28
iC _ e `ms1l_free_result $this >_result ;
i3C _ `return $result ;
i4Cli5C
iCl
iiC
ijCWoo ooW8et number of rows
ikCfunction _` h/et.um+ows
jgCreturn _ e `ms1l_num_rows $this >_result ;jFCl
jC
j3CWoo ooW6reeresources allocated b a 1uer
j4C
j5Cfunction _` hfree+esult
jC _ e `ms1l_free_result $this >_result ;jiCl
jjC
jkCWoo ooW8et error strin/
kgC
kFCfunction _` h/et*rror
kCreturn _ e `ms1l_error $this >_db'andle ;k3Cl
k4Cl
7
MVC
-
7/25/2019 Mvc Php Persian
18/28
!L' .- b=&I%* P s- .-=tP ) !]f %
2 !]f! b6
-
7/25/2019 Mvc Php Persian
19/28
gkC e [$this >_controller $controller;
FgC e [$this >_action $action;
FFClFC
F3CWoo ooWSet Variables
F4C
F5Cfunction _ d ` hset $name $value
FC e q r [$this >variables $name $value;
FiClFjC
FkCWoo ooW%ispla !emplate
gC
FCfunction _` hrender
C _ e `extract $this >variables ;
3C4Cif_ _ C Cfile_exists +((! %S 3application3C C%S 3views3C C e%S $this
C C C `` h>_controller %S 3header php3
5Cinclude_ C C+((! %S 3application3C C%S 3views3C C e%S $this
C C C `>_controller %S 3header php3 ;
Cl elseh
iCinclude_ C C+((! %S 3application3C C%S 3views3C C%S C `3header php3 ;
jCl
9
MVC
-
7/25/2019 Mvc Php Persian
20/28
kC
3gCinclude_ C C+((! %S 3application3C C%S 3views3C C e%S $this
C C e C C `>_controller %S $this >_action 3 php3 ;3FC
3Cif_ _ C Cfile_exists +((! %S 3application3C C%S 3views3C C e%S $this
C C C `` h>_controller %S 3footer php3
33Cinclude_ C C+((! %S 3application3C C%S 3views3C C e%S $this
C C C `>_controller %S 3footer php3 ;
34Cl elseh35Cinclude_ C C+((! %S 3application3C C%S 3views3C C%S
C `3footer php3 ;
3Cl
3iCl
3jC
3kCl)2.)' !(^0 M
{! 2 {+! 6%/0 )
Cconfi/ php
$.
-
7/25/2019 Mvc Php Persian
21/28
$*.
$+. - "define )*5_#ME) )0ourd-t-b-1en-me) ,
$. - "define )*5_UER) )0ouru1ern-me) ,$. - "define )*5_(8OR*) )0ourp-11word) ,
$. - "define )*5_6O!) )loc-l&o1t) ,
561%
eMini todo |fM! U%$% M> "#$% } Y%^O
S"# 1ueries.CRETET!"E #ite$s#
C _FF`4id4 int .(!.)## dauto_increment
3C _55`4item_name4 varchar .(! d.)##
4C,+:M-+
-
7/25/2019 Mvc Php Persian
22/28
model 2 Citem php Y+! )
.
-
7/25/2019 Mvc Php Persian
23/28
4. ) - ) "$t&i1 >1et )title) )ll Item1 M0 !odoLi1t pp) ,
#. ) - ) ) ""$t&i1 >1et )todo) $t&i1 >Item >1electll ,
*.'+.
.function " &-dd
.$todo, [ ]$_(O! )todo) ,
2$. ) - ) "$t&i1 >1et )title) )ucce11 M0 !odoLi1t pp) ,
2. ) - ) ) $t&i1 >1et )todo) $t&i1 >Item >/uer0 )in1ert into item1
"item_n-me 3-lue1 . ". " ""9)) m01/l_re-l_e1c-pe_1tring $todo )9) ) ,
22.'
23.
24.function delete $id, " &null
2#. ) - ) "$t&i1 >1et )title) )ucce11 M0 !odoLi1t pp) ,
2*. ) - ) ) $t&i1 >1et )todo) $t&i1 >Item >/uer0 )delete from item1, . ". ""w&ere id 9)) m01/l_re-l_e1c-pe_1tring $id )9)) ,
2+.'
2.
2.'
3
MVC
-
7/25/2019 Mvc Php Persian
24/28
W:tems view 02 CView php 00Cview php
. 2< & >
2.
3. ,7>
4. ,#.*eletet&i1 item
*. /< 1p-n>
+. /< ->
Cviewall php
$. , ../ /$2. ,
$3. /< form>
$4. / /
$#.
$*.$+.
$. ,
-
7/25/2019 Mvc Php Persian
25/28
[ ][ ] / $todoitem )Item) )id) '> 7>
$. ,$.
.
2. /< 1p-n>
3. / /< ->
4.
C%elete php
. ,!odo 1ucce11full0
. . /deleted Clic2 &ere to go b-c2 < ->
Cadd php
,!odo 1ucce11full0 -dded . /Clic2 &ere to go b-c2 < ->
Cheader php
$.
gC7head>
g3C7title>7?php echo W$title?>7 title>
g4C7stle>g5CC hitem
gC G4ggwidth px;
5
MVC
-
7/25/2019 Mvc Php Persian
26/28
giC
gjCl
gkCFgC hinput
FFC Gcolor ;
FC e G dfont famil /eor/ia times;
F3C e G4font sie px;
F4C e Gfont wei/ht normal;
F5C e GFCline hei/ht em;FC Gcolor blac=;
FiCl
FjC
FkC ha
gC Gcolor ;
FC e G dfont famil /eor/ia times;C e G4font sie px;
3C e Gfont wei/ht normal;
4C e GFCline hei/ht em;
5C Gcolor blac=;
C e Gtext decoration none;
iCjCl
kC
6
MVC
-
7/25/2019 Mvc Php Persian
27/28
3gC G ha hover
3FC e G 3bac=/round color &C6C %;
3Cl33C F hh
34C G ggggggcolor ;
35C e G4Ffont sie px;
3C e Geletter spacin/ px;
3iC e GFline hei/ht em;
3jC e G d d efont famil helvetica arial sans serif;3kC e GFborder bottom px dotted cccccc;
4gCl
4FC
4C hh
43C G ggggggcolor ;
44C e G34font sie px;45C e Geletter spacin/ px;
4C e GFline hei/ht em;
4iC e G d d efont famil helvetica arial sans serif;
4jC
4kCl
5gC W7 stle>5FC W7 head>
5C7bod>
7
MVC
-
7/25/2019 Mvc Php Persian
28/28
53C F e W F7h >M !odo #ist -pp7 h >
Cfooter php
. /< bod0>
2. /< &tml>
)%&S^O GWW W W Whttp localhost todo items viewall
1.
)%&S C e Cwww /ata co ir % "%,bIf/ (b
e Cinfo2/ata co ir )%&" 1/1; * %
N+
http//anantgarg.com/!""#/"$/1$/write-your-own-php-mvc-framework-
part-1/
MVC
http://localhost/todo/items/viewallhttp://localhost/todo/items/viewallmailto:[email protected]://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/mailto:[email protected]://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/http://localhost/todo/items/viewall