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:
$orm_entity = new \Concrete\Package\MyPackage\Src\Entity\MyEntity();
it sais: Class not found.
The entity is located at
root/packages/my_package/src/Entity/MyEntity.php
and looks like this:
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

daenu
 
daenu replied on at Permalink Reply
daenu
Anyone? Please help!
Mainio replied on at Permalink Reply
Mainio
In which directory have you placed the entity file?
daenu replied on at Permalink Reply
daenu
As I said in my post:
root/packages/my_package/src/Entity/MyEntity.php
Mainio replied on at Permalink Reply
Mainio
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?
daenu replied on at Permalink Reply
daenu
Caches are all off. Installation is fine, DB-tables are installed, but when trying to use the entity the error occurs.
Mainio replied on at Permalink Reply
Mainio
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.
daenu replied on at Permalink Reply 1 Attachment
daenu
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...
Mainio replied on at Permalink Reply
Mainio
Sure, comment out this line from your package controller:

protected $pkgAutoloaderMapCoreExtensions = true;
daenu replied on at Permalink Reply
daenu
Ok fine, this works in the test_package but in my real package the
/var/www/html/c57/packages/my_package/src/Concrete/Help/HelpServiceProvider.php
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
daenu replied on at Permalink Reply 1 Attachment
daenu
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?
Mainio replied on at Permalink Best Answer Reply
Mainio
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.
Mainio replied on at Permalink Reply
Mainio
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...