3

I recently started developing on magento2 and I'm finding a habitual problem always.

When I start creating new extension or something, it's normal I will need M2 objects on my controller's constructor, like:

\Magento\Framework\View\Result\PageFactory
\Magento\Framework\App\Action\Context
...

and a lot more, like "session", "product", "customer" etc, etc.

The problem is how I find all the namespace and how it works, variables and methods, etc? I searched on http://devdocs.magento.com/ and seems they don't provide information about M2 objects or I didn't find it. They just explain how to do this DI and use their objects...

I feel like I'm blind, my only tool is google and always I ended up coming to stack overflow or similar with a guy asking like: How to use session on magento2 (for example)... and then magically someone says to use this:

\Magento\Framework\Session\SessionManagerInterface

$this->sessionManager->setVar('whatever');

ahm... okay this is how I learned to use sessions on Magento... but I'm still so blind... what else can do this object? when I google SessionManager nothing real appears... I only see questions...

So... how you do M2 developers? I only see an alternative navigating through Magento2 core folder for discovering new useful objects or learning about known objects... but it can be a nightmare...

Really, there's not a document with ALL M2 objects, what is their purpose, methods, variables, etc...

1 Answer 1

4

I only see an alternative navigating through Magento2 core folder for discovering new useful objects or learning about known objects

Well that's pretty much it.

What I tend to do is:

  • start developping a module
  • notice that I notice an object
  • find a core feature that is likely to use the same object
  • check how the core code does it and which class it uses
  • reuse the class in my code

Also, it's optional, but I add an extra step :

4
  • But how exacly you do the 3rd and 4th step? There are a LOT of objects working around... Do you just search inside /magento? or /magento/framework? And the other thing is there are a lot of objects that I don't even know they can exist... following the example of sessionManager... I almost did my extension using $_SESSION... how I even know that object exists if no one tells me? I don't know but I feel crazy to learn M2 like this way... When you work with other frameworks, there are so much official documentation that talks about EVERYTHING... why M2 does not?
    – Marc Pont
    Commented Oct 24, 2016 at 14:51
  • @slayerbleast well that's the way I do it and that's the way I did it when I learnt M1 too. Magento can be scary the first time you look into it but the more you practice, the more you'll get use to it and you'll know where to look. For example, each folder under app/code/Magento represents a module. So if you know what you're looking for, you know which module to check etc... Commented Oct 24, 2016 at 14:55
  • yeah well okay I'll trust you
    – Marc Pont
    Commented Oct 24, 2016 at 14:57
  • @slayerbleast again, your question is kind of opinion based. I don't say my answer is the right one I'm not even sure there is a right answer, I just gave you my opinion based on my personal experience Commented Oct 24, 2016 at 14:59

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.