Symfonyã¨Laravelãæ¯ã¹ã¦ã¿ã¦ã®èå¯
Symfonyã¨Laravelã¯PHPã®Webã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ã§ 2014å¹´ç¾å¨ãã¢ãã³ãªPHPãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦äººæ°ãããããã§ãã 両æ¹ã¨ãComposerã«ããããã±ã¼ã¸ç®¡çãMVCã¢ã¼ããã¯ãã£ã éçºæã®PHPçµã¿è¾¼ã¿ãµã¼ãã®ãµãã¼ãã ãã³ãã«(Laravelã§ã¯ããã±ã¼ã¸)ãªã©ã§ã®æ©è½æ¡å¼µæ§ãæã£ã¦ãã¾ãã
ããæè¿ãå人çãªèå³ã§ãã®ãµãã¤ã®ãã¬ã¼ã ã¯ã¼ã¯ã触ã£ã¦ã¿ã¦ããã®ã§ã ææ³ã¨æ¯è¼ãè¿°ã¹ã¦ã¿ã¾ãã
ãªããå®éã«è§¦ã£ããã¼ã¸ã§ã³ã¯Symfony2.4ã¨Laravel4.1ã§ãã ã¾ãå®éã®ãããã¯ãã®éçºã«ä½¿ç¨ããããã§ã¯ãªãã®ã¨ã ããã©ã¼ãã³ã¹æ¯è¼ãªã©ã¯è¡ã£ã¦ããªããã¨ãæã£ã¦ããã¾ãã
ãã£ããã¨ããæ¯è¼ã¤ã¡ã¼ã¸
ç´°ããææ³ã¨æ¯è¼ãæ¸ãåã«ããã£ããã¨ã¤ã¡ã¼ã¸ãè¿°ã¹ã¦ããã¾ãã
- Symfonyã¯æ§é ããã£ãããã¦ãã¦éå
- Laravelã¯æ§é ããã©ããã§è»½é
ããã§ã®éåã¨ã軽éã¨ãã¯ãããã°ã©ãã³ã°ããã¦ããã¨ãã®æ触ã§ãã£ã¦ã ã¢ããªã±ã¼ã·ã§ã³ã®åä½ã®ãã¨ã§ã¯ããã¾ããã ã¾ããéçºããã¢ããªã±ã¼ã·ã§ã³ã®è¦æ¨¡ã«ãããåããã¦ã ãµã¼ãã¹ãå°è¦æ¨¡ã ããSymfonyã¯é©ãã¦ããªãã¨ãã 大è¦æ¨¡ã ããLaravelã¯ãããªãã¨ãã話ã§ãããã¾ããã
åºæ¬çã«ã¢ããªã±ã¼ã·ã§ã³ã®è¦æ¨¡ãå°è¦æ¨¡ã§ã大è¦æ¨¡ã§ãã©ã£ã¡ã®ãã¬ã¼ã ã¯ã¼ã¯ã使ã£ã¦ãããã¨æãã¾ããã
ã¢ããªã±ã¼ã·ã§ã³ã®è¦æ¨¡ã«ãã¬ã¼ã ã¯ã¼ã¯ã®åãä¸åããå ¨ããªãã¨ã¯æãã¾ãããã ãããããéçºããããã°ã©ãã®ããæ¹ã好ã¿ã«ããããã¦ãããã©ãã ãä¸çªã®ãã¤ã³ããªããããªããã¨æã£ã¦ãã¾ãã以ä¸ãåå¥ã«ããã¯ã¢ãããã¾ãã
ãã¼ã ã¹ãã¼ã¹
PHPã§ã¯5.3ãããã¼ã ã¹ãã¼ã¹ã«ããã³ã¼ãã®æ§é åããµãã¼ãããã¾ããã
Symfonyã§éçºããã³ã¼ãã¯ãã®ãã¼ã ã¹ãã¼ã¹ã§å³æ ¼ã«æ§é åããå¿
è¦ãããã¾ãã
ãã¨ãã°ãPakagistã®ããããã¼ã¸
ã®ã³ã³ããã¼ã©ã¯Packagist\WebBundle\Controller\WebController
ã¨ãããã¼ã ã¹ãã¼ã¹ã«ç½®ããã¦ãã¾ãã
Laravelã§ã¯ã³ã³ããã¼ã©ãã¯ããå¤ãã®ã¯ã©ã¹ãã°ãã¼ãã«ãªãã¼ã ã¹ãã¼ã¹ã使ç¨ãã¾ããLaravelã®å ¸åçãªã³ã³ããã¼ã©ã¯ä»¥ä¸ã®ããã«namespaceãªãã§å®ç¾©ããã¾ãã
<?php
class HomeController extends BaseController {
public function index()
{
return View::make('home.index');
}
}
ãã¼ã ã¹ãã¼ã¹ã«ããæ§é åã¯ã¯ã©ã¹åã®è¡çªãé¿ããããæ§é ã®è¦éãããããã¾ãã ä¸æ¹ã§ããã«åããã¦ãã£ã¬ã¯ããªæ§é ãæ·±ãè¤éã«ãªããã¡ã§ãã
Symfonyã¯æ§é ãå¥å ¨ã§ãããã¨ã«éããããã¦è¨è¨ãããLaravelã¯è¨è¿°ã®ã·ã³ãã«ãã«éããããã¦è¨è¨ããã¦ããæãã§ãã
ããã©ã«ãã®ãã³ãã¬ã¼ãã¨ã³ã¸ã³
Symfonyã¯TwigãLaravelã¯Bladeã¨ãããã³ãã¬ã¼ãã¨ã³ã¸ã³ãæ¨æºã§ä½¿ãã¾ãã
ã¨ããã§ãä¸ä¸ä»£ã¾ãã®PHPãã¬ã¼ã ã¯ã¼ã¯(CakePHP,Symfony1,ZF1)ã ã¨ãç´ ã®PHPããã³ãã¬ã¼ãã¨ã³ã¸ã³ã«ä½¿ç¨ããã®ãã¹ã¿ã³ãã¼ãã§ããã ã§ãæè¿ã¯ããã§ããªããSymfonyã®éçºè ã§ããFabien Potencierã® ããã°ãªã©ã§è¨å ããã¦ããããã«ãç´ ã®PHPã§ã¯ãæé©ããªãã³ãã¬ã¼ãã®è¨è¿°ãè¡ããªãã¨ãããã¨ããã å°ç¨ã®ãã³ãã¬ã¼ãã¨ã³ã¸ã³ãå©ç¨ããããã«ãªã£ã¦ãã¦ãã¾ãã
ç´ ã®PHPãã¹ãã¼ãã«å¯¾å¿ã§ããªãé åã¯ããã³ãã¬ã¼ãç¶æ¿ããã¨ã¹ã±ã¼ãå¦çãã¤ãã¬ã¼ã¿å¦çãªã©ã§ãã ãã¡ãããå ¨ãã§ããªãããã§ã¯ãªãããã¤ã³ã©ã¤ã³ã®phpã¿ã°ã§ãã³ãã¬ã¼ãããã¡ããã¡ããã¦ãã¾ãã®ãé¿ããããªãã ãã®ã¸ãã®åé¡ã¯ãåè¿°ã®Fabienããã®ããã°ã§ãåç §ãã¦ãã ããã
ã§ãSymfonyã¨Laravelã®ãã³ãã¬ã¼ãã¨ã³ã¸ã³ã®ã¯ãªãã
Symfonyã®Tiwgã¯åè¿°ã®PHPãã³ãã¬ã¼ãã®ãã¡ãªé¨åãå®å ¨ã«åãé¤ã㦠çæ³çãªãã³ãã¬ã¼ãã¨ã³ã¸ã³ãç®æãã¦è¨è¨ããã¦ããæãã§ãã ãã³ãã¬ã¼ãç¶æ¿ãã§ããããã¨ã¹ã±ã¼ããèªåãã¾ãforæã¯ä»¥ä¸ã®ããã«æ¸ãã
{% for user in users %}
* {{ user.name }}
{% else %}
No users have been found.
{% endfor %}
ãã®ãã³ãã¬ã¼ãã¯PHPã¨ã¯åºæ¬çã«å¥ãã®ã§ããããã³ãã¬ã¼ãã«PHPãæ¸ããã¨ã¯ã§ãã¾ããã
Laravelã®Bladeãåæ§ã«ãã³ãã¬ã¼ãç¶æ¿ãã¨ã¹ã±ã¼ãæ©è½ãæä¾ãã¦ããã¾ããã è¨è¨ã¨ãã¦PHPã¨å¥ãã®ã§ã¯ãªãç´ ã®PHPãã³ãã¬ã¼ãã«æ£è¦è¡¨ç¾ã«ããèãå¤æå¦çããã¶ãã¦ãã¡ãã£ã¨ææ³ãæ¡å¼µããæãã®ãã®ã§ãã ãªã®ã§ãbladeã®ãã³ãã¬ã¼ãã«ã¯PHPã®ã³ã¼ããæ¸ããã®ã§ãããTwigã®foræã¿ãããªPHPã®æ¸å¼ãã大ããç°ããããªæ©è½ã¯ç¨æããã¦ãã¾ããã
ãã³ãã¬ã¼ãã«ç´ ã®PHPãè¨è¿°ã§ãããã¨ãã害æªã¨ã¨ããæè»æ§ã¨ã¨ããã¯ãããã°ã©ãã®å¥½ã¿ã«ãã話ã ã¨æãã¾ãã ç§ã¯PHPãè¨è¿°ã§ããã»ããããã¨æããã¿ã¤ãã§ãã
Symfonyã¯ãã®é åã«ããã¦æé©ãªã³ã³ãã¼ãã³ããæä¾ããã®ã«å¯¾ãã¦ã Laravelã¯æé©ã§ã¯ãªãããPHPããã°ã©ããæ £ã親ãã¿ãããã³ã³ãã¼ãã³ããæä¾ããã ããããè¨è¨ã«ãªã£ã¦ãã¾ãã
è¨å®ãã¡ã¤ã«
è¨å®ãã¡ã¤ã«ã®è¨è¿°ã«é¢ãã¦ãè¨è¨ææ³ã®éããæãããã¾ãã ãã¨ãã°ãURLã¨ã¢ã¯ã·ã§ã³ãã²ãã¥ããã«ã¼ãã£ã³ã°ã®å®ç¾©ãSymfonyã¯yamlãã¢ããã¼ã·ã§ã³ã使ãã¾ãã (PHPã§ãè¨è¿°ã§ããããããªãåé·ãªã®ã§ããã使ãã²ã¨ã¯å¤åããªã)
ä¸æ¹ãLaravelã¯ç´ ã®PHPã使ãã¾ãããã ãSymfonyã®PHPè¨å®ãã¡ã¤ã«ã®ãããªåé·ãã¯ãªãã ã°ãã¼ãã«ãã¼ã ã¹ãã¼ã¹ã¨ã¹ã¿ãã£ãã¯ã¯ã©ã¹ã§Rubyã®DSLã£ã½ãç°¡æ½ãªè¨è¿°ãæä¾ãã¾ãã
ãã³ãã¬ã¼ãã¨ã³ã¸ã³ã®è©±ã¨åæ§ãªã®ã§ããã Symfonyã¯è¨å®ãã¡ã¤ã«ã®è¨è¿°ã«ããã¦ãæé©ãªæ¹æ³(PHPã¯æé©ã§ã¯ãªãã®ã§yamlãªã©ã®å¥ã®æ段)ãæä¾ããã®ã«å¯¾ãã¦ã Laravelã¯ããã¾ã§PHPã使ã(PHPããã°ã©ãã®ããã®ãã¬ã¼ã ã¯ã¼ã¯ã ããã)ããã®ä¸ã§è¨è¿°ããããæ½çãã¨ã£ã¦ããå°è±¡ã§ãã
ã¾ã¨ã
æå¾ã«æ½è±¡çã«ã¾ã¨ããã¨
- Symfonyã¯PHPã®ãã¡ãªã¨ãããæ¹åããããã«ä½ããããã¬ã¼ã ã¯ã¼ã¯
- Laravelã¯PHPã®ããã¨ããã伸ã°ãããã«ãã¦ä½ããããã¬ã¼ã ã¯ã¼ã¯
ã¨ãã£ãã¨ããã§ããããã