我敢肯定这是一个简单的单行,但我似乎无法找到它.
如何为特定操作使用不同的布局文件?
更新:这对我有用,谢谢!
// Within controller
$this->_helper->_layout->setLayout('other-layout') //other-layout.phtml
//Within view script
<?php $this->layout()->setLayout('other-layout'); ?>
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我有许多动态元素,每个页面都是一致的.我已将这些放在layout.phtml中
我的问题是:如何从控制器向我的布局发送变量?
如果我想从我的控制器发送东西,我可以使用:
$this->view->whatever = "foo";
Run Code Online (Sandbox Code Playgroud)
并在视图中接收它
echo $this->whatever;
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何对我的布局做同样的事情.也许有更好的方法解决这个问题?
我将此ViewScript用于我的标准表单元素:
<div class="field" id="field_<?php echo $this->element->getId(); ?>">
<?php if (0 < strlen($this->element->getLabel())) : ?>
<?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?>
<?php endif; ?>
<span class="value"><?php echo $this->{$this->element->helper}(
$this->element->getName(),
$this->element->getValue(),
$this->element->getAttribs()
) ?></span>
<?php if (0 < $this->element->getMessages()->length) : ?>
<?php echo $this->formErrors($this->element->getMessages()); ?>
<?php endif; ?>
<?php if (0 < strlen($this->element->getDescription())) : ?>
<span class="hint"><?php echo $this->element->getDescription(); ?></span>
<?php endif; ?>
</div>
Run Code Online (Sandbox Code Playgroud)
尝试单独使用ViewScript会导致错误:
表单捕获的异常:找不到文件装饰器...无法呈现文件元素
看看这个FAQ揭示了我的部分问题,我更新了我的表单元素装饰器,如下所示:
'decorators' => array(
array('File'),
array('ViewScript', array('viewScript' => 'form/field.phtml'))
)
Run Code Online (Sandbox Code Playgroud)
现在它将文件元素渲染两次,一次在我的视图脚本中,以及在视图脚本之外使用文件元素的额外元素:
<input type="hidden" name="MAX_FILE_SIZE" value="8388608" id="MAX_FILE_SIZE" …Run Code Online (Sandbox Code Playgroud) zend-framework decorator zend-form zend-view zend-form-element
是否可以在Zend View中使用helper(extends Zend_View_Helper_Abstract)获取有关调用该帮助程序的模块/控制器/操作的信息?
我有以下控制器,除了其他方法,它有这个:
class EquipasController extends OccControllerAction {
public function listaAction()
{
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout();
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我当时正在等待:http: //www.example.com/equipas/lista/
控制器将执行,我将看不到我的视口上的布局渲染.
但事实并非如此.我得到了我的主页.
在ZF上我们通常会说:如果某个操作不存在,主页应该出现?
注意:如果,而不是:http: //www.example.com/equipas/lista/
我这样做, http://www.example.com/equipas/adasdas21232131/ 不存在.
我得到相同的主页渲染.
这种行为可能是什么原因?
一个Zend新手,MEM
我希望我的客户部分是https,例如注册,登录,个人详细信息,订单详细信息等.我已经设置了包含https方案的路线(我可以通过https访问客户部分)但我不能强制我的链接使用https:
<a class="register" href="<?php echo $this->url('customer/default', array('controller' => 'registration', 'action' => 'index'), array('scheme' => 'https', 'force_canonical' => true,)); ?>">Register</a>
Run Code Online (Sandbox Code Playgroud)
我得到了什么: http://myproject.dev/customer/registration
我想要的是: https://myproject.dev/customer/registration
它似乎使用当前的方案 - 所以如果我在http上,那么网址是http,如果我在https上,那么网址是https.
我如何强制$this->url一直使用该https方案?
'router' => array(
'routes' => array(
'customer' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/customer',
'scheme' => 'https',
'defaults' => array(
'__NAMESPACE__' => 'Customer\Controller',
'https' => true,
'controller' => 'Index',
'action' => 'index',
),
),
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => …Run Code Online (Sandbox Code Playgroud) 我有几个视图Partials(像paginator部分),我希望它们可用于我的应用程序中的所有视图脚本.
是否有一个我可以放入部分视频的目录,它们将可供所有用户使用?
或者,我如何定义这样的目录?
我需要帮助理解Zend Framework中辅助函数的实际操作.
我需要有人向我解释在$this->escape($string)将字符串打印到模板之前对传递给它的字符串实际做了什么.
案例:您正在使用Zend Framework开发一个站点,并且需要相关链接到部署webapp的文件夹.即mysite.com/folder在线和localhost:8080正在开发中.
无论部署位置如何,以下在控制器中都很好用:
$this->_helper->redirector->gotoSimple($action, $controller, $module, $params);
Run Code Online (Sandbox Code Playgroud)
以下是一个意见稿,即.index.phtml:
<a href="<?php echo $this->url(array('controller'=>'index', 'action' => 'index'), null, true); ?>">
Run Code Online (Sandbox Code Playgroud)
但是,如何在链接到图像或样式表时获得正确的基本路径?(例如,在layout.phtml文件中):
<img src='<?php echo WHAT_TO_TYPE_HERE; ?>images/logo.png' />
Run Code Online (Sandbox Code Playgroud)
和
$this->headLink()->appendStylesheet( WHAT_TO_TYPE_HERE . 'css/default.css');
Run Code Online (Sandbox Code Playgroud)
WHAT_TO_TYPE_HERE 应该用给出的东西代替
<img src="/folder/images/logo.png />` on mysite.com and `<img src="/images/logo.png />
Run Code Online (Sandbox Code Playgroud)
在localhost上
我有一个控制器,我想用于ajax脚本调用和设置会话变量,获取信息等.我如何设置它,以便该特定控制器不使用默认布局(特别是没有布局),以便它可以来回发送XML/JSON消息?
zend-framework ×10
zend-view ×10
php ×7
zend-layout ×4
layout ×3
decorator ×1
view-helpers ×1
views ×1
zend-form ×1