我试图在Slim中使用控制器但是不断收到错误
PHP Catchable致命错误:传递给
TopPageController :: __ construct()的参数1 必须是ContainerInterface的一个
实例,Slim\Container的实例给出
我的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();
?>
Run Code Online (Sandbox Code Playgroud)
我的TopPageController.php
<?php
class TopPageController {
protected $ci;
//Constructor
public function __construct(ContainerInterface $ci) {
$this->ci = $ci;
}
public function method1($request, $response, $args) {
//your code
//to …Run Code Online (Sandbox Code Playgroud) 我需要将qt 5.5版与mxe一起使用,但找不到任何选项。我只看到qt是4.8.7,qt5是5.8,我仅限于两个版本之一,还是可以使用5.5。
谢谢
我试图从SLIM控制器显示动态生成的图像,但我得到一个空白屏幕.谢谢.
public function textToImage($request, $response, $args) {
// The text to draw
$text = "Hello World";
$length=strlen($text);
// Create the image
$im = imagecreatetruecolor($length*12, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 44, 62, 80);
$boxcolor=imagecolorallocate($im, 95, 128, 149);
$font = 'Helvetica.ttf';
imagefilledrectangle($im, 0, 0, $length*9+$capitaladjust, 29, $white);
imagettftext($im, 13, 0, 0, 20, $black, $font, $text);
$response->getBody()->write(base64_encode($im));
$response = $response->withHeader('Content-type', 'image/png');
return $response;
}
Run Code Online (Sandbox Code Playgroud)