2016-01-25 37 views
1

當我試圖從這樣一個數據庫,讓我的帖子:Magento的2框架錯誤,當我把我的帖子

public function getPosts() 
    { 
     if(!$this->hasData('posts')) 
     { 
      $posts = $this->_postCollectionFactory 
        ->create(); 
      $this->setData('posts', $posts); 
     } 

     return $this->getData('posts'); 
    } 

Magento的給我這個錯誤:

(!) Fatal error: Call to a member function dispatch() on null in /var/www/myproject/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php on line 531

這裏我的崗位模型:

<?php 
    namespace Ilio\Press\Model; 

    use Ilio\Press\Api\Data\PostInterface; 
    use Magento\Framework\DataObject\IdentityInterface; 
    use Magento\Framework\Model\AbstractModel; 

    class Post extends AbstractModel implements IdentityInterface, PostInterface 
    { 
     protected $_cacheTag = 'press_post'; 
     protected $_eventPrefix = 'press_post'; 

     // IdentityInterface 

     public function getIdentities() 
     { 
      return ['press_post_' . $this->getId()]; 
     } 

     // PostInterface 

     public function getId() 
     { 
      return $this->getData(self::POST_ID); 
     } 

     public function getUrl() 
     { 
      return $this->getData(self::URL); 
     } 

     public function getTitle() 
     { 
      return $this->getData(self::TITLE); 
     } 

     public function getCover() 
     { 
      return $this->getData(self::COVER); 
     } 

     public function getContent() 
     { 
      return $this->getData(self::CONTENT); 
     } 

     public function getCreated() 
     { 
      return $this->getData(self::CREATED); 
     } 

     public function getModified() 
     { 
      return $this->getData(self::MODIFIED); 
     } 

     public function setId($id) 
     { 
      return $this->setData(self::POST_ID, $id); 
     } 

     public function setUrl($url) 
     { 
      return $this->setData(self::URL, $url); 
     } 

     public function setTitle($title) 
     { 
      return $this->setData(self::TITLE, $title); 
     } 

     public function setCover($cover) 
     { 
      return $this->setData(self::COVER, $cover); 
     } 

     public function setContent($content) 
     { 
      return $this->setData(self::CONTENT, $content); 
     } 

     public function setCreated($created) 
     { 
      return $this->setData(self::CREATED, $created); 
     } 

     public function setModified($modified) 
     { 
      return $this->setData(self::MODIFIED, $modified); 
     } 
    } 

,在這裏我的收藏:

<?php 
    namespace Ilio\Press\Model\ResourceModel; 

    use Magento\Framework\Model\ResourceModel\Db\AbstractDb; 
    use Magento\Framework\Model\ResourceModel\Db\Context; 
    use Magento\Framework\Stdlib\DateTime\DateTime; 
    use Magento\Framework\Model\AbstractModel; 

    class Post extends AbstractDb 
    { 
     protected $_date; 

     public function __construct(Context $context, DateTime $date, $prefix = null) 
     { 
      parent::__construct($context, $prefix); 
      $this->_date = $date; 
     } 

     public function _construct() 
     { 
      $this->_init('ilio_press_post', 'id'); 
     } 

     public function load(\Magento\Framework\Model\AbstractModel $object, $value, $field = null) 
     { 
      return parent::load($object, $value, $field); 
     } 

     protected function _beforeSave(AbstractModel $object) 
     { 
      if($object->isObjectNew() && !$object->hasCreationTime()) 
       $object->setCreationTime($this->_date->gmtDate()); 

      $object->setUpdateTime($this->_date->gmtDate()); 
      return parent::_beforeSave($object); 
     } 
    } 

這裏是我完整的堆棧:

