nette / docs

📖 The Nette documentation
https://nette.org/en/writing
116 stars 283 forks source link

Creating a Component errors #1039

Open matt-matt1 opened 8 months ago

matt-matt1 commented 8 months ago

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 commented 8 months ago

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

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 8 months ago

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 8 months ago

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 commented 8 months ago

Hi Kashan

I followed your steps, making the directories and files you said. I'm glad you also provided images. Again I ran into problems. So created a fresh project and used the same name as yours.

Then I re-read the Nette docs and using your information along side, I was able to get my template to show. So I got over the big first step, now I must try to make it do complex things... But it took much time...

Thanks for your support

On Jan 26, 2024, at 2:17 PM, Kashan Ahmad @.***> wrote:

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.png (view on web) https://github.com/nette/docs/assets/104863696/b60929b5-9150-4766-8406-6cb752868bae Next up, use the shorthand mentioned by the docs in the factory instead of instantiating the component yourself: image.png (view on web) https://github.com/nette/docs/assets/104863696/8b2de0aa-f5bc-47bb-a4b4-2631ac79d0ac Once done, use the factory in your presenter's createComponent method and pass params if necessary: image.png (view on web) https://github.com/nette/docs/assets/104863696/f3de1284-885a-4ae6-9ceb-59fa1895465b Finally, add the factory to the DI container using the services.neon file and you'll be good to go: image.png (view on web) https://github.com/nette/docs/assets/104863696/173033c2-895f-432c-a6f7-9a38e956cb83 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.

— Reply to this email directly, view it on GitHub https://github.com/nette/docs/issues/1039#issuecomment-1912565604, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGGEH5O5EN5LJSJINXPRWTYQP6LPAVCNFSM6AAAAABCLMNCFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGU3DKNRQGQ. You are receiving this because you authored the thread.