मैं स्लिम में नियंत्रक का उपयोग करने के लिए हालांकि त्रुटिस्लिम नियंत्रक मुद्दा: ContainerInterface, स्लिम \ कंटेनर का उदाहरण दिया का एक उदाहरण होना चाहिए
पीएचपी Catchable घातक त्रुटि मिलती रहती है कोशिश कर रहा हूँ: तर्क 1
TopPageController के लिए पारित :: __ निर्माण() ContainerInterface का एक उदाहरण,
स्लिम \ कंटेनर का उदाहरण दिया
मेरे index.php होना चाहिए
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
require 'settings.php';
spl_autoload_register(function ($classname) {
require ("../classes/" . $classname . ".php");
});
$app = new \Slim\App(["settings" => $config]);
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Welcome");
return $response;
});
$app->get('/method1', '\TopPageController:method1');
$app->run();
?>
मेरा टॉप पेज कंट्रोलर.एफपी
<?php
class TopPageController {
protected $ci;
//Constructor
public function __construct(ContainerInterface $ci) {
$this->ci = $ci;
}
public function method1($request, $response, $args) {
//your code
//to access items in the container... $this->ci->get('');
$response->getBody()->write("Welcome1");
return $response;
}
public function method2($request, $response, $args) {
//your code
//to access items in the container... $this->ci->get('');
$response->getBody()->write("Welcome2");
return $response;
}
public function method3($request, $response, $args) {
//your code
//to access items in the container... $this->ci->get('');
$response->getBody()->write("Welcome3");
return $response;
}
}
?>
धन्यवाद। मैं स्लिम 3 का उपयोग कर रहा हूं।
आपके पास कंटेनर इंटरफेस पर उचित नामस्थान नहीं है। यह 'इंटरऑप \ कंटेनर \ कंटेनरइटरफेस' होना चाहिए – geggleto