使用运行在XAMPP Server上的CakePHP和PHP 5.3.5我一直收到错误消息 语法错误,意外T_CONSTANT_ENCAPSED_STRING第38行
第38行是'已发布',
守则
<div id="center_content">
<h2>Post Listings</h2>
<p>Here is a list of existing posts</p>
<div>
</div>
<?php
if (isset($posts) && is_array($posts))
{
?>
<table>
<tr>
<td>
<b>ID</b>
</td>
<td>
<b>title</b>
</td>
<td>
<b>content</b>
</td>
<td>
<b>Last Modified</b>
</td>
<td>
<b>published<b>
</td>
<td colspan="2"><b> Action</b></td>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id'];?></td>
<td><?php echo $post['Post']['title'];?></td>
<td><?php echo $post['Post']['content'];?></td>
<td><?php echo $post['Post']['modified'];?></td>
<td>
<?php echo $html->link(ife(
$post['Post']['published'] == 1',
'Published',
'Unpublished),
'/posts/'.ife($post['Post']['published'] == 1',
'disabled','enable').'/'.$post['Post']['id']
);
?>
</td>
<td>
<?php echo $html->link(
'Edit',
'/posts/edit'.$post['Post']['id']);?>
</td>
<td>
<?php echo $html->link(
'Delete',
'/posts/delete/'.$post['Post']['id']);?>
</td>
</tr>
<? endforeach; ?>
<?php
if (sizeof($posts) == 0) {
?>
<tr style= "background-color:#cccccc;">
<td colspan="6">
<span style="font-size: 17px;">
No post found.
</span>
</td>
</tr>
<?php
}
?>
</table>
<br/>
<?php
}
?>
</div>
多数事实,请注意我使用CakePHP MVC Framework
运行PHP 5.3.5的应用程序答案 0 :(得分:5)
从
更改 <?php echo $html->link(ife(
'$post['Post']['published'] == 1',
'Published',
'Unpublished'),
'/posts/'.ife('$post'['Post']['published'] == 1',
'disabled','enable').'/'.$post['Post']['id']
);
?>
到
<?php echo $html->link(ife(
$post['Post']['published'] == 1',
'Published',
'Unpublished),
'/posts/'.ife($post['Post']['published'] == 1',
'disabled','enable).'/'.$post['Post']['id']
);
?>
您只需要在$ post
之前删除单引号答案 1 :(得分:1)
尝试使其更具可读性:
$isPublished = ($post['Post']['published'] == 1) ? true : false;
echo $html->link(
ife($isPublished, 'Published','Unpublished'),
'/posts/' . ife($isPublished, 'disabled', 'enable') . '/' . $post['Post']['id']
);
答案 2 :(得分:1)
$post['Post']['published'] == '1',
答案 3 :(得分:0)
这对我有用......你有一个旧式的php标签,并且在错误的位置有单引号。
我不确定“ife”是什么,很可能是if语句错了?
<div id="center_content">
<h2>Post Listings</h2>
<p>Here is a list of existing posts</p>
<div>
</div>
<?php
if (isset($posts) && is_array($posts))
{
?>
<table>
<tr>
<td>
<b>ID</b>
</td>
<td>
<b>title</b>
</td>
<td>
<b>content</b>
</td>
<td>
<b>Last Modified</b>
</td>
<td>
<b>published<b>
</td>
<td colspan="2"><b> Action</b></td>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id'];?></td>
<td><?php echo $post['Post']['title'];?></td>
<td><?php echo $post['Post']['content'];?></td>
<td><?php echo $post['Post']['modified'];?></td>
<td>
<?php echo $html->link(
($post['Post']['published'] == 1 ? 'Published' : 'Unpublished'),
'/posts/' .
($post['Post']['published'] == 1 ? 'disabled' : 'enabled') .
'/' . $post['Post']['id']
);
?>
</td>
<td>
<?php echo $html->link(
'Edit',
'/posts/edit'.$post['Post']['id']);?>
</td>
<td>
<?php echo $html->link(
'Delete',
'/posts/delete/'.$post['Post']['id']);?>
</td>
</tr>
<?php endforeach; ?>
<?php
if (sizeof($posts) == 0) {
?>
<tr style= "background-color:#cccccc;">
<td colspan="6">
<span style="font-size: 17px;">
No post found.
</span>
</td>
</tr>
<?php
}
?>
</table>
<br/>
<?php
}
?>
</div>