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();
- 
 Have you cleared var/generation?Prashant Valanda– Prashant Valanda2016年05月07日 08:06:35 +00:00Commented May 7, 2016 at 8:06
- 
 @PrashantValanda yesKrupali– Krupali2016年05月07日 08:31:31 +00:00Commented May 7, 2016 at 8:31
1 Answer 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();
Explore related questions
See similar questions with these tags.