I am working through some tutorials and have become stuck.
My setup so far is as follows:
folder structure
app
code
local
Eav
Complex
Block
controllers
IndexController.php
etc
config.xml
Helper
Model
Resource
Complexpost.php
Setup.php
Complexpost.php
sql
complex_setup
install-0.1.0.php
app/etc/modules/Eav_Complex.xml
<config>
<modules>
<Eav_Complex>
<active>true</active>
<codePool>local</codePool>
</Eav_Complex>
</modules>
</config>
IndexController.php
<?php
class Eav_Complex_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$complex = Mage::getModel("complex/complexpost");
var_dump($complex);
}
}
config.xml
<config>
<modules>
<Eav_Complex>
<version>0.1.0</version>
</Eav_Complex>
</modules>
<frontend>
<routers>
<complex>
<use>standard</use>
<args>
<module>Eav_Complex</module>
<frontName>complex</frontName>
</args>
</complex>
</routers>
</frontend>
<global>
<models>
<complex>
<class>Eav_Complex_Model</class>
<resourceModel>complex_resource</resourceModel>
</complex>
<complex_resource>
<class>Eav_Complex_Model_Resource</class>
<entities>
<complexpost>
<table>complex_post</table>
</complexpost>
</entities>
</complex_resource>
</models>
</global>
</config>
All the above files are correct – I have already asked a question earlier about them., so up until here I know everything is in order.
I'm fairly certain that the following files are also in order, and that the problem lies elsewhere, but just to be safe I am posting them here as well.
Model/Complexpost.php
<?php
class Eav_Complex_Model_Complexpost extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init("complex/complexpost");
}
}
Model/Resource/Complexpost.php
<?php
class Eav_Complex_Model_Resource_Complexpost extends Mage_Eav_Model_Entity_Abstract
{
protected function _construct()
{
$resource = Mage::getSingleton('core/resource');
$this->setType("complex_complexpost");
$this->getConnection(
$this->setConnection("complex_read"),
$this->setConenctION("complex_write")
);
}
}
Model/Resource/Setup.php
<?php
class Eav_Complex_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
}
install-0.1.0.php
<?php
$installer = $this;
throw new Exception("Stopping installer from completing");
When I hit the URL http://127.0.0.1/magento1/complex
(I have confirmed that the URL is correct), I receive this error message: Invalid entity_type specified: complex_complexpost
– This seems to complain that the resource type in Model/Resource/Complexpost.php
is incorrect.
I have not set up anything in the database either via phpAdmin or via installer – could that potentially be the problem?
I am expecting an exception at this point, but the one I am expecting is the one that I thrown manually in install-0.1.0.php
, not the one I'm getting.
If you can see anything obviously out of place, I'd be very grateful if you could point it out, and even more so if you could explain what my mistake was (I am still learning Magento and understanding my mistake would be super helpful!)
Best Answer
If you are trying to create an EAV entity, you need a record for that entity in the
eav_entity_type
table.This needs to be inserted when the module is installed.
For this you need to make your
install-0.1.0.php
look like this:your
config.xml
should contain this under theglobal
tagand your class
Eav_Complex_Model_Resource_Setup
should contain this method:I hope I've closed all the brackets and parentheses.
You will end up with a bunch of new errors after this because you have a log of files still missing, but it should solve your entity type problem.
For a full description on how to create an eav entity, check this question: How to create an EAV entity?