我目前在一个Zend项目中,我创建了一个名为company
的控制器,在那里我创建了许多操作。现在我想编写一些utils函数,它们将只用于我的控制器的一个操作,比如nameAction
。
以下是我所做的:
class CompanyController extends Zend_Controller_Action {
public function nameAction( $name = null ) {
function get_inner_html( $node ) {
// Some code goes here
return $html;
}
function check_if_social_account($url) {
// Some code goes here
return $social_account;
}
// Here is the main code of my controller
}
}
这个代码运行得很好,但把一些函数变成函数有点奇怪,不是吗?
这些工具函数get_inner_html
&check_if_social_account
,在CompanyController
中作为私有函数?在单独的文件中?
如果此函数将在其他类中使用,请将其提取到另一个类中。如果没有,请在控制器类中创建专用方法。