简体   繁体   中英

Attaching data from controllers to views in PHP frameworks, standardization

most of the modern PHP frameworks use data attaching method, for example:

View->render('login', $errors); // or
View::make('login')->with(array('errors'=>$errors);

I'm trying to establish a convention, where even if the View designers and the Controller developers do not have a direct communication, they can expect what data to put, and what data to receive, I have thought of two methods, first using a class that takes care of rendering the views including the data, and this class would contain all types of data which will be used among the platform, second method is to have a naming convention to follow, I personally find the first method better, but I have to note that I'm not a skilled developer, I'm not sure what implications can that method have, which method would you choose? perhaps another method?

For direct view rendering, you can use View::composer method. View composers are callbacks or class methods that are called when a view is created. If you have data that you want bound to a given view each time that view is created throughout your application, a view composer can organize that code into a single location.

It is about auto rendering. You communication convention with designers should be easily done through Separation of concerns pattern.

Blade templating syntax is ideal for that, since it separates logic out of your view. By logic, I mean all data that comes from you domain layer (model,db...).

Using {{$data}} syntax is pretty straightforward and easy to understand to designers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM