Jump to content

 MappingException error when try use symfony em


alexmixaylov
 Share

Recommended Posts

I am trying to make module with new symfony way. But get MappingException error.  

Quote

The class 'Visix\Repository\CategoryRepository' was not found in the chain configured namespaces PrestaShopBundle\Entity, Visix\Entity 

my module name is "prodconf"

namespase "Visix"

<?php

namespace Visix\Repository;

use Doctrine\DBAL\Connection;

class CategoryRepository
{
    /**
     * @var Connection
     */
    private $connection;

    /**
     * @var string
     */
    private $dbPrefix;

    /**
     * @param Connection $connection
     * @param string $dbPrefix
     */
    public function __construct(Connection $connection, $dbPrefix)
    {
        $this->connection = $connection;
        $this->dbPrefix   = $dbPrefix;
    }

    public function getCategories()
    {
        $qb = $this->connection->createQueryBuilder();
        $qb
            ->addSelect('c.id_category')
            ->addSelect('c.id_parent')
            ->from($this->dbPrefix . 'category', 'c');

        $result = $qb->execute();

        return $result->fetchAll();
    }
}
<?php

namespace Visix\Controllers\Admin;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Visix\Repository\CategoryRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class ScenarioController extends AbstractController
{

    public function getCategories(Request $request)
    {

        $test = $this->getDoctrine()->getRepository(CategoryRepository::class)->getClassName();

        return new JsonResponse($test);
    }
}

and services.yml 

  visix_category_repository:
    class: 'Visix\Repository\ScenarioRepository'
    arguments:
      - '@doctrine.dbal.default_connection'
      - '%database_prefix%'

what I am doing incorrectly?

Share this post


Link to post
Share on other sites

{
  "name": "Alex/prodconf",
  "description": "Product Configurator",
  "authors": [
    {
      "name": "alex",
      "email": "[email protected]"
    }
  ],
  "require": {
    "php": ">=7.1.0"
  },
  "autoload": {
    "psr-4": {
      "Visix\\": "src/"
    },
    "classmap": [
      "prodconf.php",
      "classes/"
    ],
    "exclude-from-classmap": []
  },
  "config": {
    "preferred-install": "dist",
    "prepend-autoloader": false
  }
}

yes I have composer.json in module folder

Share this post


Link to post
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More