PHP ? ?????????? ???????? ?????? - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

PHP ? ?????????? ???????? ??????

Description:

: PHP Smarty Smarty Smarty: {* *} { } ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 12
Provided by: V434
Category:
Tags: php | smarty

less

Transcript and Presenter's Notes

Title: PHP ? ?????????? ???????? ??????


1
PHP ? ?????????? ???????? ??????
2
????????? ????
  • script.php?nametest
  • ???????? ???????? ??????????
  • ?????????? ?????????? ??????????????? php-??????
    (???? ???????? ????????? register_globals)name
  • ????? ??????????? ???????????????
    ???????_GET'name'_POST'name'_REQUEST'n
    ame'HTTP_GET_VARS'name' (? PHP3)
  • ??????? import_request_variables('p', 'p_')
  • ????? ?????????? ????????? QUERY_STRING

3
????????? ?????
  • lthtmlgtltbodygt
  • ltH2gt????? ?????? ? ???????lt/H2gt
  • lt?
  • parties array("?????? ??????", "????????????
    ??????", "????", "????")
  • ?gt
  • ltform method"GET" action"anketa.php"gt
  • ltPgt?? ????? ?????? ?? ????????
    ??????????lt/PgtltBLOCKQUOTEgt
  • lt?
  • for(i 0 i lt sizeof(parties) i)
  • ?gt
  • ltINPUT type"radio" id"partylt?i1?gt"
    name"party" value"lt?i1?gt"gt ltLABEL
    for"partylt?i1?gt"gt lt?i1?gt.
    lt?partiesi?gtlt/LABELgtltBRgt
  • lt?
  • ?gt
  • lt/BLOCKQUOTEgtltPgtltINPUT TYPEsubmit
    value"?????????????"gtlt/formgt
  • lt/H3gtlt/bodygtlt/htmlgt

4
????????? ?????
  • lthtmlgtltbodygt
  • ltH2gt????? ?????? ? ???????lt/H2gt
  • lt?
  • dataFile "data.txt"
  • ?gt
  • lt?
  • if(vote_GET"party")
  • save fopen(dataFile,"a")
  • fwrite(save,"vote\n")
  • fclose(save)
  • ?gt
  • ltPgt???? ?????? ??????.lt/Pgt
  • lt?
  • ?gt
  • lt/H3gtlt/bodygtlt/htmlgt

5
????? ??????????? ??????
  • lthtmlgtltbodygt
  • ltH2gt????? ?????? ? ???????lt/H2gt
  • lt? dataFile "data.txt" ?gt
  • lt?
  • if(vote_GET"display")
  • datafopen(dataFile,"r"))
  • while( str fgets(data,2) )
  • votesstr
  • fclose(data)
  • ?gt
  • ltH3gt?????????? ??????lt/H3gtltOLgt
  • lt?
  • for(i 0 i lt sizeof(parties) i)
  • ?gt
  • ltLIgtlt?partiesi?gt lt?votesi1?gt ???????
  • lt?

6
??????? ? PHP
  • ???????? ????????? ????????????? ?? ??????
    (?????? ???????????? ?? ?????? ????????????).
  • ???????
  • ? ?????? ??????? PHP
  • Smarty

7
Smarty
  • ???? ? ???????? Smarty
  • ???????????
  • ????????? ?????? ???????? ?????????
  • func par1"val1" par2"val2" ???????? include
    file"inc.php"
  • php /php

8
Smarty
  • ?????????????????????????????
  • ????????????
  • upper
  • truncate truncate20""
  • default tddefault"nbsp"
  • replace fileName
  • replace" ""_"

9
Smarty
  • ?????????? smarty
  • smarty.get.par1
  • smarty.post.par1
  • smarty.cookies.username
  • smarty.template
  • smarty.ldelim

10
??????. PHP
  • lt?php
  • require_once('smarty/Smarty.class.php')
  • smarty new Smarty()
  • smarty-gttemplate_dir 'templates'
  • smarty-gtcompile_dir 'templates_c'
  • DB-gtquery("SELECT FROM news ORDER BY ID LIMIT
    0,10")
  • smarty-gtassign('news', DB-gtfetchrowset())
  • smarty-gtdisplay('index.tpl.html')
  • ?gt

11
??????. ?????? index.tpl.html
  • lthtmlgt
  • foreach fromnews itemrecord
  • ltPgt????????? record.title
  • Te??? ???????
  • record.description
  • ?????? ?????? lta href"index.php?idrecord.id"
    gt?????????...lt/agt
  • /foreach
  • lt/htmlgt
Write a Comment
User Comments (0)
About PowerShow.com