It has been exciting to take a peek at the Magento 2 code now and then, and to view the changelog as new things are being added or modified. I figured it was about time to get a copy installed and create a module to start to learn the differences.
I have a simple developer toolbar module that I wrote that adds the bar to the top of the page, both in the admin and on the front end, that allows you to toggle logging, template path hints, profiler, cache, flush cache if on, and mark all unread admin notifications as read (if there are any). The module uses no template files at all and is all self-contained, so no matter what your design is, it always works.
The first noticeable difference is the way you call models, helpers, blocks, etc. No more shortcut, xpath-y style of calling things. You need to use the full class name now. Here are a few examples:
// Magento 1.x
// Magento 2
No More app/etc/modules/Your_Module.xml
That’s right, there are no more separate xml files for each module in app/etc/modules. Instead, you simply add the xml tags into the module’s config.xml file. At it’s most simple form, that simply means adding the
codePool tags into your config.xml:
No More Declaration of Module’s Models/Blocks/Helpers
In Magento 1.x, if you wanted to have your own model files for instance, you needed to declare that in your config.xml with code like this:
There is no longer any need for this due to the using of full classnames when calling models for instance. This really simplifies things and helps remove some room for error when writing modules.
Many Events Have Changed
The other difference is that the event that I was observing was no longer an event. I was extremely surprised to find that there was a different event that provided a LOT more flexibility and a LOT more options for doing cool things with it. I initially was frustrated when I found out that my observer wasn’t firing, but was thrilled to find out that Magento only made a way better option. So, as you begin to experiment and port your modules over to Magento 2, be slow to get frustrated. A lot has changed, and so far from my experience, it has been for the better!
I will continue to post more as I experiment with Magento 2.