简体   繁体   English

在视图中声明和使用PHP变量可以在Localhost上正常运行,但不能在实时服务器(ubuntu AWS)Laravel 4.1上运行

[英]Declaring and using PHP variables in views works fine in Localhost but not on live server (ubuntu AWS) Laravel 4.1

I have honed my website to work fine on my localhost, but I am having trouble on my live server. 我已经磨练过我的网站,可以在我的本地主机上正常工作,但是我在实时服务器上遇到了麻烦。 When I declare variables in my views, and try to use them, I am getting js or php errors (depending on where I declare and use the variable). 当我在视图中声明变量并尝试使用它们时,我遇到了js或php错误(取决于声明和使用变量的位置)。 Here are the examples: 以下是示例:

In js, I declare a php variable like so: 在js中,我声明了一个php变量,如下所示:

//in javascript //在javascript中

<? $id = Session::get('redirected_id'); ?>
@if(isset($id))
$('#myModal').modal('show');
@endif

Basically if I send a variable with the redirect to the view, I want this modal to appear. 基本上,如果我发送带有重定向到视图的变量,则希望此模式出现。 When I run this on localhost, all of the js works fine. 当我在localhost上运行时,所有的js都能正常工作。 When I run this on my live server, I get the error: 在实时服务器上运行此命令时,出现错误:

Uncaught SyntaxError: Unexpected token < 

in reference to <? $id = Session::get('redirected_id'); ?> 参考<? $id = Session::get('redirected_id'); ?> <? $id = Session::get('redirected_id'); ?>

On another note, I am getting php errors on my live server when I declare a variable in the html portion, and then use it as an "offset" variable. 另一方面,当我在html部分中声明一个变量,然后将其用作“偏移”变量时,我的实时服务器上出现php错误。 For example: 例如:

<? $offset=0; ?>
@foreach($artists_near as $artist)

@if($offset%4==0 && $offset > 0)
<article class="MusicianCol clearfix fadeMusicBox" style="display:none;">
@endif

It is complaining at the line: 它在抱怨:

@if($offset%4==0 && $offset > 0)

saying: 说:

Undefined variable: offset

This is strange because I am seeing no errors on the localhost. 这很奇怪,因为在本地主机上看不到任何错误。 I am using the same declarations for jquery, etc.. on the pages using the blade syntax, so I should be including the same files. 我在使用刀片语法的页面上对jQuery等使用了相同的声明,因此我应该包括相同的文件。 Any ideas? 有任何想法吗?

Your production environment has the short_open_tag setting disabled. 您的生产环境已禁用short_open_tag设置。 For full compatibility its recommended that you do not turn it on and instance use the full php tag <?php instead of <? 为了完全兼容,建议您不要打开它,并且实例使用完整的php标签<?php而不是<?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel sanctum 在本地主机上工作,但在实时服务器中返回 401 unauthenticated - Laravel sanctum works in localhost, but returns 401 unauthenticated in live server 在实时服务器上未定义,但在本地主机上工作 - Undefined on live server, but WORKS on localhost 代码可在localhost上运行,但不能在实时服务器上运行 - code works on localhost but not live server javascript在localhost上工作正常,但在实时服务器上却不能 - javascript working fine in localhost but not on live server Fullpage js 在本地主机上工作正常但不在实时服务器中 - Fullpage js working fine localhost but not in live server AJAX 适用于本地主机,但不适用于实时服务器 - AJAX works on localhost, but doesn't on live server jQuery ajax调用在本地主机上有效,但在实时服务器上无效 - jquery ajax call works on localhost, but not on live server Ajax请求php在localhost上工作,但不在实时服务器上 - Ajax request to php working on localhost but not on live server jQuery Fadein和Fadeout在本地主机上工作正常,但在Web服务器上工作不正常 - jquery fadein and fadeout works fine on localhost but not on web server javascript mqtt websocket 在 localhost 中工作正常,在 https 服务器中工作正常 - javascript mqtt websocket works fine in localhost, not working in https server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM