0

我的 yii 第一个项目中有一个文件。我的项目有这个路径的新主题

first_proj\themes\project\views\layouts\main.php

我想在其中调用一个函数,如下所示

<?php
    if($is_project_manager){
?>
        <div class="each-pop-el" style="cursor:pointer" ng-click="showAllMemberTask()">show tasks</div>
  <?php } ?>  

并在 first_proj\protected\controllers\project.php 中具有功能,这是

public function actionIsProjectmanager(){
        $project_manager = false;
            $crt = new CDbCriteria;
            $crt->condition = 'user_id=:uid and role=1';
            $crt->params = array('uid'=>Yii::app()->user->id);
            $project_manager= projectMember::model()->findAll($crt);
            // $model_result = MyModel::model()->test();

            $this->render('the url to theme and main.php file', array('is_project_manager' => $project_manager));
    }

我怎样才能访问那个 main.php 文件?我必须写什么而不是
the url to theme and main.php file在我的函数中?

4

3 回答 3

0

在您的视图中使用它

<?php
    if($this->isProjectmanager){
?>
        <div class="each-pop-el" style="cursor:pointer" ng-click="showAllMemberTask()">show tasks</div>
  <?php } ?> 

并在你的控制器中创建一个辅助函数(不是一个动作!)

public function IsProjectmanager(){
    if ($someConditon) {
       return true;
    }
    else  {
       return false;
    }

    }
于 2015-03-11T06:19:29.140 回答
0

您将控制器设置layout为文件。所以它看起来像这样:

$this->layout = 'main';

布局也必须使用视图文件进行渲染。

$this->render('index', array('is_project_manager' => $project_manager));

然后index.php在您的views/project文件夹中放置一个包含操作内容的文件。

这假设您已将配置设置为将主题设置为project

于 2015-03-10T09:35:45.827 回答
0

您需要知道的第一件事是:无需将布局文件传递给视图。当你使用render()函数时,yii 会自动为你的视图添加布局。然后,为了指定布局,您需要$this->layout = '//layouts/main在您的操作中使用。

于 2015-03-10T12:00:17.120 回答