2

So let's say that in my controller inside some of my methods I want to return a view like this:

return $this->render('home', [
    'model' => $model,
]);

In my doc block, I want to document what this method is returning. I do not know how to document that this method is returning a view. Is that a resource ? Is it mixed ?

Is this valid? :

@return resource

And how do you document that your method is returning redirect to some other page ?

tereško
  • 58,060
  • 25
  • 98
  • 150
offline
  • 1,589
  • 1
  • 21
  • 42

1 Answers1

3

Your docblock is just giving you typehinting in your IDE and making things more readable. You can absolutely do @return resource, if that's what you're returning, but you can also just include more comments too

/**
*  This function returns a view which then redirects the user to another page
*
*  @param string $model The model we looked at
*  @return resource The page to redirect to
*/
function foo($model){
    return $this->render('home', [
    'model' => $model,
    ]);
}

If there's a more specific class in your framework for what the actual return from $this->render is, then you should probably include that, but if you're saying $this->render redirects the page, then there's actually no reason to return it inside this function since those calls won't happen, and it can just be a void function (or you can return a boolean in case things fail)

DaOgre
  • 2,080
  • 16
  • 25
  • I am using yii2 framework, and there you have to return calls to views. So view can be considered to be a resource ? I know that usually you are using resource when your are returning database connections and maybe query calls. – offline Sep 11 '14 at 19:01
  • So if you're talking about: http://www.yiiframework.com/doc-2.0/yii-base-viewrenderer.html#render()-detail you can see the return type for render is a string. Your docblock should just be reflecting the actual class type, or primitive type that you're returning. – DaOgre Sep 11 '14 at 19:05
  • Wow, I never thought to consult the API doc. One more question, the "resource" term is a bit vague to me. Can you please explain where it would be appropriate to use it ? – offline Sep 11 '14 at 19:08
  • No problem, a resource is a special type of variable, you can see the specifics in the php documentation here: http://php.net/manual/en/language.types.resource.php – DaOgre Sep 11 '14 at 19:13