langziyang Posted June 12, 2019 Share Posted June 12, 2019 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 More sharing options...
Payalba Posted June 14, 2019 Share Posted June 14, 2019 (edited) 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 June 14, 2019 by Payalba (see edit history) Link to comment Share on other sites More sharing options...
langziyang Posted June 15, 2019 Author Share Posted June 15, 2019 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 More sharing options...
Payalba Posted June 15, 2019 Share Posted June 15, 2019 Hi, Can you share the complete code of your module ? Regards, PYT Link to comment Share on other sites More sharing options...
langziyang Posted June 15, 2019 Author Share Posted June 15, 2019 7 minutes ago, Payalba said: Hi, Can you share the complete code of your module ? Regards, PYT etalimama.zip Link to comment Share on other sites More sharing options...
Payalba Posted June 15, 2019 Share Posted June 15, 2019 Thanks. I will rework your code. It's not the good way to build admin controllers. Regards, PYT Link to comment Share on other sites More sharing options...
Payalba Posted June 15, 2019 Share Posted June 15, 2019 Hi, Try this. I will continue to rework your module next week. Don't forget to update the autoload each time you modify the composer.json (composer dumpautolaod) Regards, PYT etalimama.zip 1 Link to comment Share on other sites More sharing options...
Mahdi Shad Posted December 15, 2019 Share Posted December 15, 2019 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 More sharing options...
pedepot Posted January 25, 2020 Share Posted January 25, 2020 Add require_once(__DIR__ . '/vendor/autoload.php'); require_once(__DIR__ . '/vendor/autoload.php'); to your module.php file right before the class definition. Link to comment Share on other sites More sharing options...
Rhobur Posted January 25, 2020 Share Posted January 25, 2020 (edited) I see you are trying the new Symfony way so your controller should live in src/Controllers/Admin/ and in composer.json add: "autoload": { "psr-4": { "your_module_name\\": "src/" } And of course, run composer dumpautoload afterwards. Edited January 25, 2020 by Rhobur (see edit history) Link to comment Share on other sites More sharing options...
pedepot Posted January 26, 2020 Share Posted January 26, 2020 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 More sharing options...
langziyang Posted January 29, 2020 Author Share Posted January 29, 2020 On 6/15/2019 at 11:09 PM, Payalba said: Hi, Try this. I will continue to rework your module next week. Don't forget to update the autoload each time you modify the composer.json (composer dumpautolaod) Regards, PYT etalimama.zip working fine Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now