Open GoogleCodeExporter opened 9 years ago
Original comment by qiang.xue
on 25 Mar 2009 at 3:19
Need more time.
Original comment by qiang.xue
on 28 Apr 2009 at 1:09
Original comment by qiang.xue
on 20 Sep 2009 at 6:00
Original comment by qiang.xue
on 9 Jan 2010 at 9:01
As discussed in the topic below, more degrees of abstraction than one (e.g.
CHttpResponse) would be a good idea - an abstract base class for any type of
response
could be implemented, and several response types with different capabilities
could be
useful.
http://www.yiiframework.com/forum/index.php?/topic/8668-
capplicationonbeforeoutput/page__p__43341&#entry43341
This post also discusses other aspects of designing a form response model, such
as
integrating CClientScript with one or more response types, in a more generic
way -
allowing other (HTML-specific) post-processing filters to integrate with the
framework in the same manner.
An example of a basic class hierachy might look something like this:
- CHttpResponse (abstract, defines generic features and interface)
- CHtmlResponse (enables post-filtering)
- CTextResponse (adds a plain-text header, for plain text)
- CFileResponse (adds a header with content-type and filename)
You might want to look at ASP.NET MVC for inspiration - it's a C# framework in
it's
very early stages, and in many ways extremely simple compared to Yii, but it
has an
excellent response model that works very well.
I envision CWebApplication have a configuration attribute for response types,
enabling you to configure them in your config file, and/or extend them or
implement
your own response types, for example:
...
'responseTypes' => array(
'html' => array(
'class'=>'CHtmlResponse',
'filters'=>array(
'clientScript'=>'CClientScript',
),
),
'text' => array(
'class'=>'CTextResponse',
),
'file' => array(
'class'=>'CFileResponse',
),
'rss' => array(
'class'=>'MyRssFeedResponse',
),
),
'defaultResponseType'=>'html',
...
In your controller/action, anything that you output would be captured and
passed to
the response object - a default response object would always be created for
you, but
you would have the opportunity to change the response type (before starting
your
output), at the beginning of your action, for example:
public function actionFeed()
{
$this->responseType = 'rss';
$this->render('myXmlFeedView');
}
public function actionDownload()
{
$this->responseType = 'file';
$this->response->file = '/var/web/bigfile.zip';
}
Setting $this->responseType in the example above, actually invokes
CController::setResponseType() - and $this->response actually invokes
CController::getResponse(), which constructs the response type and sets an
attribute.
This is just an example of how a mechanism of this type could work, and very
similar
to that used by ASP.NET MVC.
Another different approach could be implementing response types as behaviors
that
apply to CController. So when you call CController::setResponseType, you are
actually
removing the existing behavior and applying another one. This approach would
enable
you to add different meaningful helper methods for each response type - for
example,
CHtmlResponse would have render(), renderPartial(), and so on, while
CFileResponse
might decorate your controller with a send() method instead.
Just thinking out loud here :-)
Original comment by rasmus.m...@gmail.com
on 28 Apr 2010 at 1:03
i agree on this with rasmus. this is a very important part of the http request
cycle, too bad it's been neglected until now.
Original comment by off...@thisway.ro
on 1 Feb 2012 at 12:30
Migrated to http://github.com/yiisoft/yii/issues/303
Original comment by qiang.xue
on 15 Feb 2012 at 6:48
Original issue reported on code.google.com by
maartenvanvliet
on 25 Mar 2009 at 11:19