search

Home  >  Q&A  >  body text

YII框架这段代码是啥意思?是moudles里面view中default中的index.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

<code class="lang-php"><?php

/* @var $this DefaultController

  

  $this是从哪来的?

  

  

  

 */

 

$this->breadcrumbs=array(

    $this->module->id,

);

?>

 

 

<h1><?php echo $this->uniqueId . '/' . $this->action->id; ?></h1>

 

 

 

 

 

<p>

This is the view content for action "<?php echo $this->action->id; ?>".

The action belongs to the controller "<?php echo get_class($this); ?>"

in the "<?php echo $this->module->id; ?>" module.

</p>

 

 

 

 

<p>

You may customize this page by editing <tt><?php echo __FILE__; ?></tt>

</p>

 

 

</code>

我想知道这个$this是哪来的?这也没有类啊!

PHPzPHPz2939 days ago580

reply all(3)I'll reply

  • 阿神

    阿神2017-04-10 14:48:34

    注释里面不是写了吗?

    1

    2

    <code>$this DefaultController

    </code>

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-10 14:48:34

    Yii view 里面的$this 是指当前controller,具体过程去看conroller的render方法.
    因为是用Yii自身的renderer,所以调用的是ViewRenderer类的renderFile方法,
    这方法接收一个$context参数,其实传的就是当前controller的实例对象,
    然后再调这个controller的renderInternal方法,这个方法把view文件require进来了,
    所以在view的$this其实是把当前controller传进来,然后调用传进来的controller的自身方法,把view文件require进来.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-10 14:48:34

    debug_print_backtrace 一看就知道

    我心里有答案,但没实际用过YII,所以就只说方法了

    reply
    0
  • Cancelreply