I read some MVC framework for web application like play-framework, yii etc. They want to let server side to render the UI and send it to the browser side. Please see below yii code as an example,
I created a php class as below:
<?php
namespace app\controllers;
use yii\web\Controller;
class SiteController extends Controller
{
// ...existing code...
public function actionSay($message = 'Hello')
{
return $this->render('say', ['message' => $message]);
}
}
Then I create a view php file:
<?php
use yii\helpers\Html;
?>
<?= Html::encode($message) ?>
When the render method is called in the action of the controller class, it will render the view and return that to the browser.
I see there are a few frameworks which are using that kind of design pattern. I wander whether it is a good idea from a design point of view. It seems that they combine UI and service together. Whenever we change something on UI, we have to do the corresponding update on server code.
I'd like to separate UI and backend service to different layers. For example, the service can listen on a restful address port over http protocol. And the client side will request/post on these restful interfaces. In this way, the server side doesn't know anything about who is UI/client. It can be browser, mobile or any kind of client.
Which design is a better from design point of view? I just want to get more idea on them. Any feedback is very welcome.
Aucun commentaire:
Enregistrer un commentaire