(!) Fatal error: Call to a member function dispatch() on null in /var/www/fdsffds/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php on line 531 
Call Stack 
# Time Memory Function Location 
1 0.0003 243464 {main}() .../index.php:0 
2 0.6459 4132016 Magento\Framework\App\Bootstrap->run() .../index.php:39 
3 0.6495 4167192 Magento\Framework\App\Http->launch() .../Bootstrap.php:258 
4 2.7653 16419816 Magento\Framework\View\Result\Page\Interceptor->renderResult() .../Http.php:119 
5 2.7653 16420344 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() .../Interceptor.php:130 
6 2.7654 16428984 call_user_func_array:{/var/www/fdsfdsfdsf/vendor/magento/framework/Interception/Interceptor.php:141} () .../Interceptor.php:141 
7 2.7654 16429400 Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult() .../Interceptor.php:141 
8 2.7654 16429440 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() .../BuiltinPlugin.php:67 
9 2.7654 16429744 Magento\Framework\Interception\Chain\Chain->invokeNext() .../Interceptor.php:136 
10 2.7656 16439136 call_user_func_array:{/var/www/fdsfdsfds/vendor/magento/framework/Interception/Chain/Chain.php:68} () .../Chain.php:68 
11 2.7656 16439384 Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult() .../Chain.php:68 
12 2.7656 16439424 Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}() .../VarnishPlugin.php:74 
13 2.7656 16439728 Magento\Framework\Interception\Chain\Chain->invokeNext() .../Chain.php:63 
14 2.7657 16439936 Magento\Framework\View\Result\Page\Interceptor->___callParent() .../Chain.php:70 
15 2.7657 16440424 call_user_func_array:{/var/www/fdsfdsfds/vendor/magento/framework/Interception/Interceptor.php:74} () .../Interceptor.php:74 
16 2.7657 16440912 Magento\Framework\View\Result\Layout->renderResult() .../Interceptor.php:74 
17 2.7657 16441496 Magento\Framework\View\Result\Page->render() .../Layout.php:162 
18 8.6429 20093064 Magento\Framework\View\Layout\Interceptor->getOutput() .../Page.php:241 
19 8.6429 20093248 Magento\Framework\View\Layout\Interceptor->___callPlugins() .../Interceptor.php:494 
20 8.6429 20093864 call_user_func_array:{/var/www/fdsfdsfds/vendor/magento/framework/Interception/Interceptor.php:144} () .../Interceptor.php:144 
21 8.6429 20094096 Magento\Framework\View\Layout->getOutput() .../Interceptor.php:144 
22 8.7088 20158240 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:938 
23 8.7088 20158336 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
24 8.7088 20158336 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
25 8.7088 20158384 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
26 8.7088 20158432 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
27 8.7088 20158872 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
28 8.7088 20158968 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
29 8.7088 20158968 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
30 8.7088 20159016 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
31 8.7089 20159064 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
32 8.7089 20159496 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
33 8.7089 20159592 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
34 8.7089 20159592 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
35 8.7089 20159640 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
36 8.7090 20159688 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
37 9.1222 22644824 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
38 9.1222 22644920 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
39 9.1222 22644920 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
40 9.1222 22644968 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
41 9.1223 22645016 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
42 9.1274 22647056 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
43 9.1274 22647152 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
44 9.1274 22647152 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
45 9.1274 22647200 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
46 9.1274 22647248 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
47 9.1275 22647848 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
48 9.1275 22647944 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
49 9.1275 22647944 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
50 9.1275 22647992 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
51 9.1275 22648040 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
52 9.1275 22648472 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
53 9.1275 22648568 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
54 9.1275 22648568 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
55 9.1275 22648616 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
56 9.1275 22648664 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
57 9.1466 22663688 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
58 9.1466 22663784 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
59 9.1466 22663784 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
60 9.1467 22663832 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
61 9.1467 22663880 Magento\Framework\View\Layout->_renderContainer() .../Layout.php:520 
62 9.1676 22688600 Magento\Framework\View\Layout\Interceptor->renderElement() .../Layout.php:569 
63 9.1676 22688696 Magento\Framework\View\Layout->renderElement() .../Interceptor.php:193 
64 9.1676 22688696 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() .../Layout.php:472 
65 9.1676 22688744 Magento\Framework\View\Layout->renderNonCachedElement() .../Interceptor.php:206 
66 9.1676 22688792 Magento\Framework\View\Layout->_renderBlock() .../Layout.php:518 
67 9.1676 22689072 Magento\Framework\View\Element\AbstractBlock->toHtml() .../Layout.php:542 
68 9.1677 22689776 Magento\Framework\View\Element\Template->_toHtml() .../AbstractBlock.php:652 
69 9.1689 22690448 Magento\Framework\View\Element\Template->fetchView() .../Template.php:279 
70 9.1695 22691032 Magento\Framework\View\TemplateEngine\Php->render() .../Template.php:255 
71 9.1714 22708568 include('/var/www/fdsfdsfds/app/code/Ilio/Press/view/frontend/templates/list.phtml') .../Php.php:59 
72 9.1802 22812056 Magento\Framework\Data\Collection->getIterator() .../Php.php:1 
73 9.1802 22812104 Magento\Framework\Data\Collection\AbstractDb->load() .../Collection.php:820 
74 9.1802 22812496 Magento\Framework\Data\Collection\AbstractDb->loadWithFilter() .../AbstractDb.php:550 
75 9.1802 22812608 Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection->_beforeLoad() .../AbstractDb.php:562 

這裏是$帖子的var_dump:

object(Ilio\Press\Model\ResourceModel\Post\Collection)[871] 
    public '_idFieldName' => string 'id' (length=2) 
    protected '_model' => string 'Ilio\Press\Model\Post' (length=21) 
    protected '_resourceModel' => string 'Ilio\Press\Model\ResourceModel\Post' (length=35) 
    protected '_resource' => null 
    protected '_fieldsToSelect' => null 
    protected '_initialFieldsToSelect' => null 
    protected '_fieldsToSelectChanged' => boolean false 
    protected '_joinedTables' => 
    array (size=0) 
     empty 
    protected '_mainTable' => null 
    protected '_resetItemsDataChanged' => boolean false 
    protected '_eventPrefix' => string '' (length=0) 
    protected '_eventObject' => string '' (length=0) 
    protected '_eventManager' => null 
    protected '_conn' => null 
    protected '_select' => null 
    protected '_bindParams' => 
    array (size=0) 
     empty 
    protected '_data' => null 
    protected '_map' => null 
    protected '_fetchStmt' => null 
    protected '_isOrdersRendered' => boolean false 
    protected '_logger' => null 
    private '_fetchStrategy' (Magento\Framework\Data\Collection\AbstractDb) => null 
    protected 'extensionAttributesJoinProcessor' => null 
    protected '_items' => 
    array (size=0) 
     empty 
    protected '_itemObjectClass' => string 'Ilio\Press\Model\Post' (length=21) 
    protected '_orders' => 
    array (size=0) 
     empty 
    protected '_filters' => 
    array (size=0) 
     empty 
    protected '_isFiltersRendered' => boolean false 
    protected '_curPage' => int 1 
    protected '_pageSize' => boolean false 
    protected '_totalRecords' => null 
    protected '_isCollectionLoaded' => null 
    protected '_flags' => 
    array (size=0) 
     empty 
    protected '_entityFactory' => null 
+0

您可以顯示所有堆棧跟蹤? – Naumov

+0

檢查變量$發佈var_dump()請或xdebug – Naumov

+0

感謝您的回覆,回答編輯再次 –

回答

0

嘗試更換class Post extends AbstractDbclass Post extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb。因爲你擴展了Magento\Framework\Data\Collection\AbstractDb.php的類。附:對不起,我的英語

+0

答案是對的! –

相關問題