当前位置: 首页>>代码示例>>PHP>>正文


PHP Layout::getMvcInstance方法代码示例

本文整理汇总了PHP中Zend\Layout\Layout::getMvcInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Layout::getMvcInstance方法的具体用法?PHP Layout::getMvcInstance怎么用?PHP Layout::getMvcInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Layout\Layout的用法示例。


在下文中一共展示了Layout::getMvcInstance方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: direct

    /**
     * Encode data as JSON, disable layouts, and set response header
     *
     * If $keepLayouts is true, does not disable layouts.
     *
     * @param  mixed $data
     * @param  bool $keepLayouts
     * NOTE:   if boolean, establish $keepLayouts to true|false
     *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
     *         this array can contains a 'keepLayout'=>true|false
     *         that will not be passed to Zend_Json::encode method but will be used here
     * @return string|void
     */
    public function direct($data = null, $keepLayouts = false)
    {
        if ($data == null) {
            throw new \InvalidArgumentException('JSON: missing argument. $data is required in json($data, $keepLayouts = false)');
        }
        
        $options = array();
        if (is_array($keepLayouts))
        {
            $options     = $keepLayouts;
            $keepLayouts = (array_key_exists('keepLayouts', $keepLayouts))
                            ? $keepLayouts['keepLayouts']
                            : false;
            unset($options['keepLayouts']);
        }

        $data = \Zend\Json\Json::encode($data, null, $options);
        if (!$keepLayouts) {
            $layout = LayoutManager::getMvcInstance();
            if ($layout instanceof LayoutManager) {
                $layout->disableLayout();
            }
        }

        $response = \Zend\Controller\Front::getInstance()->getResponse();
        $response->setHeader('Content-Type', 'application/json');
        return $data;
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:41,代码来源:Json.php

示例2: disableLayouts

 /**
  * Disable layouts and view renderer
  *
  * @return \Zend\Controller\Action\Helper\AutoComplete\AbstractAutoComplete Provides a fluent interface
  */
 public function disableLayouts()
 {
     if (null !== ($layout = Layout::getMvcInstance())) {
         $layout->disableLayout();
     }
     $this->getBroker()->load('viewRenderer')->setNoRender(true);
     return $this;
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:13,代码来源:AbstractAutoComplete.php

示例3: disableLayouts

 /**
  * Disable layouts and view renderer
  *
  * @return \Zend\Controller\Action\Helper\AutoComplete\AbstractAutoComplete Provides a fluent interface
  */
 public function disableLayouts()
 {
     if (null !== ($layout = Layout::getMvcInstance())) {
         $layout->disableLayout();
     }
     HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
     return $this;
 }
开发者ID:heiglandreas,项目名称:zf2,代码行数:13,代码来源:AbstractAutoComplete.php

示例4: getLayout

 /**
  * Get layout object
  *
  * @return \Zend\Layout\Layout
  */
 public function getLayout()
 {
     if (null === $this->_layout) {
         $this->_layout = \Zend\Layout\Layout::getMvcInstance();
         if (null === $this->_layout) {
             // Implicitly creates layout object
             $this->_layout = new \Zend\Layout\Layout();
         }
     }
     return $this->_layout;
 }
开发者ID:rexmac,项目名称:zf2,代码行数:16,代码来源:Layout.php

示例5: __invoke

 /**
  * Encode data as JSON, disable layouts, and set response header
  *
  * If $keepLayouts is true, does not disable layouts.
  *
  * @param  mixed $data
  * @param  bool $keepLayouts
  * NOTE:   if boolean, establish $keepLayouts to true|false
  *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
  *         this array can contains a 'keepLayout'=>true|false
  *         that will not be passed to Zend_Json::encode method but will be used here
  * @return string|void
  */
 public function __invoke($data, $keepLayouts = false)
 {
     $options = array();
     if (is_array($keepLayouts)) {
         $options = $keepLayouts;
         $keepLayouts = array_key_exists('keepLayouts', $keepLayouts) ? $keepLayouts['keepLayouts'] : false;
         unset($options['keepLayouts']);
     }
     $data = \Zend\Json\Json::encode($data, null, $options);
     if (!$keepLayouts) {
         $layout = LayoutManager::getMvcInstance();
         if ($layout instanceof LayoutManager) {
             $layout->disableLayout();
         }
     }
     $response = \Zend\Controller\Front::getInstance()->getResponse();
     $response->setHeader('Content-Type', 'application/json');
     return $data;
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:32,代码来源:Json.php

示例6: prepareAutoCompletion

 /**
  * Prepare data for autocompletion
  *
  * @param  mixed   $data
  * @param  boolean $keepLayouts
  * @return string
  */
 public function prepareAutoCompletion($data, $keepLayouts = false)
 {
     if (!$data instanceof DojoData) {
         $items = array();
         foreach ($data as $key => $value) {
             $items[] = array('label' => $value, 'name' => $value);
         }
         $data = new DojoData('name', $items);
     }
     if (!$keepLayouts) {
         $this->getBroker()->load('viewRenderer')->setNoRender(true);
         $layout = Layout::getMvcInstance();
         if ($layout instanceof Layout) {
             $layout->disableLayout();
         }
     }
     $response = FrontController::getInstance()->getResponse();
     $response->setHeader('Content-Type', 'application/json');
     return $data->toJson();
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:27,代码来源:AutoCompleteDojo.php

示例7: testCallingStartMvcTwiceDoesntGenerateAnyUnexpectedBehavior

 /**
  * @group ZF-5152
  */
 public function testCallingStartMvcTwiceDoesntGenerateAnyUnexpectedBehavior()
 {
     Layout\Layout::startMvc('/some/path');
     $this->assertEquals(Layout\Layout::getMvcInstance()->getLayoutPath(), '/some/path');
     Layout\Layout::startMvc('/some/other/path');
     $this->assertEquals(Layout\Layout::getMvcInstance()->getLayoutPath(), '/some/other/path');
     $this->assertTrue(Layout\Layout::getMvcInstance()->isEnabled());
 }
开发者ID:rexmac,项目名称:zf2,代码行数:11,代码来源:LayoutTest.php

示例8: initContext

 /**
  * Initialize context detection and switching
  *
  * @param  mixed $format
  * @throws \Zend\Controller\Action\Exception
  * @return void
  */
 public function initContext($format = null)
 {
     $this->_currentContext = null;
     $controller = $this->getActionController();
     $request = $this->getRequest();
     $action = $request->getActionName();
     // Return if no context switching enabled, or no context switching
     // enabled for this action
     $contexts = $this->getActionContexts($action);
     if (empty($contexts)) {
         return;
     }
     // Return if no context parameter provided
     if (!($context = $request->getParam($this->getContextParam()))) {
         if ($format === null) {
             return;
         }
         $context = $format;
         $format = null;
     }
     // Check if context allowed by action controller
     if (!$this->hasActionContext($action, $context)) {
         return;
     }
     // Return if invalid context parameter provided and no format or invalid
     // format provided
     if (!$this->hasContext($context)) {
         if (empty($format) || !$this->hasContext($format)) {
             return;
         }
     }
     // Use provided format if passed
     if (!empty($format) && $this->hasContext($format)) {
         $context = $format;
     }
     $suffix = $this->getSuffix($context);
     $this->_getViewRenderer()->setViewSuffix($suffix);
     $headers = $this->getHeaders($context);
     if (!empty($headers)) {
         $response = $this->getResponse();
         foreach ($headers as $header => $content) {
             $response->setHeader($header, $content);
         }
     }
     if ($this->getAutoDisableLayout()) {
         $layout = \Zend\Layout\Layout::getMvcInstance();
         if (null !== $layout) {
             $layout->disableLayout();
         }
     }
     if (null !== ($callback = $this->getCallback($context, self::TRIGGER_INIT))) {
         if (is_string($callback) && method_exists($this, $callback)) {
             $this->{$callback}();
         } elseif (is_string($callback) && function_exists($callback)) {
             $callback();
         } elseif (is_array($callback)) {
             call_user_func($callback);
         } else {
             throw new Action\Exception(sprintf('Invalid context callback registered for context "%s"', $context));
         }
     }
     $this->_currentContext = $context;
 }
开发者ID:stunti,项目名称:zf2,代码行数:70,代码来源:ContextSwitch.php

示例9: getLayoutInstance

 /**
  * Get layout object
  *
  * @return \Zend\Layout\Layout
  */
 public function getLayoutInstance()
 {
     if (null === $this->_layout) {
         if (null === ($this->_layout = \Zend\Layout\Layout::getMvcInstance())) {
             $this->_layout = new \Zend\Layout\Layout();
         }
     }
     return $this->_layout;
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:14,代码来源:Layout.php


注:本文中的Zend\Layout\Layout::getMvcInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。