CakePHP2.5.5ã§ã³ã³ããã¼ã©ã使ã£ã¦ã¿ã
前回ã®ç¶ãã
ä»åã¯CakePHP1.3.6ã®こちらのログãCakePHP2.5.5ã§ãªãã£ã¦ã³ã³ããã¼ã©ã ãã使ã£ã¦ã¿ãã
CakePHPã¯COCï¼Convention over Configurationï¼ãæ¡ç¨ãããã¬ã¼ã ã¯ã¼ã¯ãªã®ã§ãããã«æºãã¦ç¢ºèªç¨ã³ã³ããã¼ã©ã¼ãä½æããã
- ã³ã³ããã¼ã©ã¼ã¯ã/app/controllersé ä¸ã«ããã
- ã³ã³ããã¼ã©ã¼ã®ãã¡ã¤ã«ã¯ã[ããã°ã©ã å]Controller.phpã¨ãããï¼ãã£ã¡ã«è¨æ³ï¼Cake1ç³»ã§ã¯ãããã¢ã³ãã¼ã¹ã³ã¢è¨æ³ã ã£ãï¼
- ã³ã³ããã¼ã©ã¼ã®ã¯ã©ã¹åã¯ã[ããã°ã©ã å]Controllerã¨ãããï¼ãã£ã¡ã«è¨æ³ï¼
- ã³ã³ããã¼ã©ã¼ã®ã¡ã³ãå¤æ°$nameã«ã¯ããã£ã¡ã«è¨æ³ã®ããã°ã©ã åãå ¥ããã
- ããªãããindex()ã¡ã½ãããä½æããã
ãããã°ã©ã åãã¯TesCakeã«ããã/app/controllersã«ãTestCakeController.phpããä½æãã以ä¸ã®ã³ã¼ããæ¸ãã
<?php class TestCakeController extends AppController{ public $name = 'TestCake'; public $uses = null; public $autoRender = false; function index(){ echo "ããã¯CakePHP2.5ã®ã³ã³ããã¼ã©ã¼ã®ãã¹ãã§ã"; } } ?>
ã¡ã³ãã¼å¤æ°ã®$usesã¯ã¢ãã«ã$autoRenderã¯ãã¥ã¼ãã³ãã¬ã¼ãã®å©ç¨ãæå³ããã®ã§ãããã§ã¯ãããããnull, falseã«ãã¦ãindex()ã«ããechoæã§ã¬ã¹ãã³ã¹ãè¿ãã
ããã§ã/localhost/workspace/cakesample/TestCakeã«ã¢ã¯ã»ã¹ããã¨ãindex()ãå¼ã°ãã以ä¸ã®ç»é¢ãã§ãã
ã¡ã½ããã®å¼ã³åºãã¯ã/ããã°ã©ã å/ã¡ã½ããåã§è¡ããã
以ä¸ã®ã³ã¼ããæ¸ãã¦ã¿ãã
<?php class TestCakeController extends AppController{ public $name = 'TestCake'; public $uses = null; public $autoRender = false; function index(){ echo "ããã¯CakePHP2.5ã®ã³ã³ããã¼ã©ã¼ã®ãã¹ãã§ã"; } function index2(){ echo "This is a test of CakePHP2.5 Controller"; } } ?>
ããã§ã/localhost/workspace/cakesample/TestCake/index2ã«ã¢ã¯ã»ã¹ããã¨ãindex2()ãå¼ã°ãã以ä¸ã®ç»é¢ãã§ãã