Home > Web Front-end > JS Tutorial > body text

How to solve the error problem of php code in js

零到壹度
Release: 2018-03-24 11:20:23
Original
2149 people have browsed it

In a module, the front end is extjs and the back end is php. An error is reported. This is an error reported when the error warning of php is turned on to the most strict. Although the program can run, the log accumulation is getting bigger and bigger. many.

<span style="color:rgb(0,0,0);
   font-family:Consolas, Inconsolata, Courier, monospace;font-size:12px;
   background-color:rgb(255,255,255);">Undefined variable:loginUserName
</span>
Copy after login
<script>
    Ext.onReady(function () {
        var app = Ext.create("PSI.App", {
         //   userName: "{$loginUserName}",
            productionName: "{$productionName}"
        });
       
    });
</script>
Copy after login

Backend php:

    /**
     * 业务日志 - 主页面
     */
    public function index()
    {
        $us = new UserService();

        if ($us->hasPermission(FIdConst::USE_ORDER)) {
            $this->initVar();

           // $this->assign("loginUserName", "tom");
 

            $this->display();
        } else {
            $this->gotoLoginPage("/Home/");
        }
    }
Copy after login

I commented out loginUserName on both the front and back ends Yes, why is it still reporting an error?

I tracked down thinkphp’s page cache and found this line in

js:

//   userName: "{$loginUserName}",
Copy after login

Corresponding to this line in the cache php code:

//   userName: "<?php echo ( $loginUserName); ?>",
Copy after login

Although there are comments in the js, there is not much control in the php code at this time, as long as it is

At this time, this line in the php page is commented:

 // $this->assign("loginUserName", "tom");
Copy after login

So, when the front-end page is parsed, $loginUserName cannot be found, and an error is reported. .

Solution:

Just delete this line in the js code:

 //   userName: "{$loginUserName}",
Copy after login

Related recommendations:

Using JS in PHP to pop up garbled error messages

Introducing js and css file errors into php template files and html files

The above is the detailed content of How to solve the error problem of php code in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template