Jump to content

prestashop 1.7 admin module extends FrameworkBundleAdminController


Recommended Posts

hi,i have new module name is "etalimama"

this is my tab code:

$moduleName = $this->name;
TabManager::addTab('AdminTaoBao', 'TaoBao', $moduleName, 'AdminTools');

i have admin controller on etalimama/controllers/admin/AdminTaoBaoController.php

 

<?php

//etalimama/controllers/admin/AdminTaoBaoController.php

namespace EtAliMaMa\Controller\Admin;

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
use Symfony\Component\HttpFoundation\Response;

class AdminTaoBaoController extends FrameworkBundleAdminController
{
    /**
     * @see https://devdocs.prestashop.com/1.7/development/architecture/migration-guide/controller-routing/#security
     * @AdminSecurity(
     *     "is_granted(['read'], request.get('_legacy_controller'))",
     *     message="You do not have permission to access Exemple page."
     * )
     *
     * @return Response
     */
    public function indexAction()
    {
        return $this->render("@Modules/etalimama/views/templates/admin/index.html.twig");
    }
}

then,this is my composer.json on etalimama/composer.json

 

{
  "name": "prestashop/alimama",
  "description": "A module for etalimama",
  "autoload": {
    "psr-4": {
      "EtAliMaMa\\": "controllers/"
    }
  },
  "license": "MIT",
  "type": "prestashop-module"
}

 

routes.yml on config/

etalimama_admin_index:
  path: etalimama
  methods: [GET]
  defaults:
    _controller: 'EtAliMaMa\Controller\Admin\AdminTaoBaoController::indexAction'
    _legacy_controller: 'AdminTaoBao'
    _legacy_link: AdminTaoBao

 

i run command on modules/ and modules/etalimama/ 

composer dumpautoload

when i view admin tab.then say:

 

Class "EtAliMaMa\Controller\Admin\AdminTaoBaoController" does not exist.

 

please tell me why?

 

Link to comment
Share on other sites

Hi

Try in your composer :

"psr-4": {
      "EtAliMaMa\\Controllers": "controllers/"

in routes.yms

_controller: 'EtAliMaMa\Controller\admin\AdminTaoBaoController::indexAction'

and in

//etalimama/controllers/admin/AdminTaoBaoController.php
namespace EtAliMaMa\Controller\admin;
Edited by Payalba (see edit history)
Link to comment
Share on other sites

11 hours ago, Payalba said:

Hi

Try in your composer :


"psr-4": {
      "EtAliMaMa\\Controllers": "controllers/"

in routes.yms


_controller: 'EtAliMaMa\Controller\admin\AdminTaoBaoController::indexAction'

and in


//etalimama/controllers/admin/AdminTaoBaoController.php

namespace EtAliMaMa\Controller\admin;

same error

Link to comment
Share on other sites

  • 5 months later...
On 6/12/2019 at 5:48 AM, langziyang said:

hi,i have new module name is "etalimama"

this is my tab code:


$moduleName = $this->name;
TabManager::addTab('AdminTaoBao', 'TaoBao', $moduleName, 'AdminTools');

i have admin controller on etalimama/controllers/admin/AdminTaoBaoController.php

 


<?php

//etalimama/controllers/admin/AdminTaoBaoController.php

namespace EtAliMaMa\Controller\Admin;

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
use Symfony\Component\HttpFoundation\Response;

class AdminTaoBaoController extends FrameworkBundleAdminController
{
    /**
     * @see https://devdocs.prestashop.com/1.7/development/architecture/migration-guide/controller-routing/#security
     * @AdminSecurity(
     *     "is_granted(['read'], request.get('_legacy_controller'))",
     *     message="You do not have permission to access Exemple page."
     * )
     *
     * @return Response
     */
    public function indexAction()
    {
        return $this->render("@Modules/etalimama/views/templates/admin/index.html.twig");
    }
}

 

 


{
  "name": "prestashop/alimama",
  "description": "A module for etalimama",
  "autoload": {
    "psr-4": {
      "EtAliMaMa\\": "controllers/"
    }
  },
  "license": "MIT",
  "type": "prestashop-module"
}

 

 

Depending on your composer file, you should use the following namespace:

namespace EtAliMaMa\Admin;

also change it on other places

Link to comment
Share on other sites

  • 1 month later...

I am still struggling on my journey to master this new feature. I have got a question and I hope that the community could help me. Do you know to clear the cache with twig in Prestashop?

Prestashop does not take into account the changes I made to my twig templates and to the file routes.yml.

 

Many thanks,

 

Link to comment
Share on other sites

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
×
×
  • Create New...