i have custom module. i can't call controller in view of my module. this url call
http://localhost/magento2-2.0.0-rc/index.php/namespace/modulename/product/view/custom/
Code file Custom.php in Namespace/Modulename/Controller
namespace Namespace\Modulename\Controller;
class Custom extends \Magento\Framework\App\Action\Action
{
/**
* Index action
*
* @return $this
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('/');
}
}
This file Custom.php in Namespace/Modulename/Controller/Product/View
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Namespace\Modulename\Controller\Product\View;
class Custom extends \Namespace\Modulename\Controller\Custom
{
protected $resultForwardFactory;
protected $resultPageFactory ;
protected $_coreRegistry;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
\Magento\Framework\Registry $registry
) {
$this->resultForwardFactory = $resultForwardFactory;
$this->resultPageFactory = $resultPageFactory;
$this->_coreRegistry = $registry;
parent::__construct($context);
}
public function execute()
{
$data = $this->getRequest()->getPostValue();
print_r($data); die('xx');
}
}
Edit routes.xml in etc/frontend
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="modulename" frontName="modulename">
<module name="Namespace_Modulename" />
</route>
</router>
</config>