JaquelineBrandao / yii

Automatically exported from code.google.com/p/yii
0 stars 0 forks source link

Add CController::beforeRender()/afterRender() #970

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I think it's pretty useful.

Example usage of beforeRender(): http://www.yiiframework.com/doc/
cookbook/54/

afterRender() can be used to echo page statistics (render-time, memory-
usage, db-queries) as html comment after the actual html content.

Original issue reported on code.google.com by keyboard...@gmail.com on 28 Feb 2010 at 12:07

GoogleCodeExporter commented 9 years ago
Any reason why beforeAction/afterAction won't serve for the similar purpose?
Note that the render() method is not always invoked during a request. 
Also, what about renderPartial? What if render() is invoked in a way that it 
returns
the rendering result instead of echoing it?

Original comment by qiang.xue on 5 Mar 2010 at 10:16

GoogleCodeExporter commented 9 years ago
> Any reason why beforeAction/afterAction won't serve for the similar purpose?

Well I think it's a better distinction to have additional beforeRender and 
afterRender method. Let's assume I have a parent controller with attribute 
$pageAuthor. The beforeRender() method of the parent controller injects the 
$pageAuthor as a meta tag into the layout (with help of client-script). This 
example 
isn't possible with beforeAction(), since it's not possible to change the 
$pageAuthor inside of the action (beforeAction() was already called).

> Note that the render() method is not always invoked during a request.

Yes but that's perfect since the proposed methods should obviously be used to 
do 
something related to a (rendered) view - not directly related to a 
controller-action.

> Also, what about renderPartial?

renderPartial() is very different and there is probably no use for 
beforeRenderPartial() or something. The case is that render() is bound to 
nearly 
every action in order to display the view. That's not the case for 
renderPartial().

> What if render() is invoked in a way that it returns
the rendering result instead of echoing it?

I don't think it's a big problem. For example one could use different parent 
controllers. Also maybe it's possible to do signature beforeRender($output = 
true) 
or something? 

Original comment by keyboard...@gmail.com on 5 Mar 2010 at 11:05

GoogleCodeExporter commented 9 years ago
Set for next release.

Original comment by qiang.xue on 13 Mar 2010 at 2:18

GoogleCodeExporter commented 9 years ago
Move to 1.1.3 release.

Original comment by qiang.xue on 2 May 2010 at 2:19

GoogleCodeExporter commented 9 years ago

Original comment by qiang.xue on 6 Jul 2010 at 4:57

GoogleCodeExporter commented 9 years ago
qiang what are your thought about this? After rethinking, I have the feeling my 
proposal is not the best solution. What you think about:

CController::processOutput($content, $return)
CController::beforeProcessOutput($content, $return)
CController::afterProcessOutput($content, $return)

You may see attached patch.

Original comment by keyboard...@gmail.com on 19 Aug 2010 at 4:35

Attachments:

GoogleCodeExporter commented 9 years ago
Not quite sure if we need before/afterProcessOutput. Any use examples? Also, 
the $return parameter is not very useful and it breaks BC.

before/afterRender should be useful.

Original comment by qiang.xue on 19 Aug 2010 at 3:06

GoogleCodeExporter commented 9 years ago
Well beforeProcessOutput/afterProcessOutput is just more fine grained

- can be used with renderPartial() if needed
- possible to access the output directly via $output
- possible to modify the output (though there are other ways to do it)

But okay, I agree it's kind of dirty. I'll attach a patch here soon, then you 
can review again. Note that beforeRender requires $return in order to make a 
decision whether to prepend/append data to the content if the results of 
render() will get returned.

Original comment by keyboard...@gmail.com on 19 Aug 2010 at 11:43

GoogleCodeExporter commented 9 years ago
I think beforeRender/afterRender don't need $return parameter. We can simply 
use their return values to pre/append the body content. They do need $view 
parameter so that it is possible to handle differently according to $view.

Original comment by qiang.xue on 20 Aug 2010 at 12:30

GoogleCodeExporter commented 9 years ago
Okay that makes sense. Most of the time the return value doesn't matter anyway 
I guess. If it does, one can check for $view param.

Original comment by keyboard...@gmail.com on 20 Aug 2010 at 7:10

GoogleCodeExporter commented 9 years ago
Move to 1.1.4.

Original comment by qiang.xue on 2 Sep 2010 at 4:09

GoogleCodeExporter commented 9 years ago
1.1.5

Original comment by qiang.xue on 2 Sep 2010 at 4:09

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r2622.

Original comment by qiang.xue on 6 Nov 2010 at 2:47