A file for a project
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 (); }
Question one:
$lang = json_encode($lang); $lang = json_decode($lang);
What's the effect of these two sentences here? , why would you turn $lang into a JSON format and parse it into a PHP variable? Isn't this superfluous?
Question two:
$this->assign('lang' , $lang); $this->assign('l' , $tLang); $this->l = $tLang; $this->lang = $lang;
How do you understand these four sentences?
My understanding is that assign's first argument is the variable name, followed by its variable value, but
`$this->l = $tLang;`不就是将`$tLang`赋值给`$this`的`l`属性么?这四句不就重复了么?
Reply content:
A file for a project
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 (); }
Question one:
$lang = json_encode($lang); $lang = json_decode($lang);
What's the effect of these two sentences here? , why would you turn $lang into a JSON format and parse it into a PHP variable? Isn't this superfluous?
Question two:
$this->assign('lang' , $lang); $this->assign('l' , $tLang); $this->l = $tLang; $this->lang = $lang;
How do you understand these four sentences?
My understanding is that assign's first argument is the variable name, followed by its variable value, but
`$this->l = $tLang;`不就是将`$tLang`赋值给`$this`的`l`属性么?这四句不就重复了么?
Let's not say how the code is written.
The first problem is to convert an array into an object.
The second problem, assign, is to register the template variable, which can be used directly in the view $lang
. So it's different.
Problem one: $lang
The variables here do not know where to come from .... However json_encode()
, json_decode()
ligatures is capable of doing data type conversions. If $lang
It is initially an array, the execution of these two sentences is converted to object.
Question two: I'm not quite sure.
Problem One: Convert the $lang variable to an object. The $lang is mostly introduced by include. In the template engine, arrays are not the same format as objects. Maybe the author used it handy, so he turned.
Problem two: It is convenient for page call to pass $lang and $tlang to the page. The use of $this->l and $this->lang is to save it in the current class to make it easy for itself to invoke or to call outside. And each time we new out of the class, the class passes two variables to the page, and assigns the value of the variable to the properties of the current class.