ããã«ã¡ã¯ãhabrauserïŒ
ä»æ¥ãç§ã¯ããªãã®è£å€æã«äžå®éã®ãã€ããã³ãããæåºããããšæããŸãããããèªãããã«ãç§ã®æ çµã¿ããšåŒã³ãŸãã ã«ããã®äžã«ã¯ãåè§ãè»èŒªãåããå€æ°ã®èªè»¢è»ãã³ãŒãã«é¢ããã°ãããã³ã¡ã³ããããªãããªãã®éã®å®å šã«æå³ã®ãªãããã¹ããããã³ä»ã®å€ãã®åæ§ã®ææã衚瀺ãããŸãã ãããæããªã人-[ãã£ãšèªã]ãã¿ã³ãã¯ãªãã¯ããŠãã ããã
çŸæç¹ã§ã¯ããã¬ãŒã ã¯ãŒã¯ã«ããã€ãã®å€æŽãå ããããŠããããããã®èšäºã®ãã¹ãŠã®äŸãæ©èœããããã§ã¯ãªãããã¬ãŒã ã¯ãŒã¯ã®æ§é ã¯ãããã«ç°ãªããŸãã
ç°¡åãªçŽ¹ä»
çŸæç¹ã§ã¯ãã¢ã¹ã¯ã¯è¿éã®å€§åŠã§3幎çã§ãã³ã³ãã¥ãŒã¿ãŒãœãããŠã§ã¢ãšèªååã·ã¹ãã ã®åŠäœãååŸããŠããŸãã 3幎ç®ã®2åŠæã«ã圌ãã¯ãä»ãæºåãã§ããŸãããã®ãããªããšãç§ãã¡ã«è©±ããŸããããããŠãæ°ããããŒããã³ã³ãã¥ãŒã¿ãŒãããã¯ãŒã¯ãœãããŠã§ã¢ããŸãã¯èšãæããã°ãHTMLãåŠã³å§ããŸããã å°ãåã«ãã¯ã©ã¹ã¡ãŒãã®1人ãHTMLãCSSãããã³PHPã®åŠç¿ãéå§ããããã§ããçšåºŠã®æåãåããŸããã圌ã¯ãªã³ã©ã€ã³ã¹ãã¢ãäœããŸããã ã©ããããããç§ã¯åœŒã«ãœãŒã¹ã³ãŒããèŠããŠãããããã«é Œã¿ãŸããããç¹ã«é©ããããšã¯ãããŸããã§ããã
ãããèŠãŠãç§ã¯é»ã£ãŠããããšãã§ãããMVCãããŒã¹ããããŠãã¹ãŠã®ãžã£ãºã«ã€ããŠäœãããããå§ããŸããã åœç¶ã圌ã¯ç§ã®èšèããã»ãšãã©äœãç解ããŠããŸããã§ããïŒã芧ã®ãšãããç§ã¯ããŸããã説æããŠããŸããïŒã ããããæåéãæ°é±éåŸãäžèšã®ããŒããæããã«ãªããŸããã å çã¯ç§ãã¡ãšä»¥åã«ãããè¡ããŸããããåé¡ãªãç§ãã¡ã¯åœŒãšåçŽçãèªåã§æ±ãããšã«åæããŸããã ãã®çµæãç¹å®ã®æ°ã®ãã¢ã«ã€ããŠããµã€ãã¯èªåã®æã§ãŒãããæžãçŽãããã¯ã©ã¹ã¡ãŒãã¯æ°ãããµã€ãã«å ããŠå°è±¡çãªç¥èãåãåããŸããïŒåœ¹ã«ç«ã€ãšæããŸãïŒã
ç§ã¯ãœãŒã¹ã³ãŒããæšãŠïŒç§ãã¡ã¯åœŒã®ã©ãããããã§äœæ¥ããŸããïŒãèªå® ã§ãããããšèª¿ã¹ãæ©èœãè¿œå ãããªãã¡ã¯ã¿ãªã³ã°ããäœããäœãçŽããŸããã ãã®çµæãããã€ãã®ãããžã§ã¯ããéåžžã«ããŸãæ©èœããäžçš®ã®ãã¬ãŒã ã¯ãŒã¯ãåŸãŸããã ä»ãç§ã¯èªåã®äœåã人ã ã«å ¬éããããšã決ããã®ã§ã圌ã¯ç§ã«ãŠã§ãããã°ã©ãã³ã°ãæãããããããŸãã¯ç§ã®èããããã«çºå±ãããããšã決ããŸããã ãããŠãããªãã¯æ±ºããŠç¥ããªããçªç¶èª°ãã圹ã«ç«ã€ã
ãã¬ãŒã ã¯ãŒã¯æ©èœ
1. 軜éã ãŸããéåžžã«å°ããã é梱ãããšãçŽ34ãããã€ãããããŸãïŒæšæºã®ãŠã§ã«ã«ã ããã¹ããšããŽç»åãåé€ããå ŽåïŒ
2. OOPã®æ¬ åŠã ãããå©ç¹ã§ãããããã®éã§ãããã¯ããããŸããããçè«çã«ã¯OOPã¢ããªã±ãŒã·ã§ã³ã¯æç¶ãåã¹ã¿ã€ã«ã§èšè¿°ãããã¢ããªã±ãŒã·ã§ã³ãããã¯ããã«å€ãã®ãªãœãŒã¹ãæ¶è²»ããŸãã ïŒãããæåã«å®èšŒããã人ããŸã åºç€ãå®å šã«ç解ããŠããªãã£ãå Žåããªããžã§ã¯ãã«ã€ããŠã©ã®ãããªã¹ããŒããããåŸããïŒ
3. MVCã ããŠãããã§ã¯äœã説æããå¿ èŠã¯ãªããšæããŸãã
4. ã«ãŒãã£ã³ã°ã ïŒç§ã®æèŠã§ã¯ïŒã«ãŒãã£ã³ã°ã¯éåžžã«äœ¿ããããã§ãããåæã«èšå®ãéåžžã«æè»ã§ãããæ¹è¯ãå¿ èŠã§ãã ããã©ã«ãã®ã«ãŒãã£ã³ã°ã¯ãController / Action / Param-1 / Value-1 / Param-2 / Value-2ãã§ãã
5. JSONããã³XMLã ãããã®åœ¢åŒã®ããããã§åçãåŸãã«ã¯ãããããã¢ãã¬ã¹ã.jsonããŸãã¯ã.xmlããè¿œå ããå¿ èŠããããŸãã ã€ãŸããã¢ãã¬ã¹ "/ goods / view / id / 3"ã§è£œåã«é¢ããæ å ±ãåãåã£ãå Žåãã¢ãã¬ã¹ "/goods/view/id/3.json"ã§JSON圢åŒã§ååŸã§ããŸãã
6. æ©èœã ã³ãã¥ããã£ã¯1人ã ããªã®ã§ãããã«äœ¿çšã§ããæ©èœã¯ããŸããããŸããã ãããŸã§ã®ãšãããSOAPãã£ã¹ãããã¹ã¯ãªãããäžååã§ãããã»ãã·ã§ã³ã䜿çšãããŠãŒã¶ãŒèªèšŒãéåžžã«æ©èœããŠããŸãã
7. ããã¯ãã¬ãŒã¹ã ãã¬ãŒã³ãã ã¢ããªã±ãŒã·ã§ã³ããããã°ã¢ãŒãã§ãªãå Žåã¯åæãããŸãã
8. DBã MySQLã®ã¿ããµããŒããããŠããŸãã ããã¯ãã€ãã¹ã§ãããçŸæç¹ã§ã¯éèŠã§ã¯ãããŸããã
9. ORMã OOPã¯ååãšããŠãã¬ãŒã ã¯ãŒã¯ã«ååšããªããããããã«ã¯ãããŸããã ãã ããããŒã¿ããŒã¹ã«ã¯äœããã®ãã€ã³ãããããŸãã
10. ACLã çŸæç¹ã§ã¯å©çšã§ããŸãããããã¬ãŒã ã¯ãŒã¯ã®éçºèšç»ïŒå°ãªããšãããã€ãã®è¯å®çãªã¬ãã¥ãŒãåããå Žåã«ã®ã¿éçºãããŸãïŒã¯ããããã§ãã
11. ãããã°ã¢ãŒãã ååšããããã€ãã®ãšã©ãŒã®åºåãããã¯ãã©ãã¯ã®åºåã䜿çšãããèšå®ã«åœ±é¿ããŸãã
ãã¬ãŒã ã¯ãŒã¯æ§é
ã¹ããŒã
| -ã¢ããª/ | -æ§æ/ | -ãããã°/ | -* .php | -* .php | -ã³ã³ãããŒã©ãŒ/ | -* / | -* Action.php | -ã¢ãã«/ | -* .php | -ãã¥ãŒ/ | -ã«ã¹ã¿ã / | -* .phtml | -ã¬ã€ã¢ãŠã/ | -default.phtml | -ã¹ã¯ãªãã/ | -* / | -* .phtml | -ã©ã€ãã©ãª/ | -æ©èœ/ | -default.php | -* .php | -åæå/ | -configs.php | -init.php | -predispatch.php | -ã¢ãã«/ | -basemodel.php | -ã«ãŒã¿ãŒ/ | -router.php | -include.php | -ãã¡ã€ã«/ | -* | -index.php | -.htaccess
ãã¹ãŠãé çªã«æ€èšããŸããã
äžçªäžãã€ãŸã.htaccessãã¡ã€ã«ããå§ããŸãããã ãã®å 容ã¯æ¬¡ã®ãšããã§ãã
RewriteEngine on RewriteCond %{REQUEST_URI} !/files RewriteRule .*$ index.php [L] AddDefaultCharset UTF-8
ã€ãŸããã/ filesãã§å§ãŸã以å€ã®ãªã¯ãšã¹ãã¯ãindex.phpã«ãªãã€ã¬ã¯ããããŸãã å®éããããå¯äžã®æè¯ã®æžãæããªãã·ã§ã³ãšã¯ã»ã©é ããã®ã§ã¯ãããŸããããç§ã¯ãã§ã«ããã䜿çšããããšã«æ £ããŠããããŸã å€æŽããªãããšã«æ±ºããŸããã ããŠãããã©ã«ãã®ãšã³ã³ãŒãã£ã³ã°ïŒUTF-8ã ããã§ã¯ãã以äžèå³æ·±ããã®ã¯èŠåœãããŸããã
index.phpã«ç§»ããŸãããã ãã®å 容ã¯æ¬¡ã®ãšããã§ãã
// ( ) define('APP_DEBUG', TRUE); // define('APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR); define('LIBRARY_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR); // , require_once(LIBRARY_PATH . 'include.php'); // startAction(); // loadLayout($_response['layout']);
ããã§ã¯ããã¹ãŠã®ã¢ã¯ã·ã§ã³ãã³ã¡ã³ããããŠãããããäœã説æããå¿ èŠã¯ãªããšæããŸãã
ãã©ã«ããŒãã¡ã€ã« ã èŠããŠãããããããŸãããããã®ãã©ã«ããŒã®ã¿ãçŽæ¥ã¢ã¯ã»ã¹ã§ããŸããã€ãŸãã index.phpããã€ãã¹ããŸãã ãããã£ãŠãã¹ã¿ã€ã«ã·ãŒããJavaScriptãã¡ã€ã«ãç»åãªã©ã®ãªãœãŒã¹ããã®äžã«åœ¢æãããŸãã
次ã«ã ã¢ããªãã©ã«ããŒã«ã€ããŠèããŸãã ååã瀺ãããã«ãããã¯ã¢ããªã±ãŒã·ã§ã³èªäœã®ãã©ã«ããŒã§ãã ããã«ã¯ãã¢ããªã±ãŒã·ã§ã³æ§æïŒ configãã©ã«ããŒïŒãã³ã³ãããŒã©ãŒïŒ controllersãã©ã«ããŒïŒããã³ãããã®ã³ã³ãããŒã©ãŒã®ã¢ã¯ã·ã§ã³ãã¢ãã«ïŒ modelsãã©ã«ããŒïŒããã³ãã¥ãŒïŒ viewsãã©ã«ããŒïŒãå«ãŸããŠããŸãã
ã³ã³ãããŒã©ãŒã¯ãPHPãã¡ã€ã«ãå«ããã©ã«ããŒã§ã-ã¢ã¯ã·ã§ã³ã ãã©ã«ãåã¯camelCaseã§ããå¿ èŠããããŸãã ã¢ã¯ã·ã§ã³ãã¡ã€ã«ã®ååãcamelCaseã«ããå¿ èŠããããŸãããæ«å°Ÿã«ãActionããšããæ¥å°ŸèŸããããŸãã
ã€ãŸãããã¡ã€ã«ã·ã¹ãã å ã®ååãgoodsããšã¢ã¯ã·ã§ã³ãindexã ã ãshowã ã ãnewã ã ãeditã ãããã³ãdeleteããæã€ã³ã³ãããŒã©ãŒã¯æ¬¡ã®ããã«ãªããŸãã
| -ã³ã³ãããŒã©ãŒ/ | -åå/ | -indexAction.php | -showAction.php | -newAction.php | -editAction.php | -deleteAction.php
ãªãã·ã§ã³ã§ãä»»æã®ã³ã³ãããŒã©ãŒã«_init.phpãã¡ã€ã«ãå«ããããšãã§ããŸãã ãã®ãã¡ã€ã«ã®å 容ã¯ããã®ã³ã³ãããŒã©ãŒã§ã¢ã¯ã·ã§ã³ãå®è¡ããåã«å®è¡ãããŸãã
次ã«ãã¢ãã«ïŒãã©ã«ããŒãmodelsã ïŒã«ã€ããŠèª¬æããŸãã ç§ã®ç解ã§ã¯ãã¢ãã«ã¯ã³ã³ãããŒã©ãŒã§ããã«åŠçããå¿ èŠã®ãªããããã«äœ¿çšã§ããããŒã¿ãè¿ãå¿ èŠããããŸãã ã€ãŸããããšãã°ããããã¯5ã§ææ°ã®ãã¥ãŒã¹ã衚瀺ããå¿ èŠããããŸãã ã³ã³ãããŒã©ããçŽæ¥ãªã¯ãšã¹ããè¡ãããšãã§ããŸãããç§ã®ç解ã§ã¯ãã³ãŒãã次ã®åœ¢åŒã«æžããæ¹ãããæ£ç¢ºã§ãã
loadModel('news'); $_view['last_news'] = getLastNews(5);
ããã§ã¯ã ãnewsãã¢ãã«ã§
getLastNews()
ã¡ãœããã宣èšãããåçŽã«ãã©ãŒããããããŠãã¥ãŒã«è¡šç€ºããããŸãŸã«ãªã£ãŠããããŒã¿ã®é åãè¿ããŸãã
ã¢ãã«èªäœã¯ãåäžã®ãã¡ã€ã«ã«çµåãããã¡ãœããã®ã³ã¬ã¯ã·ã§ã³ã§ãã
ãã¥ãŒã ããã¥ãŒããã©ã«ããŒã«ç§»ããŸãããã 3ã€ã®ãµããã£ã¬ã¯ããªïŒ custom ã layout ã scriptsãå«ãŸããŠããŸãã ãã¹ãŠã®ãã¥ãŒã®æ¡åŒµåã¯.phtmlã§ãã
ã¬ã€ã¢ãŠããã©ã«ããŒã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®ã¬ã€ã¢ãŠããå«ãŸããŸãã 説æããç¹å¥ãªãã®ã¯ãããŸããã ã³ã³ãã³ããã¬ã€ã¢ãŠãã«åºåããã«ã¯ã
content()
ã¡ãœããã䜿çšã
content()
ã
scriptsãã©ã«ããŒã«ã¯ãã¢ã¯ã·ã§ã³ã²ãŒã ã®ãã¥ãŒãå«ãŸããŠããŸãã æ§é ã¯æ¬¡ã®ãšããã§ãïŒ scripts / <Controller name> / <ActionName> .phtml
ããŠã ãã«ã¹ã¿ã ããã©ã«ããŒã«ã¯ãæåã®2ã€ã®ãã©ã«ããŒã«é©ããªãä»ã®ãã¹ãŠã®ãã¥ãŒããããŸãã ããšãã°ãããããŒãªã©ã«ãã£ãŠãµã€ãããŒãããã¯ãåå¥ã«åãåºãããå ŽåããããŸãã
ãããŠæåŸã«ã ãconfigããã©ã«ããŒã æ§æãè€è£œã§ããdebugãµããã£ã¬ã¯ããªãå«ãŸããŠããŸãã å®æ°APP_DEBUGãtrueã®å Žåãã¢ããªã±ãŒã·ã§ã³ã¯config / debugãã©ã«ããŒã§èŠæ±ãããæ§æãèŠã€ããããšããŸããæ§æãååšããªãå Žåã«ã®ã¿ãæ§æãã©ã«ããŒããæ¥ç¶ããŸãã ã¢ããªã±ãŒã·ã§ã³ããããã°ã¢ãŒãã§ãªãå Žåã ãããã°ãã©ã«ããŒã¯ç¡èŠãããŸãã
ãã¹ãŠã®æ§æã¯é åãè¿ãPHPãã¡ã€ã«ã§ããã€ãŸãããã®å 容ã¯æ¬¡ã®ããã«ãªããŸãã
return array( // . . . );
ãã©ã«ããã©ã€ãã©ãªã ã å®éãããã¯ãã¬ãŒã ã¯ãŒã¯ãã®ãã®ã§ããããã詳现ã«æ€èšããããšã¯ããŸããïŒæ¥ããããïŒã ããã€ãã®è©³çŽ°ã®ã¿ã説æããŸãã
ãã©ã«ããŒãæ©èœã ã ãã¬ãŒã ã¯ãŒã¯ã®æ©èœãæ¡åŒµããå¿ èŠãããå Žåãããã«ãããŸãã ãã®ãã©ã«ããŒããã®PHPãã¡ã€ã«ã¯ã
loadFunction($fnc)
ã¡ãœããã䜿çšããŠããŒããããŸãã èªåããŒãã¯ãŸã ãããŸããããè¿ãå°æ¥ã«ãªããŸãã ãŸãããã¡ã€ã«ãdefault.phpãã«ã泚æãæãå¿ èŠããããŸãã ãã¬ãŒã ã¯ãŒã¯ã®ãã¹ãŠã®äž»èŠæ©èœãå«ãŸããŠãããã¢ããªã±ãŒã·ã§ã³ã®èµ·åæã«æ¥ç¶ãããŸãã
initãã©ã«ããŒã§ã¯ãinit.phpãã¡ã€ã«ã«èå³ããããŸãã ã¢ããªã±ãŒã·ã§ã³ãèµ·åãããã³ã«å®è¡ãããããã§åçãªæ§æãå®è¡ããå¿ èŠããããŸãã
ãmodelsããã©ã«ããŒã§ ã ãbasemodel.phpããã¡ã€ã«ã«æ³šæããŠãã ããã ããã¯ãäžã§æžããMySQLã®ãã€ã³ãã£ã³ã°ã§ãã
ãã¬ãŒã ã¯ãŒã¯ã䜿çšãã
ãã®ãã¬ãŒã ã¯ãŒã¯ã§å°ããªã¢ããªã±ãŒã·ã§ã³ãäœæããŠã¿ãŸãããã èªãã æ¬ã®ã«ã¿ãã°ã«ããŠãã ããã
ãããžã§ã¯ãã®äœæãšèšå®
ãªã³ã¯ã®1ã€ã§ãã¬ãŒã ã¯ãŒã¯ãããŠã³ããŒãããŸãïŒ github.com/SazereS/NoNameFramework.git yadi.sk/d/ZAnE6Yq_4kgBe troloload.ru/f/5979_nonameframework.zip dl.dropboxusercontent.com/u/85783372/NoNameFrameworkz
ãã¬ãŒã ã¯ãŒã¯ããµã€ããã©ã«ããŒã«è§£åããŸãã ç§ãã¡ã®ã¢ããªã±ãŒã·ã§ã³ã¯ããŒã¿ããŒã¹ã䜿çšããã®ã§ãããã«ããªãã«ãšã£ãŠäŸ¿å©ãªæ¹æ³ã§ãããäœæããŸãã
app / configã«ç§»åããŠã mysql.phpãã¡ã€ã«ãéããŸãã ããã©ã«ãå€ãç¬èªã®å€ã«çœ®ãæããŸãã 次ã®ããã«ãªããŸããã
// mysql.php return array( 'dbHost' => 'localhost', 'dbUser' => 'root', 'dbPass' => '', 'dbName' => 'test', );
次ã«ã ã©ã€ãã©ãª/ init / init.phpãéããè¡
initDb();
ã確èªã
initDb();
ã³ã¡ã³ããå€ãããŸããã
ãã®åæèšå®ã§ã¯ãå®äºãããšèŠãªãããšãã§ããŸãã
CRUDã¢ããªã±ãŒã·ã§ã³ã®äœæ
ãŸããããŒã¿ããŒã¹ã«ããŒãã«ãå¿ èŠã§ãã ãããæ¬ãšåŒã³ãåidãtitleãauthorãcommentãmarkã§æ§æããŸãã ãããè¡ãã«ã¯ãäœæããããŒã¿ããŒã¹ã«å¯ŸããŠãã®ãªã¯ãšã¹ããå®è¡ããŸãã
CREATE TABLE `books` ( `id` INT(10) NOT NULL AUTO_INCREMENT, `title` VARCHAR(80) NOT NULL, `author` VARCHAR(40) NOT NULL, `comment` TEXT NOT NULL, `mark` INT NOT NULL, PRIMARY KEY (`id`) ) COLLATE='utf8_general_ci' ENGINE=MyISAM;
ã¢ãã«ãå¿ èŠã§ãã ãããè¡ãã«ã¯ã modelsãã©ã«ããŒã«books.phpãã¡ã€ã«ãäœæããŸãã
ããã¯ã³ã³ãããŒã©ãŒãäœæããŸãã ãããè¡ãã«ã¯ã app / controllersãã©ã«ããŒã«booksãã©ã«ããŒãäœæããŸãã
CRUDã¯ãäœæãèªã¿åããæŽæ°ãåé€ïŒäœæãèªã¿åããæŽæ°ãåé€ïŒã®ç¥èªã§ãã ã³ã³ãããŒã©ãçæããã®ã¯ãããã®ã¢ã¯ã·ã§ã³ã§ãã ãããã®ã¢ã¯ã·ã§ã³ããšã«ã¢ã¯ã·ã§ã³ãäœæããŸãã ãããã®ã¢ã¯ã·ã§ã³ã®ååã¯new ã view ã edit ãããã³deleteã§ãã ããã«ããã¹ãŠã®æžç±ããªã¹ãããã¢ã¯ã·ã§ã³ãå¿ èŠã§ãã ããããã€ã³ããã¯ã¹ããšåŒã³ãŸãã ãããè¡ãã«ã¯ã booksãã©ã«ããŒã«indexAction.phpãnewAction.phpãviewAction.phpãeditAction.phpãdeleteAction.phpã® 5ã€ã®ãã¡ã€ã«ãäœæããŸãã
äžéšã®ã¢ã¯ã·ã§ã³ã²ãŒã ã«ã¯ãã¥ãŒãã¡ã€ã«ãå¿ èŠã§ãã å¿ èŠã«å¿ããŠäœæããŸãã æ°ããã¢ã¯ã·ã§ã³ããå§ããŸãããã ãããè¡ãã«ã¯ã views / scriptsãã©ã«ããŒã«ïŒã³ã³ãããŒã©ãŒã®ååã§ïŒ ããã¯ã®ãµããã©ã«ããŒãäœæãããã®äžã«new.phtmlãã¡ã€ã«ïŒã¢ã¯ã·ã§ã³ã®ååã§ïŒãäœæããŸãã 次ã®ããã¹ããäžæçã«æ¿å ¥ããŸãïŒ
books/new
ã 次ã«ãWebãµãŒããŒãèµ·åããŠãã¢ãã¬ã¹ãhttpïŒ// <ãµã€ãã¢ãã¬ã¹> / books / newãã«ç§»åããŸãã ããã§ãæç§æž/ newã衚瀺ãããã¯ãã§ãã
è¡åã«æ»ããŸãããã newAction.phpãã¡ã€ã«ãéãã次ã®ã³ãŒããè¿œå ããŸãã
<?php // models/books.php loadModel('books'); // , POST if(isPost()){ // , $post $post = getPost(); // if(newBook($post)){ // - redirect('books'); } else { // - $_view['form'] = $post; } }
$ _viewå€æ°ã«æ³šæããŠãã ããã ã³ã³ãããŒã©ããã¥ãŒãšéä¿¡ããã®ã¯åœŒå¥³ã®å©ããåããŠã§ãã æž¡ããããã¹ãŠã®å€ã¯ããã¥ãŒãšã¬ã€ã¢ãŠãã®äž¡æ¹ããå©çšã§ããŸãã
ããã«ã
newBook()
é¢æ°ã«ãé¢å¿ããããŸãã å®éããã®æ©èœã¯ãŸã ååšããŸããã äœæããŸãããã ãããè¡ãã«ã¯ãã¢ãã«ïŒ books.php ïŒãéãã次ã®ã³ãŒããããã«æ¿å ¥ããŸãã
<?php function newBook($array) { // 'books' return insertRow('books', $array); }
ããã§ãã¢ãã«ãšã¢ã¯ã·ã§ã³ã®åŠçãå®äºãããã¥ãŒã«æ»ããŸãã 次ã®ã³ãŒããããã«è²Œãä»ããŸãïŒ
<form method="post"> <label> : </label> <br /> <input type="text" name="title" value="<?=$_view['form']['title'] ?>" /> <br /> <label>: </label> <br /> <input type="text" name="author" value="<?=$_view['form']['author'] ?>" /> <br /> <label> : </label> <br /> <textarea name="comment"><?=$_view['form']['comment'] ?></textarea> <br /> <label> ( 1 10): </label> <br /> <input type="text" name="mark" value="<?=$_view['form']['mark'] ?>" /> <br /> <button type="submit"></button> </form>
ããã§ããã©ãŠã¶ã§ããŒãžãæŽæ°ãããã©ãŒã ãä»ããŠããŒã¿ãè¿œå ã§ããŸãã ããŒã¿ã¯è¿œå ãããŸããããªãã€ã¬ã¯ãåŸããã¥ãŒã®æ¬ èœã«é¢ããã¡ãã»ãŒãžã衚瀺ãããŸãã äœæããŸãããïŒãã¡ã€ã«ã¯index.phtmlãšåŒã°ããŸãïŒã
次ã«ãã¢ã¯ã·ã§ã³ã€ã³ããã¯ã¹ã«ç§»åããŸã ã ã³ãŒããããã«æ¿å ¥ããŸãã
<?php // loadModel('books'); // $_view['books'] = getAllBooks();
ã芧ã®ãšãããååšããªã
getAllBooks()
é¢æ°ãåã³äœ¿çšããŸããã ãããã®è¡ãã¢ãã«ã«è¿œå ããŸãã
function getAllBooks() { // , return fetchAll('books'); }
ãã¥ãŒã«ç§»åããŠãããã«ãããæ¿å ¥ããŸãã
<?php if($_view['books']) foreach ($_view['books'] as $v) { ?> #<?=$v['id'] ?>: <a href="<?=baseUrl('books/view/id/'.$v['id']) ?>"><?=$v['title'] ?></a><br /> <?php } ?>
ããã§ãæ°ãã
baseUrl()
é¢æ°ã
baseUrl()
ãŸããã æ£ãããªã³ã¯ãäœæããå¿ èŠããããŸãã ãã®å Žåããµã€ãã®ã«ãŒããããªã³ã¯ãäœæããããšã§ãããè¡ããªããŠãããŸããŸããããç¹ã«localhost / framework / testã®ãããªã¢ãã¬ã¹ã«ãµã€ãããããµã€ãã®å Žåãäžå¿ èŠãªãã©ãã«ãæé€ã§ããŸãã
ããã§ãã®ã¢ã¯ã·ã§ã³ã§çµäºã§ããŸãã è«çãã§ãŒã³ãã¥ãŒã®æ¬¡ã®ã¢ã¯ã·ã§ã³ã«é²ã¿ãŸã ã é¡æšã«ãã£ãŠãã¹ãŠãæ確ã§ãããããããã§ã³ãŒãå šäœã玹ä»ããŸãã
viewAction.phpïŒ
<?php loadModel('books'); // getBook() , $_view['book'] = getBook(getParam('id'));
ã¢ãã«ã®è¿œå ïŒ
function getBook($id) { // - return fetchRow('books', 'id = ' . $id); }
衚瀺ïŒäœæããããšãå¿ããªãã§ãã ããïŒïŒ
<strong>: </strong> <?=$_view['book']['title'] ?><br /> <strong>: </strong> <?=$_view['book']['author'] ?><br /> <strong>: </strong><br /> <?=$_view['book']['comment'] ?><br /> <strong>: </strong> <?=$_view['book']['mark'] ?> 10<br /> <a href="<?=baseUrl('books/edit/id/'.$_view['book']['id']) ?>"></a><br /> <a href="<?=baseUrl('books/delete/id/'.$_view['book']['id']) ?>"></a><br />
ä»ããeditAction
editAction.phpïŒ
loadModel('books'); // $_view['form'] = getBook(getParam('id')); if(isPost()){ $post = getPost(); // if(updateBook(getParam('id'), $post)){ // - redirect('books/view/id/'. getParam('id')); } else { // - $_view['form'] = $post; } } // // edit.phtml, new.phtml setResponse('action', 'new');
new.phtmlã®ãã©ãŒã ã䜿çšããããããã®ã¢ã¯ã·ã§ã³ã®ãã¥ãŒã¯äœæããŠããŸããã
ã¢ãã«ã«é¢æ°ãè¿œå ããŸãã
function updateBook($id, $values) { // $id return updateRow('books', 'id = ' . $id, $values); }
æåŸã«ãæåŸã®ã¢ã¯ã·ã§ã³ã¯deleteã§ãã
deleteAction.phpïŒ
loadModel('books'); deleteBook(getParam('id')); redirect('books');
ã¢ãã«ã®æ©èœïŒ
function deleteBook($id) { // return deleteRow('books', 'id = ' . $id); }
ãã®ã¢ã¯ã·ã§ã³ã¯ãã€ã³ããã¯ã¹ã¢ã¯ã·ã§ã³ã«ãªãã€ã¬ã¯ãããããããååãšããŠãã¬ãŒã³ããŒã·ã§ã³ã¯å¿ èŠãããŸããã
ããã§ãçµæã®ã³ãŒãããããã«æ¹åã§ããŸãã ãæ°ã¥ããããããŸããããæ¯åãã¢ã¯ã·ã§ã³ã®éå§æã«ãåãæäœ
loadModel('books')
ã åå¥ã«åãåºããŸãããã ãããè¡ãã«ã¯ãã³ã³ãããŒã©ãŒã®ãã©ã«ããŒã«_init.phpãã¡ã€ã«ãäœæãããã®è¡ãããã«é 眮ããŠãã³ã³ãããŒã©ãŒããåé€ããŸãã ãªã³ã¯ãçªããŠããããžã§ã¯ããæ©èœããŠããããšã確èªããŸãã
次ã«ãæ°ããã¬ã³ãŒããšãã¹ãŠã®ã¬ã³ãŒãã®ãªã¹ããäœæããããã®ãªã³ã¯ãäœæããŸãã ãããè¡ãã«ã¯ããã¡ã€ã«app / views / layout / default.phtmlãéããŸãã
content()
ã«ãŒãã³ã¯ããã¥ãŒã®ã³ã³ãã³ããã¬ã€ã¢ãŠãã§è¡šç€ºããŸãã ãã®ããäžã«æ¬¡ã®ã³ãŒãè¡ãè¿œå ããŸãã
<a href="<?=baseUrl('books') ?>"> </a><br /> <a href="<?=baseUrl('books/new') ?>"> </a><br />
ããã§ããªã¹ããžã®ãªã³ã¯ãšè¿œå ãã©ãŒã ãã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®ããŒãžã«è¡šç€ºãããŸãã
ã«ãŒãã£ã³ã°
åã¢ã¯ã·ã§ã³ã®ã¢ãã¬ã¹ãçæ³çã«ã©ã®ããã«èŠãããã決ããŸãããã ãã®ãªãã·ã§ã³ããå§ãããŸãïŒ
'books' => ''ã 'books / new'-> 'book / new'ã 'books / view / id / {id}'-> 'book / {id}'ã 'books / edit / id / {id}'-> 'book / {id} / edit'ã 'books / delete / id / {id}'-> 'book / {id} / delete'ã
ãããæ©èœããããã«ïŒ config / router.phpãã¡ã€ã«ãéããé åã次ã®åœ¢åŒã«ãã£ã¹ãããŸã ã
return array( # - '' => 'books', # 'book/new' => 'books/new', 'book/{id|int}' => 'books/view/id/{id}', 'book/{id|int}/edit' => 'books/edit/id/{id}', 'book/{id|int}/delete' => 'books/delete/id/{id}', );
æ¬/ 1ã§ã¯ã ID 1ã®æ¬ã«é¢ããæ å ±ãéããŸãããæ®ãã¯åæ§ã§ãã
ã«ãŒãæ§æã«ã€ããŠããå°ã
é£æ³é åã®ããŒã¯ã«ãŒããã¿ãŒã³ã§ãããå€ã¯ãã¹ãŠã®ãã©ã¡ãŒã¿ãŒãå«ãå®éã®ã¢ã¯ã·ã§ã³ã¢ãã¬ã¹ã§ãã åçãªéšåã¯äžæ¬åŒ§ã§å²ãŸããŠããŸãã ã«ãŒãã®åãããã¯ã¯å®å šã«éçãŸãã¯å®å šã«åçã§ããå¯èœæ§ãããããšã«æ³šæããŠãã ãããã€ãŸãã
'user/{id}' => 'users/profile/id/{id}'
-ãšã³ããª
'id{id}' => 'users/profile/id/{id}'
-ééã£ãŠããŸããã€ãŸããçŸæç¹ã§ã¯yoursite.com/id33523ã®ãããªãªã³ã¯ãååŸã§ããŸããããè¿ããã¡ã«ä¿®æ£ããäºå®ã§ãã
ã«ãŒãã¯ãããŒã¿åïŒstring-stringãstrãinteger-intãintegerãfractional-floatãrealïŒããã³éä¿¡ãããå€ã®æ倧é·ã§ãã£ã«ã¿ãªã³ã°ãããŸãã ãã£ã«ã¿ãŒãè¿œå ããã«ã¯ããã©ã¡ãŒã¿ãŒåã®åŸã«ãåçŽããŒã§ãã£ã«ã¿ãŒãæå®ããŸãã äŸïŒ
# '{id|int}' => 'index/index/id/{id}', # 'test/{test|3}' => 'index/index/result/success1/param/{test}', 'test/{test|integer}' => 'index/index/result/success2/param/{test}', 'test/{test|float}' => 'index/index/result/success2/param/{test}', 'test/{test|str|5}' => 'index/index/result/success4/param/{test}', 'test/{test|string}' => 'index/index/result/success5/param/{test}', # 'view' '{controller}/{id|int}' => '{controller}/view/id/{id}', # '{controller}/{action}/{id|int}' => '{controller}/{action}/id/{id}',
ãããã«
å®éãããã¯ãã®ãã¬ãŒã ã¯ãŒã¯ã®ãã¹ãŠã®æ©èœã§ã¯ãããŸãããã=ïŒãšæžãã®ã¯ããããã§ãã å°ãªããšã誰ããç§ã®åµé ç©ã圹ã«ç«ã€ãšæãããšãæã¿ãŸãããããªããã°ããªãç§ã¯ããã«ååæ¶ã«ã€ããããŸããïŒ
ããŠã³ããŒããªã³ã¯
GitHubïŒ github.com/SazereS/NoNameFramework.git
Yandex.DiskïŒ yadi.sk/d/ZAnE6Yq_4kgBe
DropboxïŒ dl.dropboxusercontent.com/u/85783372/NoNameFramework.zip
TrololoadïŒ troloload.ru/f/5979_nonameframework.zip
ãããããé¡ãããŸãïŒ ãšã©ãŒã§éŒ»ãçªããšã匱ç¹ãææããããšãheããªãã§ãã ããã ãããã°ã©ãã³ã°ã®çµäºã¯ããªãã®ãã®ã§ã¯ãããŸãããã®ãããªæã§ãããåŒæ°ã§ãµããŒããããŠããã°æè¬ãããŸãã äºåã«æè¬ããŸãïŒ