Home  >  Article  >  Backend Development  >  nginx - php basic issues. .

nginx - php basic issues. .

WBOY
WBOYOriginal
2016-09-08 08:43:521152browse

Files of a certain project

<code><?php
/**
 * 基础类
 */
abstract class Ctrl_Base extends Yaf_Controller_Abstract{
    /**
     * 开启 SESSION : 1
     * 必须登录 : 2
     * 必须管理员 : 4
     */
    protected $_auth = 0;

    /**
     * 当前登录用户
     * @var array
     */
    public $mCurUser = array();
    public $l;
    public $lang;

    /**
     * 构造函数
     */
    public function init(){
        $tSqlite = $this->sqlite();
        $tLCount = $tSqlite->getRow("SELECT COUNT(0) c FROM sqlite_master where type='table' and name='lang'");
        $tLang = array();
        if(!empty($tLCount['c'])){$tLang = $tSqlite->getRow($tSql = 'select * from lang');}
        
        $tLang = empty($tLang['lang'])?'cn':$tLang['lang'];
        include realpath(dirname(__FILE__).'../../../lang/'.$tLang.'/common.php');
        $lang = json_encode($lang);
        $lang = json_decode($lang);
        $this->assign('lang' , $lang);
        $this->assign('l' , $tLang);
        $this->l = $tLang;
        $this->lang = $lang;
        //(1 & $this->_auth) && $this->_session();
        //(1 < $this->_auth) && $this->_role();
        $tSqlite->close();
    }</code>

Question 1:

<code>        $lang = json_encode($lang);
        $lang = json_decode($lang);</code>

What do these two sentences mean here? , why should $lang be converted into json format and then parsed into php variables? Isn't this unnecessary?
Question 2:

<code>        $this->assign('lang' , $lang);
        $this->assign('l' , $tLang);
        $this->l = $tLang;
        $this->lang = $lang;</code>

How do you understand these four sentences?
My understanding is that the first parameter of assign is the variable name, followed by its variable value, but

<code>`$this->l = $tLang;`不就是将`$tLang`赋值给`$this`的`l`属性么?这四句不就重复了么?</code>

Reply content:

Files of a certain project

<code><?php
/**
 * 基础类
 */
abstract class Ctrl_Base extends Yaf_Controller_Abstract{
    /**
     * 开启 SESSION : 1
     * 必须登录 : 2
     * 必须管理员 : 4
     */
    protected $_auth = 0;

    /**
     * 当前登录用户
     * @var array
     */
    public $mCurUser = array();
    public $l;
    public $lang;

    /**
     * 构造函数
     */
    public function init(){
        $tSqlite = $this->sqlite();
        $tLCount = $tSqlite->getRow("SELECT COUNT(0) c FROM sqlite_master where type='table' and name='lang'");
        $tLang = array();
        if(!empty($tLCount['c'])){$tLang = $tSqlite->getRow($tSql = 'select * from lang');}
        
        $tLang = empty($tLang['lang'])?'cn':$tLang['lang'];
        include realpath(dirname(__FILE__).'../../../lang/'.$tLang.'/common.php');
        $lang = json_encode($lang);
        $lang = json_decode($lang);
        $this->assign('lang' , $lang);
        $this->assign('l' , $tLang);
        $this->l = $tLang;
        $this->lang = $lang;
        //(1 & $this->_auth) && $this->_session();
        //(1 < $this->_auth) && $this->_role();
        $tSqlite->close();
    }</code>

Question 1:

<code>        $lang = json_encode($lang);
        $lang = json_decode($lang);</code>

What do these two sentences mean here? , why should $lang be converted into json format and then parsed into php variables? Isn't this unnecessary?
Question 2:

<code>        $this->assign('lang' , $lang);
        $this->assign('l' , $tLang);
        $this->l = $tLang;
        $this->lang = $lang;</code>

How do you understand these four sentences?
My understanding is that the first parameter of assign is the variable name, followed by its variable value, but

<code>`$this->l = $tLang;`不就是将`$tLang`赋值给`$this`的`l`属性么?这四句不就重复了么?</code>

Let’s not talk about how the code is written...

The first problem is to convert the array into an object.

Second question, assign is a registered template variable, which can be used directly in the view$lang. So it is different

Question 1: I don’t know where the variable $lang comes from. . . . However, this kind of json_encode(), json_decode() can be used for data type conversion. If $lang is an array initially, it will be converted to object after executing these two sentences.

Question 2: I’m not very clear either. .

Question 1: Convert $lang variable into object. $lang is mostly introduced by include. In the template engine, the format of arrays and objects are different. Maybe the author found it easy to use, so he transferred it.
Question 2: Pass $lang and $tLang to the page to facilitate page calls. The use of $this->l and $this->lang is to save them in the current class for easy calling by itself or outside. And every time we create a new class, the class will pass two variables to the page and assign the variable values ​​​​to the properties of the current class.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn