nginx - php basic issues. .
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
