I need to create some functionality that will be used by nearly all my controllers.
So I need to create a custom class. Now do I do this as a Core class? Or as a library? How do these differ?
I use the core class override technique when there's some behavior of one of the core classes that I want to change project wide. A great example of this is using Jamie Rumbelow's model class in /core/MY_Model.
For functionality that will be USED in each controller, I build a library to perform those functions and autoload it, then call the functions from that library as needed.
You want a library is you are developing a class. For simple functions, create a helper. If you are developing functionality that interacts with your database, create a model.
Add your custom helpers and libraries in you application folder.
Related
I've been working a lot with Symfony recently, and I really like the ability to define routes in a routing.yml file. I was looking into Spring's routing system and I couldn't find any options other than placing routes in annotations on controller methods. Is it possible to accomplish something like this in Spring?
My first thought was creating an abstract controller that grabs the routes from a .yml file, but that seemed a bit hacky.
EDIT:
For some added context, I am looking to build a simple Database API with Spring. After some digging it looks like the routing.yml file is best suited for working with server-rendered pages, which is not what I aim to do with my Spring project.
Symfony and Spring are different framework. You are used to one use and want to use same it in another entirely different system. It will not work. You have to adapt to frameworks.
Spring will scan your project and collect your specific annotation like Controller/Component/Configuration/... and configures itself. Therefore, there is no need predefined project structure, unlike, for example, Laravel. So, you can define this structure if you want. Or every class can be in one package, just not beautiful.
Back to routing. You can configure them by the value of annotations only. This is interpreted at compile time. (Ofc, there are runtime annotations, but I focused parameters of annotation.) So, you can not use configuration from the file because it is already runtime. So, you should use constants or hardcode.
Or, you can use an alternative: Annotate the interfaces, then the controllers will be the implementations.
Alternative #2: If you use Spring with Kotlin, In Kotlin, you can have several classes or interfaces in one file.
I have a project I aim to build by laravel framework, but I need to draw the analysis of the project , including the UML diagram, the laravel framework comes with its classes that operates the project (autoloaders and service providers), but my work will be focused on the customizable area of the laravel framework , thus, making a model, middleware, controller, migration.
So how do I clarify in the UML that the shown classes are built on top of laravel framework, by extending laravel classes, without mentioning the whole UML analysis of the framework?
There are two options:
Model the Laravel classes. Only specify the class names, not attributes/operations. Put them in a package called 'Laravel'. Then model your own classes and use generalization relationships to the Laravel classes.
Define a stereotype for each Laravel class you use, e.g. ≪BusServiceProvider≫ and apply these stereotypes to your classes.
I would prefer option 1. I usually show these classes using a special background color.
I have been using for a while but still I am confuse on what to include in my controllers specifically "When should I use Model and When to Use Service"?
I am confused if I am making the right thing.
I would suggest to never use models directly into the controllers.. Adopt the repository-pattern which enables the use of dependency injection of services into the controller.. Use Service Layer to contain the business logic.. In this way all the related codes would be onto similar layer.
Reference for repository pattern:
http://heera.it/laravel-repository-pattern#.VuJcVfl97cs
Please don't use model directly in your controller, unless if you are building a very simple application but for a large application, it would be good to use a repository. Kindly take a look at this tutorial https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/
I'm using alloy on titanium, I want to use modules but I'm worried about breaking the MVC principles.
How can I achieve this?
Thanks.
In our projects we are using Titanium modules as service layer. (If a piece of business logic will be used in more than one controller, we refactor the logic into a module, so logic can be injected in all controllers). I do not see any violations of the original MVC architecture.
What we're trying to achieve in our projects is close to MVCS architecture (more info here)
can anyone help me with converting my project to use PetaPoco?
here is my issue. backend is SQL 2010 database .NET fraimework 4.0
I have an existing 3-tier win app in C# that uses a custom DAL -- each Data call uses stored procs with parameters and either returns dataset or specific value as needed -- each call accepts dataset referenced parameter and baseClass parameter (base class is identical to DB table schema well mostly)
I want to replace my custom DAL with PetaPoco but keep the 3-tier layout
the app is relying on predefined base classes as DTO to pass info between UI-BAL-DAL
does anyone have a sample/example of app solution layout as to how to use PetaPoco in 3-tier enviroment code example would be very helpfull
thanks in advance...
Vlad
Example not really needed
All you have to do is get acquainted with PetaPoco library. The best way is its documentation. It's not a complicated/complex library, so you should get up to speed with it quite quickly.
If you also have you application broken down into projects for each layer (UI, BL, DAL), then the easiest thing to do is to create a new DAL project and implement all used functionality of existing DAL but use PetaPoco in this one. Then just change your project references and voila. That's it. You can keep your POCOs/DAO. If you've used IoC then it will be even easier because instantiating DAL repositories (or whatever you're using) is probably done via some DI container.
Layering and PetaPoco
PetaPoco has nothing to do with application layering. If you use it in 3-tier applicatin that's fine.
What are you using now?
You didn't mention which DAL library (if any) you're using right now. If you don't, then using PetaPoco will result in less lines of code and much simplified object mapping.