2017-10-30 16:39
浏览 119

函数Slim \ Views \ TwigExtension :: __ construct()的参数太少,0通过,预期正好2

I'm trying to generate a link to a delete method using the urlFor helper, and i am using twig extensions to utilize the urlFor method but im getting the error

Too few arguments to function Slim\Views\TwigExtension::__construct(), 0 passed in /Applications/MAMP/htdocs/eli35/src/dependencies.php on line 47 and exactly 2 expected

not sure what to include in the parameters.

Ultimately im trying to click on the delete link to delete a task.

Any suggestions, thanks in advance.

Here is the dependencies.php file.

// DIC configuration

$container = $app->getContainer();

// view renderer
$container['renderer'] = function ($c) {
    $settings = $c->get('settings')['renderer'];
    return new Slim\Views\PhpRenderer($settings['template_path']);

// monolog
$container['logger'] = function ($c) {
    $settings = $c->get('settings')['logger'];
    $logger = new Monolog\Logger($settings['name']);
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level']));
    return $logger;

$container['db'] = function($c){
    $settings = $c->get('settings')['db'];
    $pdo = new PDO("mysql:host=" . $settings['host'] . ";dbname=" . $settings['dbname'] . ";port=" . $settings['port'],
    $settings['user'], $settings['pass']);
    return $pdo;

$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig( 'views', [
        'cache' => false,
    $view->addExtension(new \Slim\Views\TwigExtension(

    $view->parserExtensions = array(
        new \Slim\Views\TwigExtension(),

    return $view;

here is the section of the TodosController.php for my delete method

public function deleteTodo($request, $response, $args)
    $sth = $this->db->prepare("DELETE FROM tasks WHERE id=:id");
    $sth->bindParam("id", $args['id']);
    $todos = $sth->fetchAll();

    return $this->response->withRedirect('/todos');


here is the route link for my delete method, its in the routes file

$app->delete('/todo/[{id}]', '\App\Controllers\TodosController:deleteTodo')->setName("deletetask");

here is todos.twig where im displaying the delete link

{% extends "templates/layout.html" %}

{% block content %}
<h1>My Todos</h1>

  {% for task in todos %}
        <div class="myl">
        <li><h4>{{ task.task}}</h4></li>
        <small style="font-style:italic">{{task.created_at |date("m/d/Y")}}</small></br>

        <a href="{{ urlFor('deletetask', {'id':}) }}">Delete</a>

    {% endfor %}

{% endblock %}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题