Cakephp AppView功能从视图

时间:2016-05-26 23:09:26

标签: cakephp cakephp-3.0

如何在另一个视图中调用您在AppView中编写的函数?比如索引视图?

<?php
/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link      http://cakephp.org CakePHP(tm) Project
 * @since     3.0.0
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */
namespace App\View;

use Cake\View\View;

/**
 * Application View
 *
 * Your application’s default view class
 *
 * @link http://book.cakephp.org/3.0/en/views.html#the-app-view
 */
class AppView extends View
{       

    public function initialize(){
    }       

    public function printNavSidebar(){
        echo '<nav class="large-1 medium-2 columns" id="actions-sidebar">';
    }


}

如何在索引视图中调用printNavSidebar()函数?

1 个答案:

答案 0 :(得分:0)

哎呀找到了它。在模板$this中是视图类的实例,所以:

$this->printNavSidebar();