Home > Article > Backend Development > typecho - html and php mixed problem
The above code is the template page of typecho, which is a mixed page of html and php. The php code contains this, which is quite strange. I don’t see where the class this comes from in this code. What is the syntax of this? Also, I see many sections of PHP code on this page. Can each section be regarded as a whole section? For example, if you define the variable a in one section and then get the value in another PHP block, right? Forgot to contact me
The above code is the template page of typecho, which is a mixed page of html and php. The php code contains this, which is quite strange. I don’t see where the class this comes from in this code. What is the syntax of this? Also, I see many sections of PHP code on this page. Can each section be regarded as a whole section? For example, if you define the variable a in one section and then get the value in another PHP block, right? Forgot to contact me
$this represents its own object;
$this->$name uses the content of $name as the attribute name of the object. To access object attributes
For example, first specify $name='address';
$this->$ name is equivalent to $this->address
This usually points to the application or framework kernel
<code><?php class App { public function view($template, $return = true) { ob_start(); include $template; $content = ob_get_contents(); if ($return) { return $content; } else { echo $content; } } } </code>
When the controller displays the template, it is usually called
<code>$this->view('模板地址');</code>
And $this in this template points to the instance of the app class
In the php file, code other than can be regarded as echoing a string, and the scope of each piece of code is not independent
<code><?php $test = 'hello!world'; ?> html代码 <?php echo $test; //显示hello!world ?></code>