nginx - php基礎問題。。

來源:互聯網
上載者:User
某個項目的檔案

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();    }

問題一:

        $lang = json_encode($lang);        $lang = json_decode($lang);

這兩句在這裡什麼作用?,為什麼要把$lang變成json格式後又解析成php變數?這不是多此一舉嗎?
問題二:

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

這四句又怎麼理解?
我的理解是assign的第一個參數是變數名,後面是它的變數值,可是

`$this->l = $tLang;`不就是將`$tLang`賦值給`$this`的`l`屬性嗎?這四句不就重複了嗎?

回複內容:

某個項目的檔案

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();    }

問題一:

        $lang = json_encode($lang);        $lang = json_decode($lang);

這兩句在這裡什麼作用?,為什麼要把$lang變成json格式後又解析成php變數?這不是多此一舉嗎?
問題二:

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

這四句又怎麼理解?
我的理解是assign的第一個參數是變數名,後面是它的變數值,可是

`$this->l = $tLang;`不就是將`$tLang`賦值給`$this`的`l`屬性嗎?這四句不就重複了嗎?

先不說代碼寫的怎麼樣..

第一個問題, 就是把數群組轉換成對象.

第二個問題, assign是註冊模板變數, 在view裡面可以直接使用$lang. 所以是不一樣的

問題一:這裡$lang的變數不知道哪裡來的。。。。不過這種json_encode(),json_decode()連寫是可以做資料類型轉換的。如果最初$lang是一個array,執行完這兩句就轉換為object。

問題二:我也不是很清楚。。

問題一:將$lang變數轉化為object(對象).$lang多半是include引入的。在模板引擎中,數組跟對象的格式是不一樣的。可能是作者用的順手,所以就轉了。
問題二:是將$lang和$tLang傳遞到頁面上方便頁面調用。而用了$this->l和$this->lang是將其儲存在當前類中方便自身調用或者在外調用。而當我們每次new出該類時,該類會傳遞兩個變數到頁面,同時並將變數值賦值給當前類的屬性。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.