0

I have my custom table and created respective models related to that. My issue is : When I try to get collection or set data into that table that time I am getting an error

Model collection resource name is not defined.

Please have a look in my files : Table name : custom_test_customertest

Namespace/Modulename/Model/Test/Customertest.php

namespace Namespace\Modulename\Model\Test;
use Magento\Framework\Model\AbstractModel;
class Customertest extends AbstractModel
{
 protected function _construct()
 {
 $this->_init('Namespace\Modulename\Model\ResourceModel\Test\Customertest');
 }
}

Namespace/Modulename/Model/ResourceModel/Test/Customertest.php

namespace Namespace\Modulename\Model\ResourceModel\Test;
class Customertest extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{ 
 protected function _construct()
 {
 $this->_init('custom_test_customertest', 'id');
 }
}

Namespace/Modulename/Model/ResourceModel/Test/Customertest/Collection.php

namespace Namespace\Modulename\Model\ResourceModel\Test\Customertest;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
 protected function _construct()
 {
 $this->_init(
'Namespace\Modulename\Model\Test\Customertest','Namespace\Modulename\Model\ResourceModel\Test\Customertest'
 );
 } 
}

When I try to collect collection from phtml or anywhere I am getting issue:

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $objectManager->get('\Namespace\Modulename\Mode\Test\Customertest')->getCollection();
asked May 7, 2016 at 7:27
2
  • Have you cleared var/generation? Commented May 7, 2016 at 8:06
  • @PrashantValanda yes Commented May 7, 2016 at 8:31

1 Answer 1

1

You have simple typo error Mode to Model

 $objectManager->get('\Namespace\Modulename\Mode\Test\Customertest')->getCollection();

Chnage to:

 $objectManager->get('\Namespace\Modulename\Model\Test\Customertest')->getCollection();
answered May 7, 2016 at 8:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.