In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the advantages of Sight components". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What did Sight do?
Sight implements a Presenter layer in Server Side. This allows you to easily convert the data found from the server into displayable data. Since the advent of Sight,Laravel, it has become the only framework that supports Server Side's MVP schema.
Why use Sight?
First, speed up the speed of development.
Second, domestic Phper understands that large factories prohibit SQL from joining more than three tables.
If you encounter a beginner, you will query the database in the FOR loop. If you ban it, it's also possible that they send out the relevant ID PLUCK. Find out the results, and then nest the FOR loop in the FOR loop to look up the relevant associated data.
Sight provides a good Pluck function. After finding the ID, the request for the relevant data to Sight,Sight will stitch the data for you. What it does is to organize the data for KEY by associating ID. As a result, the program efficiency is greatly improved.
Third, the use of Sight is quite simple.
For example, the following example is almost similar to the use of Model.
Namespace App\ Presenteruse Bardoqi\ Sight\ Presenter;use Bardoqi\ Sight\ Traits\ PresenterTrait;use Bardoqi\ Sight\ MappingTypeEnum use Bardoqi\ Sight\ Enums\ PaginateTypeEnum use App\ Repositories\ ArticleRepository;use App\ Repositories\ UserRepository; class ArticlePresenter extents Presenter {use PresenterTrait; public function getArticleList ($where) {$articleArray = ArticleRepository::getList ($where) $user_ids = $this- > selectFields ('id','title','created_at','created_by')-> fromLocal ($articleArray,'articles')-> pluck (' created_by'); $users = UserRepository::getUsersWithIds ($user_ids) $this- > innerJoinForeign ($users 'userss')-> onRelationByObject (Relation::of ()-> localAlias (' articles')-> localField ('created_by')-> foreignAlias (' users')-> foreighField ('id'))-> addFieldMappingByObject (FieldMapping::of ()-> key (' created_at') -> src ('created_at')-> type (MappingTypeEnum::METHOD_NAME)-> addFieldMappingByObject (FieldMapping::of ()-> key (' created_by')-> src ('user_name')-> type (MappingTypeEnum::JOIN_FIELD)) Return $this- > toPaginateArray (PaginateTypeEnum::PAGINATE_API);}}
In the above example, the code converts created_at from int to time and created_by from user id to user name.
We can see:
Created_at uses MappingTypeEnum::METHOD_NAME. Where is this method? it's in PresenterTrait. So, you can also define your own Trait.
Created_by reads the user_name in the associative array directly, because MappingTypeEnum::JOIN_FIELD is used.
The above code looks a bit long, but onRelationByObject () can use onRelation () to pass parameters instead, and the code is shorter.
Similarly, addFieldMappingByObject (), instead of addFieldMappingList (), is passed in an array, and the code is shorter.
Sight is much more than that. It supports not only the data found by MySQL, but also the data checked out by ElasticSearch.
Although it is a pure array operation, it also has innerJoin and outerJoin, and there is hasOne,hasMany.
Of course, there are more functions, so you need to read the documentation carefully.
Sight tries to solve the problem after you find out the data and convert it into displayable data. It does a good job and really makes you Coding More Happy; Coding More Quickly!
Github address: what are the advantages of https://github.com/BardoQi/Sight"Sight components? "that's it. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.