Doctrine 2 Entities
Permalink 1 user found helpful
I have defined my entities following this guide:https://www.concrete5.org/documentation/developers/5.7/packages/cust...
The DB-tables are installed, but if try to instatiate a new entity like so:
it sais: Class not found.
The entity is located at and looks like this:
The DB-tables are installed, but if try to instatiate a new entity like so:
$orm_entity = new \Concrete\Package\MyPackage\Src\Entity\MyEntity();
The entity is located at
root/packages/my_package/src/Entity/MyEntity.php
namespace Concrete\Package\MyPackage\Src\Entity; /** * @Entity * @Table(name="btMyEntity") */ class MyEntity { /** * @Id * @Column(type="integer", options={"unsigned":true}) * @GeneratedValue(strategy="AUTO") */ protected $entityID; // ... and so on
Anyone? Please help!
In which directory have you placed the entity file?
As I said in my post:
root/packages/my_package/src/Entity/MyEntity.php
root/packages/my_package/src/Entity/MyEntity.php
Hmm, seems to be right. I just tested with the details above and it works fine.
Do you have any caches enabled on your site?
Are you trying to access this class before (or during) the installation of the package?
Do you have any caches enabled on your site?
Are you trying to access this class before (or during) the installation of the package?
Caches are all off. Installation is fine, DB-tables are installed, but when trying to use the entity the error occurs.
Can you post an example package that you have this issue with?
It doesn't need to contain any relevant project business logic, just the parts that make the issue reproduce.
I tested it with the above details and it worked fine for me.
It doesn't need to contain any relevant project business logic, just the parts that make the issue reproduce.
I tested it with the above details and it worked fine for me.
Yes sure. Here it is. I was hoping that by creating a "simple", "hollow" package would work and so the error would lie in my code... but NO! So hopefully you'll get something. Shortly saying it's still the same: caches are off, installing the package is fine; DB-table is created...
Sure, comment out this line from your package controller:
protected $pkgAutoloaderMapCoreExtensions = true;
Ok fine, this works in the test_package but in my real package the isn't working anymore... same thing "Class not found".
Sometimes programmers live is hard isn't it
Wait I'll attach the Service Provider in the package
/var/www/html/c57/packages/my_package/src/Concrete/Help/HelpServiceProvider.php
Sometimes programmers live is hard isn't it
Wait I'll attach the Service Provider in the package
So here's the package with the HelpProvider. It seems we're getting closer to the problem.
It smell like a bug doesn't it for you?
It smell like a bug doesn't it for you?
If you're using $pkgAutoloaderMapCoreExtensions = true, then the core only registers the /Concrete folder to be autoloaded from your package with the namespace "Concrete\Package\YourPackage".
If you have that as false (or remove the line completely), concrete5 registers the whole /Src folder with to be loaded automatically with the namespace "Concrete\Package\YourPackage\Src".
You cannot mix these two. Or you can if you really want to, you'll need to write a custom autoloader to handle those classes that are not automatically loaded.
I would suggest thinking some other approach for solving the problem.
If you have that as false (or remove the line completely), concrete5 registers the whole /Src folder with to be loaded automatically with the namespace "Concrete\Package\YourPackage\Src".
You cannot mix these two. Or you can if you really want to, you'll need to write a custom autoloader to handle those classes that are not automatically loaded.
I would suggest thinking some other approach for solving the problem.
For any future readers, here's also a more detailed example (than the doc page linked above) on how to use the doctrine entities in a package:
https://github.com/mainio/c5_entities_example...
https://github.com/mainio/c5_entities_example...