è»ã賌å
¥ãããšãã«ãHabréã®èšäºãšè¿œå ãªãã·ã§ã³ã«å
±éããã³ã¡ã³ãã¯äœã§ããïŒ
ããŒã¿ã¢ããªã³ã°ã®èŠ³ç¹ããèŠããšãã©ã¡ããããã¹ããããããšã³ãã£ãã£ã§ããã芪ãªããžã§ã¯ãããç¬ç«ããŠéèŠãªæå³ãæã¡ãŸããã
YiiïŒ
phpãã¬ãŒã ã¯ãŒã¯ ïŒã«ã¯GiiããããŸããããã¯ãããŠã¹ãæ°åã¯ãªãã¯ããã ãã§ããŒã¿ã¢ãã«ã䜿çšããŠåºæ¬çãªCRUDã€ã³ã¿ãŒãã§ã€ã¹ãäœæã§ããçµã¿èŸŒã¿ã®ã³ãŒããžã§ãã¬ãŒã¿ãŒã§ãã
ããã¹ãããããããŒã¿ãªããžã§ã¯ãã«äŒŒããããªãã®ãçæã§ãããšããã§ããã ä»-ããªãã¯ã詳现ã«ã€ããŠã¯ãã£ãããžããããã
èšäºã®æåŸã§æãçæ°ãªäººã®ããã«ãã¯ã€ãã¯ã¹ã¿ãŒãã®æé ã瀺ããŸãã
ãŸãããã®èšäºã«èå³ããã人ã«ãšã£ãŠã¯ãããžãã¹ã¢ããªã±ãŒã·ã§ã³ããå
éšããã€ã¹ãŸã§ã®åŽé¢ãèæ
®ãããŸãã
- ããžãã¹ã±ãŒã¹ïŒãããã¯ã«ããæçš¿
- ã¡ã€ã³ã®ãããã¯ã®ãªã¹ã
- é¢é£ããæçš¿ã®ãªã¹ã
- å
éšïŒCRUDã«åºã¥ãgiiãžã§ãã¬ãŒã¿ãŒ
- Gii Generatorãã³ãã¬ãŒã
- ãŠã£ãžã§ããã®åºæ¬ã¯ã©ã¹
- çµ±åãã¡ãµãŒãã³ã³ãããŒã©ãŒ
- ã¯ã€ãã¯ã¹ã¿ãŒã
- ãµããŒããšéçºã«ã€ããŠ
ããžãã¹ã±ãŒã¹ïŒãããã¯ã«ããæçš¿
ãããããhabrã«ã€ããŠã®ã³ã¡ã³ããšæªãäŸ å€ãã®å Žåãèšäºèªäœãããæçšã§ããããããã«ãããã¢ããªã±ãŒã·ã§ã³ãéçºããéã«ãããŒã¿ã¢ãã«ã®ç¹å®ã®ãªããžã§ã¯ããç¬ç«ãããšã³ãã£ãã£ãšããŠãŠãŒã¶ãŒã«ãšã£ãŠããŸãé¢å¿ããªãå ŽåããããããŸãã
åçŽåãããããžãã¹ã¿ã¹ã¯ãæ€èšããŸããããŸããŸãªãããã¯ã§ã°ã«ãŒãåãããã¡ãã»ãŒãžãå
¬éããããã®Webãµã€ããäœæããŸãã
ãµã€ãã«ã¯æ¬¡ã®ã€ã³ã¿ãŒãã§ã€ã¹ãå¿
èŠã§ãã
- ã¡ã€ã³ããŒãž-å°æ¥ã¯ããŸããŸãªãŠã£ãžã§ããããµããŒãããå¿
èŠããããŸãããå®è£
ã®çŸåšã®æ®µéã§ã¯ãããåºæºã§ãã£ã«ã¿ãŒããããããã¯ã®ãªã¹ãã®ã¿ããããŸãã
- ãããã¯ã®å®å
šãªãªã¹ã-ããŒãã«åœ¢åŒã®ãããã¯ã®å®å
šãªãªã¹ãã
- ãããã¯ããŒãž-ãããã¯ã«é¢ããæ
å ±ãšããã«å
¬éãããŠããæçš¿ã®ãªã¹ãã
ããªãæšæºã§ãããïŒ
ããŒã¿ã¢ãã«ãèŠãŠã¿ãŸãããã
é©ãããããŸããã 2ã€ã®ã¯ã©ã¹ã®ã¢ãã«ã«ããžãã¹ããžãã¯ãå«ãŸããŸãã
- ãããã¯ã¯ã©ã¹- ãããã¯ã®ããŒã¿ãæ€èšŒããã®äžã®æçš¿ã®ãªã¹ããããã³ã¡ã€ã³ããŒãžã®ãŠã£ãžã§ããã®æ¡ä»¶ã«ãã£ãŠãã£ã«ã¿ãŒåŠçããããããã¯ã®ãªã¹ããè¿ãå¥ã®ã¡ãœããã
- Postã¯ã©ã¹ã¯ããŒã¿ãšæ€èšŒã®ã¿ã§ãã
ã¢ããªã±ãŒã·ã§ã³ã¯ã2ã€ã®ã³ã³ãããŒã©ãŒã«ãã£ãŠæäŸãããŸãã
- SiteController-æšæºããŒãžïŒåœç€Ÿãé£çµ¡å
ãªã©ïŒãæ¿èªïŒåç
§æ¡ä»¶ã§ã¯å¿
èŠãããŸããããäœãç¥ã£ãŠããŸãïŒãããã³ã€ã³ããã¯ã¹-ã¡ã€ã³ããŒãžã ãªããªã å°æ¥ãå€ãã®ç°ãªããŠã£ãžã§ãããæ³å®ããŠããŸããã¡ã€ã³ããŒãžããã®ã³ã³ãããŒã©ã«æ®ãããŠã£ãžã§ãããç¹å®ã®ã¢ãã«ã«è»¢éããªãããšã¯çã«ããªã£ãŠããŸãã
- TopicControllerã¯ã¢ã¯ã·ã§ã³ã®æšæºã»ããã§ãïŒãããã¯ã®ãªã¹ããäœæãç·šéã衚瀺ãåé€ã
æœåšçã«ã
PostControllerãçæããããšãã§ããŸã-管çç®çããã³/ãŸãã¯ã³ãŒãã®äžéšãã«ã¹ã¿ã ãŠã£ãžã§ããã«ã³ããŒã¢ã³ãããŒã¹ãããŸããããã®èšäºã®ç¯å²å€ã§ãã
ãããŸã§ãã»ãšãã©ã®ã³ãŒãã¯giiã䜿çšããŠçæã§ããŸããããã«ãããéçºãé«éåããããªã¹ã¯ã軜æžãããŸãïŒæåã³ãŒããå°ãªã=ãã¹ãããå¯èœæ§ãäœããªããŸãïŒã
2ã€ã®è³ªåãæ®ã£ãŠããŸãã
- ã¡ã€ã³ããŒãžã«ãããã¯ã®ãã£ã«ã¿ãŒããããªã¹ãã衚瀺ããæ¹æ³
- ãããã¯ããšã«æçš¿ã®ãªã¹ãã衚瀺ããæ¹æ³ã¯ïŒ
èªåçºé»æ©ã䜿çšããŠãããã解決ã§ããå Žå-ããã¯ç¢ºå®ãªææã«ãªããŸãã
ã¡ã€ã³ã®ãããã¯ã®ãªã¹ã
ãµã€ã/ã€ã³ããã¯ã¹ã¢ãã¬ã¹ãæäŸããã¡ã€ã³ããŒãžã«ã¯ãæå®ã®åºæºã§ãã£ã«ã¿ãŒåŠçããããããã¯ã®ãªã¹ããå«ããå¿
èŠããããŸãã ããžãã¹ããžãã¯ã®äžéšãšããŠãã¢ãã«ã«å«ãŸãããã£ã«ã¿ãŒæ¡ä»¶ã
衚瀺ã®ããã«ãããã€ãã®å®è£
ãªãã·ã§ã³ããããŸãã
æåã®ãæ±ããŠéãããã¥ãŒãã¡ã€ã«ïŒ
views / site / index.php ïŒã§ãã¹ãŠãæ£ããè¡ãããšã§ãïŒ
- ActiveDataProviderãäœæããŸãã
- ãããã¯ã¢ãã«ã®ããŒã¿ãå
¥åããŸãã
- å¿
èŠãªãã£ãŒã«ããæåã§æå®ããŠãæšæºã®ListView / GridViewãŠã£ãžã§ããã䜿çšããŠè¡šç€ºããŸã ã
ããã«é²ãã§ããã¹ãŠã
ãã¥ãŒ/ãµã€ã/ _topic-list-widget.phpãªã©ã®å¥ã®ãã¥ãŒãã¡ã€ã«ã«ããã¯ããã¡ã€ã³ãã¡ã€ã«ããã¬ã³ããŒãåŒã³åºããŸãã ããã«ããã管çæ§ãšæ¡åŒµæ§ãå°ãåäžããŸãããããã§ãããªãæ±ããŠããŸãã
ã»ãšãã©ã®å Žåããã¹ãŠã®ã«ãŒã«ã«åŸã£ãŠãåå¥ã®åå空éïŒäœ¿çšããŠããããŒãžã§ã³ã«å¿ããŠã
ã¢ããª\ãŠã£ãžã§ãããŸãã¯åºæ¬ãã³ãã¬ãŒãã®
ã¢ããª\ã³ã³ããŒãã³ã ïŒã§ãã¢ãã«
ããšã«ActiveDataProviderã®äœæãã«ãã»ã«åããåå¥ã«è¡šç€ºããåå¥ã®
ãŠã£ãžã§ãããäœæããŸãæåºã æ®ãã®ã¯ãã¡ã€ã³ããŒãžãããã®ãŠã£ãžã§ãããåŒã³åºãããšã ãã§ãã ãã®ãœãªã¥ãŒã·ã§ã³ã¯ãã¯ã©ã¹ã®å解ãå¶åŸ¡æ§ãã³ãŒãã®æ¡åŒµæ§ã®ç¹ã§æãæ£ç¢ºã§ãã
ãããããã®ãŠã£ãžã§ããã®ã³ãŒãã¯
actionIndexïŒïŒã®åŠçã«é¢ããŠ
TopicControllerã³ãŒããéåžžã«ç¹°ãè¿ããšæã
ãŸããïŒ ãããŠããã®ã³ãŒããæåã§æžãã®ã¯ãšãŠãé¢åã§ãã
ãã®ã³ãŒããèªåçã«çæããå®æãããŠã£ãžã§ãããåŒã³åºãã ãã®æ¹ãã¯ããã«è¯ãã§ãããïŒ
<?= \app\widgets\TopicControllerWidget::widget([ 'action' => 'index', 'params' => [ 'query' => app\models\Topic::findBySomeSpecificCriteria() ], ]) ?>
é¢é£ããæçš¿ã®ãªã¹ã
ãããã¯/ãã¥ãŒã¢ãã¬ã¹ãæäŸãããããã¯ã衚瀺ããããŒãžã«ã¯ããããã¯èªäœã«é¢ããæ
å ±ãšãããã«å
¬éãããŠããã¡ãã»ãŒãžã®ãªã¹ããå«ããå¿
èŠããããŸãã ããŒãã«éã®é¢ä¿ãæ£ããæ§æãããšãã¢ãã«å
ã®ãããã¯ã®ã¡ãã»ãŒãžã®ãªã¹ããèªåçã«ååŸãããããã衚瀺ã®è³ªåã®ã¿ãæ®ããŸãã
ãã£ã«ã¿ãŒããããããã¯ã®ãªã¹ããšã®é¡æšã«ãããã»ãŒåããªãã·ã§ã³ããããŸãã
1ã€ç®ã¯ããã¥ãŒãã¡ã€ã«ã®ã³ãŒãã§ãã¹ãŠãå®è¡ããŠãããã¯ã衚瀺ããããšã§ãïŒ
views / topic / view.php ïŒã
- ActiveDataProviderãäœæããŸãã
- ã¢ãã«ããã®ããŒã¿ãå
¥å$ model-> getPostsïŒïŒ ;
- å¿
èŠãªãã£ãŒã«ããæåã§æå®ããŠãæšæºã®ListView / GridViewãŠã£ãžã§ããã䜿çšããŠè¡šç€ºããŸã ã
2ã€ç®ã¯ããã®ã³ãŒããå¥ã®ãã¬ãŒã³ããŒã·ã§ã³ãã¡ã€ã«ã
views / topic / _posts-list-widget.phpã«åé¢ããããšã§ããç®éãã«ãªããªãããã«-ã©ããã§åå©çšãããšå€±æããŸãã
3çªç®ã¯æ¬æ ŒçãªãŠã£ãžã§ããã§ã
actionIndexïŒïŒéšåã®æ¡ä»¶ä»ã
PostControllerã®ã³ãŒãã倧éšåè€è£œããŸãããæåã§äœæãããŸãã
ãŸãã¯ãã³ãŒããèªåçã«çæããå®æãããŠã£ãžã§ãããåŒã³åºããŸãã
<?= app\widgets\PostControllerWidget::widget([ 'action' => 'index', 'params' => [ 'query' => $model->getPosts(), ], ]) ?>
å
éšïŒCRUDã«åºã¥ãgiiãžã§ãã¬ãŒã¿ãŒ
ããžãã¹ã¿ã¹ã¯ãå®çŸ©ãããçæããããŠã£ãžã§ããã®èŠä»¶ãæŠèª¬ãããã©ã®ããã«æ£ç¢ºã«çæãããããããããŸãã Giiã«ã¯ãã§ã«CRUDã³ã³ãããŒã©ãŒçšã®ãžã§ãã¬ãŒã¿ãŒããããŸãã CRUDãŠã£ãžã§ããã®å Žåãæ¢åã®ãžã§ãã¬ãŒã¿ãŒã«åºã¥ããŠæ°ãããžã§ãã¬ãŒã¿ãŒãäœæããå¿
èŠããããŸãã
éå§åã®ããã¥ã¡ã³ããžã®ãªã³ã¯-ç¬èªã®æ¡åŒµæ©èœãäœæããå Žåã«ã圹ç«ã¡ãŸãã
æããã«ããã¹ãŠã®æ©èœã¯Yiiæ¡åŒµæ©èœã«ããã±ãŒãžåãããŠããŸããYiiæ¡åŒµæ©èœã¯ãã³ã³ããŒã¶ãŒãä»ããŠã€ã³ã¹ããŒã«ããããããžã§ã¯ãã®ãã³ããŒãã©ã«ããŒã«å
¥ããŸãã
æ¡åŒµæ©èœã¯3ã€ã®éšåã§æ§æãããŸãã
- giiãžã§ãã¬ãŒã¿ãŒãã³ãã¬ãŒããå«ãtemplates / crudãã£ã¬ã¯ã㪠ã
- Controller.phpãã¡ã€ã«-ãŠã£ãžã§ããåŒã³åºãçšã®çµã¿èŸŒã¿ãã¡ãµãŒãã³ã³ãããŒã©ãŒã
- Widget.phpãã¡ã€ã«ã¯ãçæããããã¹ãŠã®ãŠã£ãžã§ããã®åºæ¬ã¯ã©ã¹ã§ãã
Gii Generatorãã³ãã¬ãŒã
æ¡åŒµæ©èœã¯ã³ãŒããçæããå¿
èŠãããããããã®äžå¿éšåã¯Giiãžã§ãã¬ãŒã¿ãŒã§ãã
æåã¯ãæ¡åŒµæ©èœãå®è£
ããã«ã¯ãçµã¿èŸŒã¿ã®CRUDã³ã³ãããŒã©ãžã§ãã¬ãŒã¿çšã®ç¬èªã®ãã³ãã¬ãŒããäœæããã ãã§ååã§ãããšæ³å®ãããŠããŸããã ãšããã§ãããããã£ã¬ã¯ããªããžã§ãã¬ãŒã¿ã§ã¯ãªããã³ãã¬ãŒããšåŒã°ããçç±ã§ãã ããããCRUD-Controllerãžã§ãã¬ãŒã¿ãŒã¯å
¥åããŒã¿ã®éåžžã«éäžçãªæ€èšŒãè¡ããããããšãã°ç¶æ¿ã®ããã«ã¯ã©ã¹ãå€æŽãããªã©ãå€ãã®èŠä»¶ãå®è£
ã§ããŸããã§ããã ãããã£ãŠãæ¡åŒµæ©èœã«ã¯ãã³ãã¬ãŒãã ãã§ãªããæ¬æ Œçãªãžã§ãã¬ãŒã¿ãŒãå«ãŸããŠããŸãã
giiãžã§ãã¬ãŒã¿ãŒã¯ã次ã®éšåã§æ§æãããŠããŸãïŒãã¹ãŠãã³ãã¬ãŒã/ crudãã£ã¬ã¯ããªå
ã«ãããŸãïŒã
- ããã©ã«ãã®ãã£ã¬ã¯ããªã¯ããã¹ãŠã®éæ³ãçºçãããã³ãã¬ãŒãã§ãããã®ãã£ã¬ã¯ããªã®åãã¡ã€ã«ã¯ããããžã§ã¯ãã§çæããã1ã€ã®ãã¡ã€ã«ã«å¯Ÿå¿ããŸãã
- ãã¡ã€ã«form.php-ååããæšæž¬ã§ããããã«ãããã¯çæãã©ã¡ãŒã¿ãŒïŒã¯ã©ã¹åãªã©ïŒãå
¥åããããã®ãã©ãŒã ã§ãã
- File Generator.php-ãã©ãŒã ããããŒã¿ãåãåã£ãŠæ€èšŒãããã³ãã¬ãŒããã¡ã€ã«ãé çªã«åŒã³åºããŠçµæãäœæããçæãªãŒã±ã¹ãã©ã
Generator.phpããã³
form.phpãã¡ã€ã«ã«ã¯ãäž»ã«CRUDãžã§ãã¬ãŒã¿ãŒããã®å
ã®
ãã¡ã€ã«ãšæ¯èŒããŠããã¡ã€ã«åãæ€èšŒã説æãããã³ããŒã«ãããããã¹ããªã©ã®
è¡šé¢çãªå€æŽãå«ãŸããŠããŸãã
ãã³ãã¬ãŒããã¡ã€ã«ã¯ãçæããããã¥ãŒãšãŠã£ãžã§ããã³ãŒãèªäœãæ
åœããŸãã ãŸãããã¡ã€ã«
ãã³ãã¬ãŒã/ crud / default / controller.phpãéèŠã§ããããã¯ãå
ã®ãžã§ãã¬ãŒã¿ãŒã®ã³ã³ãããŒã©ãŒã¯ã©ã¹ã«å¯Ÿå¿ãããŠã£ãžã§ããã¯ã©ã¹ãçŽæ¥çæãã圹å²ãæãããŸãã
ãŠã£ãžã§ããã¯CRUDã³ã³ãããŒã©ãŒãšåãã¢ã¯ã·ã§ã³ãæã€å¿
èŠããããŸãããçææ¹æ³ãå°ãç°ãªããŸãã 以äžã®äŸã¯ãã³ã¡ã³ãä»ãã®çæçµæã瀺ããŠããŸãã
- actionIndex-ãã¹ãŠã®ã¢ãã«ã®ç¡æ¡ä»¶ã®åºåã®ä»£ããã«ãã¡ãœããã¯$ã¯ãšãªãã©ã¡ãŒã¿ãŒãåãå
¥ããŸãã
public function actionIndex($query) { $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); return $this->render('index', [ 'dataProvider' => $dataProvider, ]); }
- actionCreateããã³actionUpdate-æåã®å Žåããªãã€ã¬ã¯ãã®ä»£ããã«ãåã«æåã³ãŒããè¿ãã ãã§ãçµã¿èŸŒã¿ã®ãã¡ãµãŒãã³ã³ãããŒã©ãŒã«ãã£ãŠãããªãåŠçãæäŸãããŸãã
public function actionCreate() { $model = new Post(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return 'success'; } return $this->render('create', [ 'model' => $model, ]); }
- actionDelete-åé€ãŠã£ãžã§ããïŒããã©ã«ãã§ã¯1ã€ã®ãã¿ã³ïŒã衚瀺ããGETã¡ãœãããšãã¢ã¯ã·ã§ã³ãå®è¡ããããã®POSTããµããŒãããŸãã æåããå Žåããªãã€ã¬ã¯ããå®è¡ããŸããããã³ãŒããè¿ããŸãã
public function actionDelete($id) { $model = $this->findModel($id); if (Yii::$app->request->method == 'GET') { return $this->render('delete', [ 'model' => $model, ]); } else { $model->delete(); return 'success'; } }
æåŸã«ããã¥ãŒãã¡ã€ã«ã«ã¯æ¬¡ã®åºæ¬çãªç·šéãå«ãŸããŸãã
- h1ã§ã¯ãªãh2ã«å€æããããã¹ãŠã®ããããŒã
- ããŒãžã®ã¿ã€ãã«ãšãã³ãããªã¹ãã®è¡šç€ºãæ
åœããã³ãŒããåé€ããŸãã-ãŠã£ãžã§ããã¯ãããã«åœ±é¿ãäžããŸããã
- ã¢ãã«ã®äœæãšç·šéã¯ãã¢ãŒãã«ãŠã£ã³ããŠïŒãã«ãã€ã³ã¢ãŒãã«ãŠã£ãžã§ããïŒã䜿çšããŠè¡ãããŸãã
- åé€ãŠã£ãžã§ãããã³ãã¬ãŒããè¿œå -倧ããªèµ€ããã¿ã³ã1ã€ãããŸãã
ãŠã£ãžã§ããã®åºæ¬ã¯ã©ã¹
ãžã§ãã¬ãŒã¿ãŒãäœæ¥ãå®äºãããšãã¢ããªã±ãŒã·ã§ã³ã®åå空éã«ãŠã£ãžã§ããã¯ã©ã¹ãäœæãããŸãã ç¶æ¿ãã§ãŒã³ã¯æ¬¡ã®ããã«ãªããŸããã¢ããªã±ãŒã·ã§ã³çšã«çæããããŠã£ãžã§ããã¯ãããŒã¹æ¡åŒµãŠã£ãžã§ããclass
\ ianikanov \ wce \ Widgetããç¶æ¿ããã次ã«ãããŒã¹YiiãŠã£ãžã§ããclass
\ yii \ base \ Widgetããç¶æ¿ãããŸãã
æ¡åŒµãŠã£ãžã§ããã®åºæ¬ã¯ã©ã¹ã¯ã次ã®ã¿ã¹ã¯ã解決ããŸãã
- 2ã€ã®äž»èŠãªãã£ãŒã«ããå®çŸ©ããŸãïŒ$ actionããã³$ paramsãããããä»ããŠãåŒã³åºããã¥ãŒãããŠã£ãžã§ããã«å¶åŸ¡ã転éãããŸãã
- çæãããã¯ã©ã¹ã§ãªãŒããŒã©ã€ãã§ããå€æ°ã®æšæºãã©ã¡ãŒã¿ãŒãå®çŸ©ããŸããããšãã°ããŠã£ãžã§ããã®ãã¥ãŒãã¡ã€ã«ãžã®ãã¹ããã¡ãµãŒãã³ã³ãããŒã©ãŒãžã®ååãšãã¹ïŒä»¥äžã«ã€ããŠïŒããšã©ãŒã¡ãã»ãŒãžãªã©ã§ãã
- ãã¥ãŒãã¬ã³ããªã³ã°ãããšãã®æšæºãã©ã¡ãŒã¿ãŒãå®çŸ©ããŸãïŒrenderããã³renderFile;
- AccessControlãVerbFilterãªã©ã®æšæºãã£ã«ã¿ãŒãæ©èœããããã«ãã³ã³ãããŒã©ãŒã€ã³ãã©ã¹ãã©ã¯ãã£ã«é¡äŒŒããã€ãã³ãã€ã³ãã©ã¹ãã©ã¯ãã£ãæäŸããŸãã
- ããããã¹ãŠãäžç·ã«åéããrunã¡ãœãããå®çŸ©ããŸãã
çµ±åãã¡ãµãŒãã³ã³ãããŒã©ãŒ
ãããã®ããŒã¿ã®è¡šç€ºã«åé¡ã¯ãããŸãã-ãŠã£ãžã§ããã¯ãã®ç®çã®ããã®ãã®ã§ãã ããããç·šéã«ã¯ã誰ãèšã£ãŠããã³ã³ãããŒã©ãŒãå¿
èŠã§ãã ãŠã£ãžã§ããããšã«åºæã®ã³ã³ãããŒã©ãŒãçæããŸã-ãã®æ¬è³ªã¯ãã¹ãŠå€±ãããŸãã æšæºã®CRUDã䜿çšããããšã¯å¿
ãããé©åã§ã¯ãªããããGIIã®è¿œå èµ·åã«äŸåããããããŸããã ãããã£ãŠããã®ãªãã·ã§ã³ã¯ãæ±çšã®çµ±åã³ã³ãããŒã©ãŒãã¡ãµãŒãã§äœ¿çšãããŸããã
ãã®ã³ã³ãããŒã©ãŒã¯ãæ§æãã¡ã€ã«ãä»ããŠã¢ããªã±ãŒã·ã§ã³ãããã«ç»é²ããã次ã®ã¢ã¯ã·ã§ã³ãå®è¡ããactionIndexãšãã1ã€ã®ã¡ãœããã®ã¿ãå«ãŸããŠããŸãã
- ã¯ã©ã€ã¢ã³ãããã®ãªã¯ãšã¹ããåãå
¥ããŸãã
- å¶åŸ¡ã察å¿ãããŠã£ãžã§ããã¯ã©ã¹ã«è»¢éããŸãã
- ãŠã£ãžã§ããã®çµæãšããŠã®ããžãã¹ãšã©ãŒãåŠçããŸãã
- ã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ã«ãªãã€ã¬ã¯ãããŸãã
ããããããã®ã³ã³ãããŒã©ãŒãããŠããªãããšã瀺ãããšãããéèŠã§ãïŒ
- ã¢ã¯ã»ã¹ã¬ãã«ã¯ãã§ãã¯ããŸãã-ãã®ããžãã¯ã¯ç¹å®ã®ãŠã£ãžã§ããã«å±ããŸãã
- å
¥åæäœã¯å®è¡ãããŸããããã©ã¡ãŒã¿ãŒã¯ãã®ãŸãŸãŠã£ãžã§ããã«æž¡ãããŸãã
- å®çŸ©æžã¿ã®æåã³ãŒãã確èªããå Žåãé€ããåºåãæäœããŸããã
ãã®ã¢ãããŒãã«ããããã¡ãµãŒãã®æ±çšæ§ãç¶æããã»ãã¥ãªãã£èŠä»¶ãã¢ããªã±ãŒã·ã§ã³ã¢ããªã±ãŒã·ã§ã³ã³ãŒããªã©ã®ããžãã¹èŠä»¶ã®å®è£
ãæ®ãããšãã§ããŸãã
ã¯ã€ãã¯ã¹ã¿ãŒã
ããžãã¹äžã®èª²é¡ã¯æ確ã§ãéå§ããæºåã¯ã§ããŠããŸããïŒ æ¡åŒµæ©èœã®äœ¿çšã«ã¯4ã€ã®æé ããããŸãã
- ã€ã³ã¹ããŒã«;
- æ§æ;
- äžä»£;
- ã¢ããªã±ãŒã·ã§ã³ã
æ¡åŒµæ©èœã®ã€ã³ã¹ããŒã«ã¯ãcomposerã䜿çšããŠè¡ãããŸãã
php composer.phar require --prefer-dist ianikanov/yii2-wce "dev-master"
次ã«ãã¢ããªã±ãŒã·ã§ã³æ§æãã¡ã€ã«ã«ããã€ãã®å€æŽãå ããå¿
èŠããããŸãã
ãŸããåç
§ãgiiãžã§ãã¬ãŒã¿ãŒã«è¿œå ããŸãã
if (YII_ENV_DEV) { $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', 'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'], 'generators' => [
次ã«ãçµ±åããããã¡ãµãŒãã³ã³ãããŒã©ãŒããããã«è¿œå ããŸãã
$config = [ ... 'controllerMap' => [ 'wce-embed' => '\ianikanov\wce\Controller', ], ... ];
ããã§ã€ã³ã¹ããŒã«ãšèšå®ãå®äºããŸããã
ãŠã£ãžã§ãããçæããã«ã¯ïŒ
- giiãéããŸãã
- ãCRUD Controller WidgetããéžæããŸã;
- ãã©ãŒã ãã£ãŒã«ãã«å
¥åããŸãã
- ã³ãŒãã衚瀺ããŠçæããŸãã
ããã«ããŠã£ãžã§ããã䜿çšããã«ã¯ãã¢ã¯ã·ã§ã³ãšãã©ã¡ãŒã¿ãŒãæå®ããŠåŒã³åºãå¿
èŠããããŸã-ã³ã³ãããŒã©ãŒãåŒã³åºãããã®ãšã»ãŒåãã§ãã
ã¢ãã«ã®ãªã¹ãã衚瀺ããããã®ãŠã£ãžã§ããïŒ
<?= app\widgets\PostControllerWidget::widget([ 'action' => 'index', 'params' => [ 'query' => $otherModel->getPosts(), ], ]) ?>
1ã€ã®ã¢ãã«ã衚瀺ããããã®ãŠã£ãžã§ããïŒ
<?= app\widgets\PostControllerWidget::widget(['action' => 'view', 'params' => ['id' => $post_id]]) ?>
ã¢ãã«äœæãŠã£ãžã§ããïŒãã¿ã³+ãã©ãŒã ãModalã§ã©ããïŒïŒ
<?= app\widgets\PostControllerWidget::widget(['action' => 'create']) ?>
ã¢ãã«å€æŽãŠã£ãžã§ããïŒãã¿ã³+ãã©ãŒã ãã¢ãŒãã«ã§ã©ããïŒïŒ
<?= app\widgets\PostControllerWidget::widget(['action' => 'update', 'params'=>['id' => $post_id]]) ?>
ã¢ãã«åé€ãŠã£ãžã§ããïŒãã¿ã³ïŒïŒ
<?= app\widgets\PostControllerWidget::widget(['action' => 'delete', 'params'=>['id' => $post_id]]) ?>
ãŠã£ãžã§ãããšãã¹ãŠã®ãã¥ãŒã®ã³ãŒãã¯ã¢ããªã±ãŒã·ã§ã³ã«å±ããç°¡åã«å€æŽããããšãã§ããŸã-ãã¹ãŠãã³ã³ãããŒã©ãŒãçæãããšããšãŸã£ããåãã§ãã
ãµããŒããšéçºã«ã€ããŠ
æ¡åŒµãã©ã®ããã«ãµããŒãããã³éçºããããã«ã€ããŠã®ããã€ãã®èšèã ç§ã¯äž»ãªä»äºãšç§ã®ããµã€ãããããžã§ã¯ãïŒããããããžã§ã¯ãïŒãããã€ãæã£ãŠããŸãã ãããã£ãŠããã®æ¡åŒµæ©èœã¯ç§ã®ãµã€ããããžã§ã¯ãããã®ãµã€ããããžã§ã¯ãã§ããããããããžã§ã¯ãã®ããŒãºã«åãããŠæ¡åŒµæ©èœãéçºããŸãã
ãªãŒãã³ãœãŒã¹ã®æè¯ã®äŒçµ±ã§ã¯ãã³ãŒãã¯
githubã§å©çšã§ããŸãããã°ã®ä¿®æ£ã«é¢ããŠã¯ãµããŒãããŸãããŸãããã«ãªã¯ãšã¹ããéä¿¡ããã人ãããå Žåã¯ã¿ã€ã ãªãŒãªã¬ãã¥ãŒãè¡ãããã«ããŸãã