我应该在 Zend Framework 中的哪里找到与布局相关的逻辑?
我需要自定义 body 标签的属性。我应该把逻辑放在哪里?在基本控制器中,查看 Helper ?
这应该是布局
<?=$this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body<?=$this->bodyAttrs?>> <!-- or <?=$this->bodyAttrs()?> -->
...
</body>
</html>
这应该是控制器中的变量声明
class Applicant_HomeController extends Zend_Controller_Action
{
public function indexAction()
{
$this->idBody = "someId1";
$this->classesBody = array("wide","dark");
}
public function loginAction()
{
$this->idBody = "someId2";
$this->classesBody = array();
}
public function signUpAction()
{
$this->idBody = "someId3";
$this->classesBody = array("no-menu","narrow");
}
}
这是连接属性的函数。
/**
* @param string $idBody id Attribute
* @param array $classesBody class Attribute (array of strings)
*/
protected function _makeBodyAttribs($idBody,$classesBody)
{
$id = isset($idBody)?' id="'.$idBody.'"':'';
$hasClasses = isset($classesBody)&&count($classesBody);
$class = $hasClasses?' class="'.implode(' ',$classesBody).'"':'';
return $id.$class;
}
我需要最后的胶水代码。
I need to customize the attributes of my body tag. Where should I locate the logic? In a Base Controller, view Helper ?
This should be the layout
<?=$this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body<?=$this->bodyAttrs?>> <!-- or <?=$this->bodyAttrs()?> -->
...
</body>
</html>
And this should be the variables declaration in controllers
class Applicant_HomeController extends Zend_Controller_Action
{
public function indexAction()
{
$this->idBody = "someId1";
$this->classesBody = array("wide","dark");
}
public function loginAction()
{
$this->idBody = "someId2";
$this->classesBody = array();
}
public function signUpAction()
{
$this->idBody = "someId3";
$this->classesBody = array("no-menu","narrow");
}
}
This is the function where the attributes are concatenated.
/**
* @param string $idBody id Attribute
* @param array $classesBody class Attribute (array of strings)
*/
protected function _makeBodyAttribs($idBody,$classesBody)
{
$id = isset($idBody)?' id="'.$idBody.'"':'';
$hasClasses = isset($classesBody)&&count($classesBody);
$class = $hasClasses?' class="'.implode(' ',$classesBody).'"':'';
return $id.$class;
}
I need the last glue code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为你提供了一个更好的:
在你的控制器中:
在你的视图脚本中:
Got one better for ya:
in your controller:
in your view script: