[英]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.