小编Mat*_*ski的帖子

Nunjucks检查对象或字符串

如何检查变量是if块中的对象还是字符串?似乎无法调用{% if ... %}块内的函数.而另一种{{ if() }}语法似乎只适用于内联条件.

我现在解决它来测试变量是一个对象时应该存在的一些对象属性,但应该有一个更好的解决方案.像一个isObjectisString功能

nunjucks

3
推荐指数
1
解决办法
3485
查看次数

Zend Framework 2在ListenerAggregateInterface中分离监听器

我实现了一个ListenerAggregateInterface用于侦听dispatch(MvcEvent::EVENT_DISPATCH)事件的方法.

public function attach(EventManagerInterface $events) {
  $this->listeners[] = $events->attach(
    MvcEvent::EVENT_DISPATCH,
    array($this, 'shortCircuit'),
    101
  );

  $this->listeners[] = $events->attach(
    MvcEvent::EVENT_DISPATCH,
    array($this, 'listener1'),
    33
  );

  $this->listeners[] = $events->attach(
    MvcEvent::EVENT_DISPATCH,
    array($this, 'listener2'),
    33
  );
}
Run Code Online (Sandbox Code Playgroud)

如果某些条件shortCiruittrue其余的听众应该被跳过.因此,我打电话ListenerAggregateInterface::detach删除所有听众.

public function shortCircuit(MvcEvent $e) {
  if(condition) {
    $this->detach($e->getApplication()->getEventManager());
  }
}
Run Code Online (Sandbox Code Playgroud)

我原以为他们现在不再被执行,但事实并非如此.

zend-framework2

0
推荐指数
1
解决办法
446
查看次数

标签 统计

nunjucks ×1

zend-framework2 ×1