nette/docs

Creating a Component errors

Opened this issue · 4 comments

URL: https://doc.nette.org/en/application/components

I tried to follow the steps on this page, to make a component. But there's problems.
It said to create a Factory then it says create an Interface. Both have the same name. One could put them into separate directories, files can be created with the same names.
Please explain with a directory structure.

Nette is great and makes a complex task, simple. But I think the documentation is lacking. I mean it probably make perfect sense to a experienced Nette programmers. However people like me that are new-commers cannot piece things properly. After reading and reading many parts of the documentation, I still have problems getting Latte templates correct.

Please provide a simple example.

Hi, I'm new to Nette as well and just recently figured out how to make the component factories work, here it goes:

  • Create a directory called Factories and place your component factory files inside:
    image

  • Next up, use the shorthand mentioned by the docs in the factory instead of instantiating the component yourself:
    image

  • Once done, use the factory in your presenter's createComponent method and pass params if necessary:
    image

  • Finally, add the factory to the DI container using the services.neon file and you'll be good to go:
    image

I do believe the docs are severely lacking and the deeper you get into the framework the harder it becomes for a newbie, I spent 4 hours yesterday trying to work around flashMessages, I'm using a monorepo of multiple nette applications instantiated from a core PHP application and it works like a charm, just not that easy.

I wish they could make the docs more beginner friendly, the framework is awesome.

mabar commented

It said to create a Factory then it says create an Interface. Both have the same name.

Documentation about factories is quite clear. First it shows how to create factory yourself, then it says you can instead just write interface and Nette will implement the class itself.

Directory structure is quite irelevant here - you either place it wherever you want in app directory (in app/Bootstrap.php from nette/web-project is configured robotloader, which will just load them) or follow commonly accepted PSR-4 convention and setup PSR-4 autoloading via Composer.

mabar commented

After reading and reading many parts of the documentation, I still have problems getting Latte templates correct.

Nobody gets everything on the first try. Have you tried asking on https://forum.nette.org?
Documentation may be further improved, but most questions should be asked there