2017-02-14 4 views
2

ModelsにSlim 3でキャッチ可能な致命的なエラーが発生しました。私は私の上で同じを実装するModal class私は次のエラーを取得します。私のモデルのSlim 3でキャッチ可能な致命的なエラーがInterop Container ContainerInterfaceインターフェイスを実装する必要があります

Catchable fatal error: Argument 1 passed to Base\Models\BaseModel::__construct() must implement interface Interop\Container\ContainerInterface, none given, called in \bootstrap\app.php on line 111 and defined in \Models\BaseModel.php on line 11 

これは

use Noodlehaus\Config; 

session_start(); 

require __DIR__ . '/../vendor/autoload.php'; 

$app = new App([ 
    'settings' => [ 
     'determineRouteBeforeAppMiddleware' => true, 
     'displayErrorDetails' => true, 
     'addContentLengthHeader' => false 
    ], 
]); 

$container = $app->getContainer(); 

$container['config'] = function() { 
    return new Config(__DIR__ . '/../config/' . file_get_contents(__DIR__ . '/../env.php') . '.php'); 
}; 

$container['mailer'] = function($container) { 
    return new MailgunEmail; ///LINE 110 
}; 

require __DIR__ . '/../app/routes.php'; 

これはenv.phpある

return [ 
    'mailgun' => [ 
     'apikey' => 'key-123456', 
     'domain' => 'sandbox123456.mailgun.org', 
     'from' => '[email protected]', 
    ], 
]; 

私のベースモデル

namespace Base\Models; 

use Interop\Container\ContainerInterface; 

abstract class BaseModel { 

    protected $container; 

    public function __construct(ContainerInterface $container) { /// LINE 11 
     $this->container = $container; 
    } 

    public function __get($property) { 
     if($this->container->{$property}) { 
      return $this->container->{$property}; 
     } 
    } 

} 

マイメールモデル

私のブートストラップファイルであります
namespace Base\Models; 

use Base\Models\BaseModel; 
use Http\Adapter\Guzzle6\Client; 
use Mailgun\Mailgun; 

class MailgunEmail extends BaseModel { 

    public function sendWithApi($to, $subject, $html) { 
     $client = new Client(); 
     /// INSTEAD OF HARD CODING LIKE THIS 
     $mailgun = new Mailgun('key-123456', $client); 
     /// I WANT TO DO SOMETHING LIKE THIS 
     $mailgun = new Mailgun($this->config->get('mailgun.apikey'), $client); 

     $domain = 'sandbox123456.mailgun.org'; 

     $builder = $mailgun->MessageBuilder(); 
     $builder->setFromAddress('[email protected]'); 
     $builder->addToRecipient($to); 
     $builder->setSubject($subject); 
     $builder->setHtmlBody($html); 

     return $mailgun->post("{$domain}/messages", $builder->getMessage()); 
    } 

} 

なぜこのエラーが発生しているのか、どうやったら解決できるのか分かりません。

答えて

0

$container変数をブートストラップファイルのMailgunEmailコンストラクタに渡すだけです。

$container['mailer'] = function($container) { return new MailgunEmail($container); ///LINE 110 };

+0

WOW、私はとても近くだった信じることができない、おかげでたくさん:-) – John

関連する問題