Yii2 Source Learning Notes (19), Yii2 Source Learning notes _php Tutorial

Source: Internet
Author: User
Tags unique id

Yii2 Source Learning Notes (19), Yii2 Source Learning notes


View remaining code

1     /**2 * @return String|boolean The view file currently being rendered. False If no view file is being rendered.3 * The view file currently being rendered4      */5      Publicfunction Getviewfile ()6     {7         returnEnd ($ This-_viewfiles);8     }9 Ten     /** One * This method was invoked right before [[[RenderFile ()]] renders a view file. A * The default implementation would trigger the [[Event_before_render]] EVENT. - * Pre-event, called when executing [RenderFile ()], default trigger [[Event_before_render]] event - * If You override this method and make sure your call the parent implementation first. the * @param string $viewFile The view file to be rendered. The Views files to render.  - * @param array $params The parameter array passed to the [[Render ()]] method. - * The parameter array is passed to the [render ()] method.  - * @return The Boolean whether to continue rendering the view file.  +      */ -      Publicfunction BeforeRender ($viewFile, $params) +     { A$Event=NewViewEvent ([//Instantiate ViewEvent at             'Viewfile'=$viewFile, -             'params'= = $params, -         ]); -$ This->trigger (Self::event_before_render, $Event);//Trigger [Event_before_render] Event -  -         return$Event->isvalid;//determine whether to continue rendering the file in     } -  to     /** + * This method was invoked right after [[RenderFile ()]] renders a view file. - * The default implementation would trigger the [[Event_after_render]] EVENT. the * Post-event, called after the [RenderFile ()] method is executed, the [[Event_after_render]] event is triggered by default * * If You override this method and make sure your call the parent implementation first. $ * @param string $viewFile The view file being rendered. Panax Notoginseng * @param array $params The parameter array passed to the [[Render ()]] method. - * The parameter array is passed to the [render ()] method.  the * @param string $output The rendering result of the view file. Updates to this parameter + * 'll be passed back and returned by [[RenderFile ()]]. A * Returns the result of view rendering the      */ +      Publicfunction AfterRender ($viewFile, $params, &$output) -     { $         if($ This->haseventhandlers (Self::event_after_render)) {//determine if [Event_after_render] event exists $$Event=NewViewEvent ([ -                 'Viewfile'=$viewFile, -                 'params'= = $params, the                 'Output'=$output, -             ]);Wuyi             //Trigger [Event_after_render] Event the$ This->trigger (Self::event_after_render, $Event); -$output = $Event->output;//return Results Wu         } -     } About  $     /** - * Renders a view file as a PHP script. - * Returns a view file as a PHP script - * This method treats the view file as a PHP script and includes the file. A * It extracts the given parameters and makes them available in the view file. + * The method captures the output of the included view file and returns it as a string. the * Convert incoming parameter to variable, include and execute view file, return execution result - * This method should mainly is called by View renderer or [[RenderFile ()]]. $      * the * @param string $_file_ The view file. the * @param array $_params_ The parameters (Name-value pairs) that would be extracted and made available in the view File. the * @return string The rendering result execution results the      */ -      Publicfunction Renderphpfile ($_file_, $_params_ = []) in     { theOb_start ();//turn on output buffering theOb_implicit_flush (false);//Close Buffer AboutExtract ($_params_, extr_overwrite);//converts an array to a variable using the the require ($_file_); the          the         returnOb_get_clean ();//gets the contents of the buffer area and clears the current output buffer +     } -  the     /**Bayi * Renders dynamic content returned by the given PHP statements. the * This method was mainly used together with content caching (fragment caching and page caching) the * Used to aggregate cached content - * When some portions of the content (called *dynamic content*) should isn't be cached. - * The dynamic content must is returned by some PHP statements. the * Render some dynamic content returned by a PHP statement the * @param string $statements The dynamic content of the PHP statements for generating. Generates a PHP statement that dynamically contents.  the * @return String The placeholder of the dynamic content, or the dynamic content if there is no the * Active Contents cache currently. Dynamic content placeholder Call Evaluatedynamiccontent Output If there is currently no valid content cache -      */ the      Publicfunction renderdynamic ($statements) the     { the         if(!empty ($ This->cachestack)) {//the list of dynamic content is not empty94$n = Count ($ This->dynamicplaceholders);//Statistics Dynamic Content bar number the$placeholder ="YII-DYNAMIC-$n";//Generate placeholders the$ This->adddynamicplaceholder ($placeholder, $statements);//Add a dynamic content placeholder the 98             return$placeholder; About}Else{//no valid cache executes the incoming PHP statement, returning the execution result -             return$ This-evaluatedynamiccontent ($statements);101         }102     }103 104     /** the * Adds A placeholder for dynamic contents. Add a dynamic content placeholder106 * This method is internally used. Internal Use107 * @param string $placeholder The placeholder name placeholder108 * @param string $statements The PHP statements for generating the dynamic content109 * PHP statements that generate dynamic content the      */111      Publicfunction Adddynamicplaceholder ($placeholder, $statements) the     {113         foreach($ This->cachestack as$cache) { the$cache->dynamicplaceholders[$placeholder] = $statements;//Add a dynamic content placeholder the         } the$ This->dynamicplaceholders[$placeholder] = $statements;//Add a dynamic content placeholder to the current view117     }118 119     /** - * Evaluates the given PHP statements. The value of the given PHP statement121 * This method was mainly used internally to implement dynamic content feature122 * @param string $statements The PHP statements to be evaluated. PHP Statement for calculation123 * @return Mixed the return value of the PHP statements. The value of the PHP statement124      */ the      Publicfunction Evaluatedynamiccontent ($statements)126     {127         returneval ($statements); -     }129  the     /**131 * begins recording a block. the * This method was a shortcut to beginning [[Block]]133 * Data Block start tag, this method is the shortcut to start [block]134 * Data blocks can be specified in one place the view content is displayed in another place, usually with the layout135 * @param string $id The block ID. Data Block identification136 * @param Boolean $renderInPlace whether to render the block contents in place. Whether to render chunk content. 137 * Defaults to False, meaning the captured block won't be displayed.138 * @return block The Block widget instance block widget instance139      */ $      Publicfunction Beginblock ($id, $renderInPlace =false)141     {142         returnBlock::begin ([143             'ID'= $id,//data block Unique identification144             'Renderinplace'= $renderInPlace,//whether the identity is displayed145             'View'= = $ This,146         ]);147     }148 149     /** Max * Ends Recording a block. Data Block End identification151      */ the      Publicfunction Endblock ()153     {154 block::end ();155     }156 157     /**158 * Begins the rendering of content is decorated by the specified view.159 * This method can is used to implement nested layout. For example, a layout can embedded the * In another layout file specified as ' @app/views/layouts/base.php ' like the following:161 * Start the specified view render content, used to implement the nested layout, the first parameter passed to the path of the layout file162      * ~~~163 * 
    begincontent (' @app/views/layouts/base.php ');?>164 * ... layout content here ...165 * 
    endcontent ();?>166      * ~~~167      *168 * @param string $viewFile The view file that'll be used to decorate the content enclosed by this widget.169 * This can be specified as either the path or path alias of the view file path or path alias.  the * @param array $params the variables (name = value) to being extracted and made available in the decorative Vie W.171 * Parameters that can be used in the view172 * @return Contentdecorator the Contentdecorator widget instance part instance173 * @see Contentdecorator174      */175      Publicfunction Begincontent ($viewFile, $params= [])176     {177         returnContentdecorator::begin ([178             'Viewfile'=$viewFile,179             'params'= = $params, the             'View'= = $ This,181         ]);182     }183 184     /**185 * Ends the rendering of content. End Rendering186      */187      Publicfunction endcontent ()188     {189 contentdecorator::end (); the     }191 192     /**193 * begins fragment caching. Start Fragment Cache194 * This method would display cached content if it is available.195 * If not, it'll start caching and would expect an [[Endcache ()]]196 * Call to end the cache and save the content into cache.197 * Display the available cache content, otherwise the cache content will start until the [Endcache ()] method appears198 * A Typical usage of fragment caching is as follows,199      * $      * ~~~201 * if ($this->begincache ($id)) {202 *//... generate content here203 * $this->endcache ();204      * }205      * ~~~206      *207 * @param string $id a unique ID identifying the fragment to be cached. Unique identifier of the cache fragment208 * @param array $properties initial property values for [[FragmentCache]] initial properties [FragmentCache]209 * @return Boolean whether you should generate the contents for caching. Whether to generate cached content.  About * False If the cached version is available.211      */212      Publicfunction Begincache ($id, $properties = [])213     {214$properties ['ID'] = $id;//Fragment Identification215$properties ['View'] = $ This;//Invoking initialization Properties216         /*@var $cache FragmentCache*/217$cache =Fragmentcache::begin ($properties);218         if($cache->getcachedcontent ()!==false) {219$ This->endcache ();//reads the cached content from the cache, renders the content and returns false, no longer caches - 221             return false;222}Else {223             return true;224         }225     }226 227     /**228 * Ends fragment caching. End Fragment Cache229      */ the      Publicfunction Endcache ()231     {232 fragmentcache::end ();233     }234 235     /**236 * Marks The beginning of a page. Start tag237      */238      Publicfunction beginpage ()239     { -Ob_start ();//turn on output buffering241Ob_implicit_flush (false);//Close Buffer242 243$ This-trigger (self::event_begin_page);244     }245 246     /**247 * Marks The ending of a page. End tag248      */249      Publicfunction EndPage () -     {251$ This-trigger (self::event_end_page);252Ob_end_flush ();//Close Output Buffers253}

http://www.bkjia.com/PHPjc/1137013.html www.bkjia.com true http://www.bkjia.com/PHPjc/1137013.html techarticle yii2 Source Learning notes (19), Yii2 Source Learning notes View remaining code 1/* * 2 * @return String|boolean The view file currently being rendered. False If no view file is being ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.