phalconのチュートリアルをしていたら、「Service 'db' wasn't found in the dependency injection container」が出ました。
対処法を教えてください・・・!
ファイル構造
tutorial/ app/ controllers/ models/ views/ public/ css/ img/ js/
index.php
1<?php 2 3use Phalcon\Loader; 4use Phalcon\Mvc\View; 5use Phalcon\Mvc\Application; 6use Phalcon\Di\FactoryDefault; 7use Phalcon\Mvc\Url as UrlProvider; 8use Phalcon\Db\Adapter\Pdo\Mysql; 9 10// オートローダにディレクトリを登録する 11$loader = new Loader(); 12 13$loader->registerDirs( 14 [ 15 "../app/controllers/", 16 "../app/models/", 17 ] 18); 19 20$loader->register(); 21 22 23 24// DIコンテナを作る 25$di = new FactoryDefault(); 26 27// ビューのコンポーネントの組み立て 28$di->set( 29 "view", 30 function () { 31 $view = new View(); 32 33 $view->setViewsDir("../app/views/"); 34 35 return $view; 36 } 37); 38 39// ベースURIを設定して、生成される全てのURIが「tutorial」を含むようにする 40$di->set( 41 "url", 42 function () { 43 $url = new UrlProvider(); 44 45 $url->setBaseUri("/tutorial/"); 46 47 return $url; 48 } 49); 50 51 52 53$application = new Application($di); 54 55try { 56 // リクエストを処理する 57 $response = $application->handle(); 58 59 $response->send(); 60} catch (\Exception $e) { 61 echo "Exception: ", $e->getMessage(); 62} 63 64 65 66// Setup the database service 67 68// Make a connection 69$di->set( 70 "db", 71 function () { 72 return new DbAdapter( 73 [ 74 "host" => "localhost", 75 "username" => "root", 76 "password" => "secret", //今だけ変えています 77 "dbname" => "phalcon_test", 78 ] 79 ); 80 } 81);
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。