duanliaozhi2915 2017-12-09 19:23
浏览 44

Symfony异常,带控制器和树枝模板的数据库查询

I have a controller file and a twig template but the communication is disturbed. The Exception is:

An exception has been thrown during the rendering of a template ("Error producing an iterator").

Either I still miss something in the controller file or something is wrong with the settings.

My Object is "ArticleCategory" Controller:

namespace AppBundle\Controller;
use Pimcore\Controller\Configuration\ResponseHeader;
use Pimcore\Model\Asset;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Pimcore\Model\DataObject\ArticleCategory;
use Zend\Paginator\Paginator;


class ContentController extends FrontendController
{ 
    public function testroot1Action(Request $request)
    {   
        $articleCategory = new ArticleCategory\Listing(); 
        $articleCategory->setOrderKey('date');
        $articleCategory->setOrder('DESC');

        $paginator = new Paginator($articleCategory);
        $paginator->setCurrentPageNumber($request->get('page'));
        $paginator->setItemCountPerPage(5);
        var_dump($paginator);

        $this->view->content = $paginator;

    }
}

The Twig Template. The Exception comes from my for in loop. The iterate of "content" dosent work:

{% extends 'layout.html.twig' %}
{% block content %} 


    {{ dump(content)}}

   {% for contents in content %}

        {{ dump(contents)}}        

    {% endfor %} 

{% block content %} 

Is there somthing more to do or is somthing wrong?

  • 写回答

2条回答 默认 最新

  • dongzhenbi8919 2017-12-09 19:34
    关注

    it should be :

    {% extends 'layout.html.twig' %}
    {% block content %}         
    
       {% for content in contents %}     
    
           // here you have access to a singular content object
    
        {% endfor %} 
    
    {% block content %} 
    
    评论

报告相同问题?