Home > Article > Web Front-end > How to solve the error problem of php code in js
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>
<script> Ext.onReady(function () { var app = Ext.create("PSI.App", { // userName: "{$loginUserName}", productionName: "{$productionName}" }); }); </script>
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/"); } }
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}",
Corresponding to this line in the cache php code:
// userName: "<?php echo ( $loginUserName); ?>",
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");
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}",
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!