Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework 在Zend框架中,我应该在哪里找到与布局相关的逻辑?_Zend Framework_Zend View_Zend Layout - Fatal编程技术网

Zend framework 在Zend框架中,我应该在哪里找到与布局相关的逻辑?

Zend framework 在Zend框架中,我应该在哪里找到与布局相关的逻辑?,zend-framework,zend-view,zend-layout,Zend Framework,Zend View,Zend Layout,我需要自定义我的身体标签的属性。我应该在哪里找到逻辑?在基本控制器中,查看辅助对象 这应该是布局 <?=$this->doctype() ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ... </head> <body<?=$this->bodyAttrs?>> <!-- or <?=$this-&

我需要自定义我的身体标签的属性。我应该在哪里找到逻辑?在基本控制器中,查看辅助对象

这应该是布局

<?=$this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        ...
    </head>
    <body<?=$this->bodyAttrs?>>  <!-- or <?=$this->bodyAttrs()?> -->
        ...
    </body>
</html>
这是连接属性的函数

/**
  * @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;
}
我需要最后一个胶水代码。

为您准备了一个更好的:

<?php
class My_View_Helper_Attribs extends Zend_View_Helper_HtmlElement
{

    public function attribs($attribs) {
        if (!is_array($attribs)) {
            return '';
        }
        //flatten the array for multiple values
        $attribs = array_map(function($item) {
           if (is_array($item) {
                return implode(' ', $item)
           }
           return $item;
        }, $attribs);
        //the htmlelemnt has the build in function for the rest
        return $this->_htmlAttribs($attribs)
    }
}
在您的视图脚本中:

<body <?= $this->attribs($this->bodyAtrribs) ?>>
>

我认为@Fatmuemoo为您提供了最好的解决方案,但是如果您添加此
$this->view->bodyAttrs=$this->\u makeBodyAttribs($this->idBody,$this->classesBody),您的代码将运行到您的操作结束。此外,在您的函数中,
isset
应替换为
!空的
否则没有意义。
public function indexAction()
{
    //notice it is $this->view and not just $this
    $this->view->bodyAttribs= array('id' => 'someId', 'class' => array("wide","dark"));
}

public function loginAction()
{
    $this->view->bodyAttribs['id'] = "someId2";
    $this->view->bodyAttribs['class'] = array();
}
<body <?= $this->attribs($this->bodyAtrribs) ?>>