-1

I add the controller in my local but it not working.

di.xml

 <?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Controller\Account\CreatePost" type="Tychons\Registration\Controller\Account\CreatePost" />
 </config>

module.xml

    <?xml version="1.0"?>
<!--
/**
 * Module configuration.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Tychons_Registration" setup_version="1.0.0" />
</config>

Createpost.php

    namespace Company\Custom\Controller\Catalog\Product;

class View extends Tychons\Registration\Controller\Account\CreatePost

{
    public function execute()
    {
        echo "create post";exit;

    }
}

composer.json

{
    "name": "tychons/registration",
    "description": "Manage Registartion",
    "type": "magento2-module",
    "version": "1.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Tychons\\Registartion\\": ""
        }
    }
}

registratio.php

<?php
/**
 * Module configuration
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Tychons_Registation',
    __DIR__
);

Please anyone can help me.

closed as too broad by Jai, Manoj Deswal, 7ochem, Dhiren Vasoya, Priyank Apr 27 '18 at 4:51

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • All below answers are working, There's wrong with your code. Find the error and correct it. – Vivek Apr 26 '18 at 9:52
  • You should really take more care when coding: "psr-4": Tychons\\Registartion\\" should be REGISTRATION – tecjam Apr 26 '18 at 10:03
1

You did the mistake at Createpost.php

The over-rewritten class Tychons\Registration\Controller\Account\CreatePost definition is totally wrong.

<?php 
namespace Tychons\Registration\Controller\Account;

class CreatePost extends \Magento\Customer\Controller\Account\CreatePost

{
    public function execute()
    {
        echo "create post";exit;

    }
}
  • Thanks for reply but not working – venkata prasad Apr 26 '18 at 9:28
  • You do clear cache and the do di compile. Need to recompile the class – Amit Bera Apr 26 '18 at 9:30
  • yes, cleared the cache run the di compile and static-content:deploy also run – venkata prasad Apr 26 '18 at 9:32
  • Ensure that you have registration.php and composer.json on your module and also check the module.xml and di files has right stucture – Amit Bera Apr 26 '18 at 9:34
  • Added the composer.json and registration.php file please check. – venkata prasad Apr 26 '18 at 9:37
0

Try this

namespace Tychons\Registration\Controller\Account;

class CreatePost extends \Magento\Customer\Controller\Account\CreatePost

{
    public function execute()
    {
        echo "create post";exit;

    }
}
  • Thanks for reply but not working – venkata prasad Apr 26 '18 at 9:28
0

You did mistake in Createpost.php file, the code should be like this.

namespace Tychons\Registration\Controller\Account;

class CreatePost extends Company\Custom\Controller\Catalog\Product

{
    public function execute()
    {
        echo "create post";exit;
    }
}

Then run below command:

php bin/magento setup:static-content:deploy

If you are using default or developer mode then run this command instead of above command.

php bin/magento setup:static-content:deploy -f

Then run below command to flush cache.

php bin/magento c:f

To get more information about controller override you can click this link: https://webkul.com/blog/overriding-rewriting-classes-magento2/

0

Your Createpost.php contains a class called 'View' not 'Createpost' and your namespace is nothing like what is set in your prefernence in di.xml..

If it should be called CreatePost, your preference should be:

<preference for="Magento\Customer\Controller\Account\CreatePost" type="Tychons\Registration\Controller\Account\CreatePost" />

and your Createpost:

namespace Tychons\Registration\Controller\Account;

class Createpost extends \Magento\Customer\Controller\Account\CreatePost

{
    public function execute()
    {
        echo "create post";exit;

    }
}

edit:

On top of that your psr-4 has spelling mistakes in your composer.json; your module registration.php registers the module under a wrong name;

To put it bluntly, your code it a complete mess.

  • Thanks for reply but not working – venkata prasad Apr 26 '18 at 9:28
  • did you setup:di:compile? – tecjam Apr 26 '18 at 9:32
  • I did the di compile also not working – venkata prasad Apr 26 '18 at 9:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.