首页>Magento>source

我在这个模块之后做了一个简单的CRUD自定义模块

C:\xampp\htdocs\magento\vendor\magento\module-cms\Controller\Adminhtml\Page\Save.php

,点击 我有一个 save/create/add的控制器   "学生"到数据库。 点击 但这里缺少一些东西
所以控制器只能去 __construct()   功能 但是 execute()   功能不起作用 点击 你看,当我 var_dump('111');   在 __construct()   功能,它工作正常
但是当我 var_dump('111');   在 execute()   功能,什么也没发生。 结果

<br>
Here is my controller:
<br>
    <?php
    /**
     * Created by PhpStorm.
     * User: Administrator
     * Date: 18/07/2018
     * Time: 1:30 CH
     */
    namespace Fudu\HelloWorld\Controller\Adminhtml\Student;
    use Magento\Framework\Registry;
    use Magento\Framework\View\Result\PageFactory;
    use Magento\Backend\App\Action\Context;
    use Fudu\HelloWorld\Model\StudentsFactory;
    use Fudu\HelloWorld\Model\ResourceModel\Students as ResourceModel;
    class Create extends \Magento\Backend\App\Action
    {
        /**
         * @var StudentsFactory
         */
        protected $studentsFactory;
    /**
     * @var ResourceModel
     */
    protected $resourceModel;
    public function __construct(
        Context $context,
        Registry $coreRegistry,
        PageFactory $resultPageFactory,
        StudentsFactory $studentsFactory,
        ResourceModel $resourceModel
    ) {
        $this->resourceModel = $resourceModel;
        $this->studentsFactory = $studentsFactory;
        parent::__construct($context);
    }
    /**
     * Save action
     *
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $data = $this->getRequest()->getPostValue();
        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
    //
            if ($data) {
                try{
                    /** @var \Fudu\HelloWorld\Model\Students $model */
                $model = $this->studentsFactory->create();
                $model->setData($data);
                $this->resourceModel->save($model);
                $this->messageManager->addSuccessMessage(__('Create Student Successfully.'));
                // Redirect to your form page (or anywhere you want...)
                $resultRedirect->setPath('/companymodule/index/booking');
                return $resultRedirect;
            }
            catch (\Exception $e) {
                $this->messageManager->addErrorMessage($e->getMessage());
            }
        }
    }
    }
<br>
system.log : <br>
    C:\xampp\htdocs\magento\var\log\system.log
