Question

Following the convention for value of the action attribute in menu.xml:

[router_name]/[controller_name]/[action_name]

I need to know how to give the value for my action attribute if my controller path is as:

\app\code\Magenshop\Recipe\Controller\Adminhtml\Recipe\Edit.php

<?php
namespace Magenshop\Recipe\Controller\Adminhtml\Recipe;

class Edit extends \Magento\Backend\App\Action
{


protected function _initAction()
{


    $this->loadLayout()
        ->_setActiveMenu('recipe/items')
        ->_addBreadcrumb(__('Items Manager'), __('Item Manager'));

    return $this;
}   

public function indexAction() {
    $this->_initAction()
        ->renderLayout();
}

public function execute()
{

    //$this->_initAction()->renderLayout();
     $this->_view->loadLayout();
     $id     = $this->getRequest()->getParam('id'); 
    $model  = $this->recipeRecipeFactory->create()->load($id); 

            /*Begin custom code */
    //Get the admin recipe approval status 
    $approveStatus=$model->getStatus(); 
    $this->generic->setApproveStatus($approveStatus);
            /*End custom code */
    $hlp = $this->recipeHelper;

    if ($model->getId() || $id == 0) {
        /*Begin custom code */
        //getSingleton('adminhtml/session') changed to getSingleton('admin/session')
        $data = $this->backendAuthSession->getFormData(true);
        /*End custom code */
        if (!empty($data)) {
            $model->setData($data);
        }
        // $model->setFilename($hlp->getUploadHtml($model));
        $this->registry->register('recipe_data', $model);

        $this->loadLayout();
        $this->_setActiveMenu('recipe/items');

        $this->_addBreadcrumb(__('Item Manager'), __('Item Manager'));
        $this->_addBreadcrumb(__('Item News'), __('Item News'));
        $head = $this->getLayout()->getBlock('head');
        $head->setCanLoadExtJs(true);
        $head->setCanLoadTinyMce(true);
        // $head->setCanLoadTinyMce(true);
        $this->_addContent($this->getLayout()->createBlock('recipe/adminhtml_recipe_edit'))
            ->_addLeft($this->getLayout()->createBlock('recipe/adminhtml_recipe_edit_tabs'));

        $this->renderLayout();
    } else {
        $this->backendSession->addError(__('Item does not exist'));
        $this->_redirect('*/*/');
    }
}
     $this->_view->renderLayout();
}



/*public function editAction() {


 }*/

app\code\Magenshop\Recipe\etc\adminhtml\menu.xml

Is my action attribute value right here?

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
    <add id="Magenshop_Recipe::menu" title="Recipes" module="Magenshop_Recipe" sortOrder="71" resource="Magenshop_Recipe::create"/>
    <add id="Magenshop_Recipe::menu_recipe" title="Manage Recipes" module="Magenshop_Recipe" sortOrder="1" parent="Magenshop_Recipe::menu" action="recipe/recipe/edit" resource="Magenshop_Recipe::menu_item"/>

</menu>
</config>
Was it helpful?

Solution

You can specify path in menu.xml like this.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
    <add id="Magenshop_Recipe::menu" title="Recipes" module="Magenshop_Recipe" sortOrder="71" resource="Magenshop_Recipe::create"/>
    <add id="Magenshop_Recipe::menu_item" title="Manage Recipes" module="Magenshop_Recipe" sortOrder="1" parent="Magenshop_Recipe::menu" action="recipe/recipe/edit" resource="Magenshop_Recipe::menu_item"/>  <!--is this right? -->

</menu>
</config>

You need to move this file from here to

app\code\Magenshop\Recipe\Controller\Adminhtml\RecipeController.php

To

app\code\Magenshop\Recipe\Controller\Adminhtml\Recipe\Edit.php

And for another action, you need to create new file like this.

app\code\Magenshop\Recipe\Controller\Adminhtml\Recipe\Upload.php
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top