0

I am trying to create a model and collection to add product id to table.

di xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Vendor\Module\Api\Data\QueueInterface" type="Vendor\Module\Model\Queue" />
<!-- <type name="Magento\Framework\Model\AbstractModel">
    <plugin name="my_sync_plugin"
        type="Vendor\Module\Model\Queue"
        sortOrder="1"
        disabled="false"
    />
</type> -->
</config>

Vendor\Module\Model\Queue.php

<?php
namespace Vendor\Module\Model;

class Queue extends \Magento\Framework\Model\AbstractModel
{
public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
    \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
    array $data = []
) {
    parent::__construct(
        $context,
        $registry,
        $resource,
        $resourceCollection,
        $data
    );
}
/**
 * Define resource model
 */
protected function _construct()
{

    /**
    * Define resource model
    */
   $this->_init('Vendor\Module\Model\ResourceModel\Queue');
}
}   

Vendor\Module\Model\ResourceModel\Queue.php

<?php
namespace Vendor\Module\Model\ResourceModel;

class Queue extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
public function __construct(
    \Magento\Framework\Model\ResourceModel\Db\Context $context,
    $connectionName = null
) {
    parent::__construct(
        $context,
        $connectionName
    );
}

protected function _construct()
{
    /**
        * Define main table
        $this->_init('custom_table_name', 'id');  id is the primary key of custom table
    */
    $this->_init('tgs_queue','id');
 }
}

Vendor\Module\Model\ResourceModel\Queue\Collection.php

<?php
namespace Vendor\Module\Model\Mysql4\Queue;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
public function __construct(
    \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
    \Psr\Log\LoggerInterface $logger,
    \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
    \Magento\Framework\Event\ManagerInterface $eventManager,
    \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
    \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
) {
    parent::__construct(
        $entityFactory,
        $logger,
        $fetchStrategy,
        $eventManager,
        $connection,
        $resource
    );
}

public function _construct()
{
    /**
        * Define model & resource model
    */
    $this->_init('Vendor\Module\Model\Queue',
                 'Vendor\Module\Model\ResourceModel\Queue');
}
}

Why do i get :

Warning: array_values() expects parameter 1 to be array, object given in C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Interceptor.php on line 146

UPDATED : Stack trace:

Exception #0 (Exception): Warning: array_values() expects parameter 1 to 
be array, object given in C:\xampp\htdocs\magento2x_2\lib\internal\Magento   \Framework\Interception\Interceptor.php on line 146
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'array_values() ...', 'C:\\xampp\\htdocs...', 146, Array)
#1 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Interceptor.php(146): array_values(Object(Vendor\Module\Model\Queue\Interceptor))
#2 C:\xampp\htdocs\magento2x_2\var\generation\Magento\Customer\Model\Visitor\Interceptor.php(416): Magento\Customer\Model\Visitor\Interceptor->___callPlugins('save', Array, Array)
#3 C:\xampp\htdocs\magento2x_2\app\code\Magento\Customer\Model\Visitor.php(160): Magento\Customer\Model\Visitor\Interceptor->save()
#4 C:\xampp\htdocs\magento2x_2\var\generation\Magento\Customer\Model\Visitor\Interceptor.php(37): Magento\Customer\Model\Visitor->initByRequest(Object(Magento\Framework\Event\Observer))
#5 C:\xampp\htdocs\magento2x_2\app\code\Magento\Customer\Observer\Visitor\InitByRequestObserver.php(24): Magento\Customer\Model\Visitor\Interceptor->initByRequest(Object(Magento\Framework\Event\Observer))
#6 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Event\Invoker\InvokerDefault.php(73): Magento\Customer\Observer\Visitor\InitByRequestObserver->execute(Object(Magento\Framework\Event\Observer))
#7 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Event\Invoker\InvokerDefault.php(61): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Magento\Customer\Observer\Visitor\InitByRequestObserver), Object(Magento\Framework\Event\Observer))
#8 C:\xampp\htdocs\magento2x_2\app\code\Ced\DevTool\Model\Framework\Event\Manager.php(59): Magento\Framework\Event\Invoker\InvokerDefault->dispatch(Array, Object(Magento\Framework\Event\Observer))
#9 C:\xampp\htdocs\magento2x_2\var\generation\Magento\Framework\Event\Manager\Proxy.php(95): Ced\DevTool\Model\Framework\Event\Manager->dispatch('controller_acti...', Array)
#10 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\App\Action\Action.php(91): Magento\Framework\Event\Manager\Proxy->dispatch('controller_acti...', Array)
#11 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Interceptor.php(74): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#12 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Chain\Chain.php(70): Magento\Cms\Controller\Index\Index\Interceptor->___callParent('dispatch', Array)
#13 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Cms\\Con...', 'dispatch', Object(Magento\Cms\Controller\Index\Index\Interceptor), Array, 'customer-app-ac...')
#14 C:\xampp\htdocs\magento2x_2\app\code\Magento\Customer\Model\App\Action\ContextPlugin.php(61): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
 #15 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Chain\Chain.php(67): Magento\Customer\Model\App\Action\ContextPlugin->aroundDispatch(Object(Magento\Cms\Controller\Index\Index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#16 C:\xampp\htdocs\magento2x_2\lib\internal\Magento\Framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Cms\\Con...', 'dispatch', Object(Magento\Cms\Controller\Index\Index\Interceptor), Array, 'contextPlugin')
...
#47 C:\xampp\htdocs\magento2x_2\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#48 {main}
<div class="mirasvit-profiler-clearfix"></div>
<div class="mirasvit-profiler__container">
<div class="mirasvit-profiler__container-toolbar">
    <ul class="mirasvit-profiler__container-tabs" data-role="profiler-tabs">
                </ul>

    <div class="mirasvit-profiler__container-info">
        <div class="mirasvit-profiler__container-info-item">
            <small>::1</small>
        </div>
        <div class="mirasvit-profiler__container-info-item">
            <i class="fa fa-fw fa-clock-o"></i>
            20580.4 ms
        </div>

        <div class="mirasvit-profiler__container-info-item">
            <i class="fa fa-fw fa-database"></i>
            10 in 545.9 ms
        </div>
    </div>
</div>

</div>

<script>
 require([
    'jquery'
], function ($) {
    $('[data-role=profiler-tabs] li').on('click', function (e) {
        $('[data-role=profiler-tabs] li').removeClass('_active');
        $(e.currentTarget).addClass('_active');
        $('[data-tab-content]').hide();
        $('[data-tab-content=' + $(e.currentTarget).attr('data-tab') + ']').show();
    });

    $('[data-role=profiler-tabs] li:first').click();
});

  • Can you post stacktrace? – KAndy Jul 20 '16 at 20:38
  • Could you please help on how to print the stack trace in magento 2 – Sushivam Jul 21 '16 at 5:58
  • configure php settings display_errors = on or uncoment #ini_set('display_errors', 1); on app/bootstarp.php and enable developer mode – KAndy Jul 21 '16 at 6:03
  • Please find the updated answer, i have posted the error stack trace @Kandy – Sushivam Jul 21 '16 at 6:36
  • If i comment the <type name="Magento\Framework\Model\AbstractModel"> in di xml, then the error is gone !!.. but i want to override my Vendor\Module\Model\Queue... @kandy – Sushivam Jul 21 '16 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.