<br>
    [2018-07-19 15:44:29] main.INFO: Item Magento_Backend::system_currency was removed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_design_schedule was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_store was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::dashboard was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_tools was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_design was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_convert was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_cache was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::marketing was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::marketing_communications was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::marketing_seo was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::marketing_user_content was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::content was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::content_elements was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::stores was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::stores_settings was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::stores_attributes was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::other_settings was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::system_other_settings was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backend::setup_wizard was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Fudu_HelloWorld::main_menu was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Fudu_HelloWorld::add_students was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Fudu_HelloWorld::manage_students was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Fudu_HelloWorld::configuration was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Theme::design_config was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Theme::system_design_theme was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Customer::customer was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Customer::customer_manage was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Customer::customer_online was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Customer::customer_group was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_AdminNotification::system_adminnotification was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Indexer::system_index was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Config::system_config was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Cms::cms_page was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Cms::cms_block was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Backup::system_tools_backup was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Catalog::catalog was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Catalog::catalog_products was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Catalog::catalog_categories was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Catalog::catalog_attributes_attributes was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Catalog::catalog_attributes_sets was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Catalog::inventory was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Search::search_terms was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Search::search_synonyms was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_UrlRewrite::urlrewrite was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales_operation was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales_order was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales_invoice was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales_shipment was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales_creditmemo was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::sales_transactions was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sales::system_order_statuses was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Widget::cms_widget_instance was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_CheckoutAgreements::sales_checkoutagreement was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Downloadable::report_products_downloads was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_User::system_acl was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_User::system_acl_users was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_User::system_acl_roles was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_User::system_acl_locks was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Tax::sales_tax was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Tax::sales_tax_rules was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Tax::sales_tax_rates was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Email::template was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_CurrencySymbol::system_currency was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_CurrencySymbol::system_currency_rates was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_CurrencySymbol::system_currency_symbols was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Paypal::report_salesroot_paypal_settlement_reports was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Paypal::paypal_billing_agreement was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Integration::system_extensions was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Integration::system_integrations was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Amazon_Core::logs was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Amazon_Core::client_logs was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Amazon_Core::ipn_logs was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_CatalogRule::promo was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_CatalogRule::promo_catalog was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_ImportExport::system_convert_import was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_ImportExport::system_convert_export was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_ImportExport::system_convert_history was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Newsletter::newsletter_template was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Newsletter::newsletter_queue was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Newsletter::newsletter_subscriber was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Newsletter::newsletter_problem was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_EncryptionKey::system_crypt_key was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Braintree::settlement_report was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Analytics::business_intelligence was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Analytics::advanced_reporting was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Analytics::bi_essentials was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Marketplace::partners was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_SalesRule::promo_quote was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_marketing was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot_sales was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot_tax was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot_invoiced was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot_shipping was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot_refunded was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_salesroot_coupons was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_shopcart_product was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_shopcart_abandoned was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_products was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_products_bestsellers was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_products_sold was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_products_viewed was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_products_lowstock was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_customers was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_customers_accounts was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_customers_totals was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_customers_orders was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_statistics was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Reports::report_statistics_refresh was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Search::report_search_term was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Review::catalog_reviews_ratings_ratings was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Review::catalog_reviews_ratings_reviews_all was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Review::report_review was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Review::report_review_customer was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Review::report_review_product was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Sitemap::catalog_sitemap was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_TaxImportExport::system_convert_tax was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Magento_Variable::system_variable was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::marketing_automation was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::automation_studio was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::exclusion_rules was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::marketing_automation_report was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::importer was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::automation was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::campaign was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::cron was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::dashboards was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::logviewer was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Dotdigitalgroup_Email::abandoned was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Shopial_Facebook::marketing_social was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Shopial_Facebook::shopial_facebook was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Temando_Shipping::shipping was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Temando_Shipping::carriers was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Temando_Shipping::locations was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Temando_Shipping::packaging was processed [] []
    [2018-07-19 15:44:29] main.INFO: Add of item with id Temando_Shipping::dispatches was processed [] []
最新回答
  • 2019-12-5
    1 #

    让你的控制器扩展 \Magento\Framework\App\Action\Action    而不是 \Magento\Backend\App\Action ,这应该可以解决你的问题。

  • 2019-12-5
    2 #

    试试这个代码:

    <?php
    namespace Fudu\HelloWorld\Controller\Adminhtml\Student;
    class Create extends \Magento\Backend\App\Action
    {
        public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory
        ) {
            parent::__construct($context);
            $this->resultPageFactory = $resultPageFactory;
        }
        public function execute()
        {
            echo "controller call successfully";
            exit;
        }
    }
    

  • 2019-12-5
    3 #

    您无法为此控制器授予新管理员用户权限,因为当您扩展 Magento\Framework\App\Action\Action时   这意味着通过Magento访问控制列表.

    请重新检查这些问题:

      acl.xml   文件

      确保你有 _isAllowed   在您的控制器中运行并返回 _authorization->isAllowed   在 acl.xml中使用资源ID   文件。

      尝试注销并重新登录管理员用户。

      Ex Admin Controller.

      Class [Action Name] extends \Magento\Backend\App\Action
      {
      
          /**
           * {@inheritdoc}
           */
          protected function _isAllowed()
          {
              return $this->_authorization->isAllowed('[resource id in **acl.xml**]');
          }
      }
      

  • magento 1.7:添加+5天到getOrderDate()
  • magento 1.9:管理员邮件未收到新订单通知邮件