Laravel Livewire - Best way to use [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I have been interested in Laravel Livewire for a few days. But I wonder what is the best way to use it?
I have a website built on controllers. I would now like to add a forum in Livewire.
Should I build a forum traditionally on controllers, and add livewire components to the view to display categories, topics, messages? Does it miss the point and better to skip traditional controllers?
How to name livewire components?
livewire/forum/index.blade.php
livewire/forum/topics/index.blade.php
//
livewire/showForums.blade.php
livewire/showForumTopics.blade.php
I want to stick to some naming convention because as the project grows I don't want it to look chaotic. I will have many more livewire components in the future.

I'm putting this here as it was too long for a comment.
The point of Livewire is to lower the knowledge requirement for creating interactive interfaces, specifically without having to leave the comfort of Laravel. How you choose to implemenent your project (i.e. the choice between full page compoents and single components) is down to you based on the use case. I wouldn't use a full page component if I only wanted to make a single page element interactive.
In your example, you could use either. However, a full page component might make more sense as you will remove the requirement to fire off events to have other components update themselves.
Try and adhere to existing Laravel naming conventions if possible, but most importantly - be consistent with your naming!
I try to keep my components and views in sync with each other, which is also the recommendation on the Livewire documentation.
app/Http/Livewire/Post/Show.php
resources/views/livewire/post/show.blade.php
Take a look at the building a voting app with Livewire series on Laracasts. It might help with your decision making.

Related

When to go for a library file in codeigniter [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I always use controller files for my project. Sometimes i get confused when to create libraries. Can you please let me know when do we create libraries files and for what purpose?
I can simply define as following:
Controller: This entry point of your application which is associated with URI.
Helper: Helpers are written in procedural format rather than OOP format. Small scale tweaking is handled by this. As the name suggest Helper file helps the main application controllers in some ways.
Library: Libraries are conventionally reusable code which can be used over different projects.
So if you want to write a library that should be reusable and generic. or it will be a waste of time and effort.
When you need to use any code for several portion or projects, you can create library for better understanding and easy access. Suppose, you want to use any user defined captcha generating function, you can create a library and can use it for several projects.
When you are writing some code that is not specific to current project only and it can be reused on other projects then you should create a library.
For example, I have some generic controllers that I use in every project, I put them in libraries and load via __autoload.

Symfony 2 architecture - best practices [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Now, im facing three issues about my symfony 2 application architecture using Doctrine 2. This is a one bundle application.
I will use some controllers of course, but I need some special controller "BeforeController" to be called before the others. In the "BeforeController" I want to place some initialize methods. Is it best practice to extends controllers by "BeforeController"?
I want to create some services in ServiceContainer. For every entity which I have, I want to create own service (e.g. There is Products entity, so I will create Product service, which provides methods manipulating with products and so on), if is it good way. Or is it in Controller compentence?
Can somebody explain me, what is in controller or in service competence?
I should like to create some logical and intuitive architecture. Maybe any class diagram should help me.
Can somebody describe me some best practices about it?
From documentation:
kernel.controller Event, and example: Before filters with the kernel.controller Event,
Service: Service base info and more: What is a Service? Controller base info, and additionally Action. It's nothing wrong with creating separate services for each entity if you really need it.
As above.
I recommended this video from SymfonyCon Warsaw 2013 How Kris Writes Symfony Apps.
Hope this help.

Easy way to locate related files in PHP project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am a core PHP developer and learning MVC Frameworks: CodeIgnitor and Kohona. I downloaded few sample projects to do research on how they work. I am really confused how to determine which Model, which View and which Controller are interrelated to each other.
How can I easily locate which View is for with Controller and vice versa for models, views and controllers.
Also, can anyone tell me what's the major advantage of using these frameworks (Sorry this question to be asked in Google first, I am just looking for short answer) and I feel frameworks uncomfortable cause its hard to locate right file if someone else developed the application.
The right way to find related files in a project is that, you have to read code, for example, if you want to find what view or model is being used in a controller then you should seek in the ode, which model it calls and which view it loads. This is the only way to find related files.
There are lots of advantages to use a framework but one of the most important advantages of using a framework is that, it speeds up development process, writer less do more, it makes your development process faster because it provides you some tools, for example, a Session class for session management, a Validation class for user input validation etc, using these tools you can easily make an application with a very few code and it saves your time so you become more productive.
Another important advantage is that, if you are working in a team and use a framework then each developer knows the code organization of the project because the framework ties everyone to a single set of rules that every developer must follow, everyone follows the same conventions so there is no confusions and any time you may add more developer to work on a project who knows the same framework and can work without any problem.
CodeIgniter and Kohana does not implement MVC (even if they say so...).
A typical flow in php frameworks that call themself MVC are : A url routes to a controller, the controller retrives data from model and passes it the view.
The advantage to using a framework should be that it provides a set of tools for rapidly development, making you focus on the unique code for your application.
The documentation for each framework should be pretty straight forward, you should read it if you going to use a framework...

which one is better for performance : One controller per page or many pages in one controller? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I just wanted some advice regarding the MVC way of doing things. I am using codeigniter and I was wondering if it's better for performance to have one controller per page for a web application or to have one controller for all the pages?
In my opition, you should use one controller for one logical entity.
For example if you are making an online store you would make controllers:
Cart controller with add/delete/update and other methods
User controller with register/login/logout and other methods
Catalog controller with view and blablabla methods
And some other stuff
Conceptually, the MVC asks you to request a single controller. However, in practice, we may need to get information from all over. So the answer to your question comes down to the design of your application.
In codeigniter, you can use the hmvc scheme to break your code structure into models.
You will still request one (main) controller, and that controller will decide to made requests to module controllers for their own processing.
If you are not using a modular approach, then you are 'forced' to use one controller per request, and get additional information for page rendering through model requests or libraries.
I suspect the modular approach will be a bit heavier on performance, because of additional levels of abstraction, multiple times as each controller is loaded.

Why should I use MVC in a php website? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Many frameworks are based on mvc, but I have no idea about MVC. So what is the use of MVC?
Is it for speed, security or any other reason?
MVC allows you to separate your business logic from your presentation layer. This "Separation of Concerns" allows you to quickly find and edit portions of your code. It also enables easy reuse of your UI components across your system.
Check out the wiki page for a overly academic and technical introduction to MVC http://en.wikipedia.org/wiki/Model_view_controller
MVC is mostly for better maintainability of your code. By separating the database logic from the presentational logic from the controller logic you can make changes/rewrites/maintence more easily.
it also solves the problem of "spaghetti code", you can outsorce your HTML/XML/PDF/XSL creation Code to your View/Template engine, get the Data from Your Model(DB/File/RemoteCall,...) and your Controller controls the behaviour of Both, you can also simply exchange the View/Models without even Change the Controller if u implement it right, so you gain Seperation of Concerncs, get better Code & Maintainability and can easily swap components
also its easier to manage if your projects grow. I recommend the Usage of a FrontController which selects the right Controller for you depending on the Users input, you can also use Inversion of Control/DependencyInjection Pattern there and let your Controller be configued by your FrontController / Pass DB Connection and lots of lots of lots more funny stuff
Now u got a simple application framwork:) Use Zend Instead:)

Categories