web-dev-qa-db-fra.com

t_CONSTANT_ENCAPSED_STRING inattendu

J'utilise CakePHP sur un serveur XAMPP avec PHP 5.3.5. Je continue à recevoir le message d'erreur , Erreur de syntaxe inattendue, ligne T_CONSTANT_ENCAPSED_STRING 38

La ligne 38 est "publiée",

Le code

<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>&nbsp;&nbsp;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>

C'est tout, Notez que je lance l'application avec PHP 5.3.5 en utilisant CakePHP MVC Framework

4
user2721794

Le changer de

 <?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']
);
?>

Vous avez juste besoin de supprimer la citation simple juste avant $ post

5
Michael King
 $post['Post']['published'] == '1', 
1
Vlad

Essayez de le rendre un peu plus lisible: 

$isPublished = ($post['Post']['published'] == 1) ? true : false;

echo $html->link(
  ife($isPublished, 'Published','Unpublished'),
  '/posts/' . ife($isPublished, 'disabled', 'enable') . '/' . $post['Post']['id']
);
1
AlexP

Cela fonctionne pour moi ... Vous aviez un tag PHP de style ancien et des guillemets simples aux mauvais endroits.

Je ne sais pas ce que "ife" est, probablement une déclaration si a mal tourné?

<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>&nbsp;&nbsp;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>
0
John