Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a Component errors #1039

Open
matt-matt1 opened this issue Jan 26, 2024 · 4 comments
Open

Creating a Component errors #1039

matt-matt1 opened this issue Jan 26, 2024 · 4 comments

Comments

@matt-matt1
Copy link

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.

@thekayshawn
Copy link

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
Copy link
Contributor

mabar commented Jan 26, 2024

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
Copy link
Contributor

mabar commented Jan 26, 2024

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

@matt-matt1
Copy link
Author

matt-matt1 commented Jan 26, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants