2

Currently I am running Magento 2 on my local environment and running into problems with development of a custom test module.

I am trying to use dependency injection in one of my controller actions but the interpreter class that seems to be auto-generated in var/generation folder seems to have an older definition of the __construct method of my action class, leading to run time errors. I realize I need to clear the var/generation folder and get on with it. However, is there a way for me to setup my local development environment in such a way that I don't have to do this step every time there is a change to the action class?

Is there any documentation on best practices for local development? Information on the web can get confusing in some cases - like for instance I happened to read somewhere that using static deploy during development isn't best practice, but then I had problems in using a git branch that had setup a new theme. The system wouldn't pick up the new theme however, after static deployment the theme override was working fine.

Is there a list of 5-6 steps that you need to do on the regular while developing locally on M2?

2 Answers 2

1

I'm just gonna give you what Ben Marks listed on twitter in September to optimize M2 development:

  • mode = developer
  • cache on
  • no DI compile
  • opcode on
  • PHP 7
  • xdebug autostart off
3
  • Can you elaborate more on the implications of 'no DI compile' ? While I don't do compile DI, I'd guess I'd still need to clean up the var/generation directory on the go? Thanks!
    – Paras Sood
    Commented Oct 30, 2016 at 22:09
  • @ParasSood yes you're totally right: cleaning up var/generation must be done on the go Commented Oct 30, 2016 at 22:22
  • I'm not entirely sure that generation of controller classes even in Dev mode isn't a bug.
    – benmarks
    Commented Oct 31, 2016 at 0:28
1

You need to clear the different areas of Magento 2's caching system e.g. var/generation or var/cache depending on the processed/updated files and where they are located in caching system but yeah there's no one clear all command that I'm aware of.

In local development environment setting up Grunt is a massive time saver. For instance if you created a new theme and registered it in Grunt theme config file you can simply issue grunt exec <theme name> command and it will process the theme deployment. grunt exec on it's own is alternative to bin/mangento static-content:deploy which can be used in production when grunt is not available.

One of the other very useful grunt command is grunt refresh which clears cache, removes static content and regenerates new static files for you.

2
  • I think I smell a blog post... 😉
    – benmarks
    Commented Oct 31, 2016 at 0:29
  • Won't that be awesome :)
    – Devtype
    Commented Oct 31, 2016 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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