Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected T_CONSTANT_ENCAPSED_STRING

Tags:

html

php

cakephp

Am using CakePHP running on XAMPP Server with PHP 5.3.5 i keep getting the error message syntax error, unexpected T_CONSTANT_ENCAPSED_STRING Line 38

Line 38 is 'Published',

The 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>

Thats all, Note am running the app with PHP 5.3.5 using CakePHP MVC Framework

like image 208
user2721794 Avatar asked Feb 16 '23 05:02

user2721794


2 Answers

Change it from

 <?php echo $html->link(ife(
'$post['Post']['published'] == 1', 
'Published',
'Unpublished'),
'/posts/'.ife('$post'['Post']['published'] == 1',
'disabled','enable').'/'.$post['Post']['id']
);
?>

to

<?php echo $html->link(ife(
$post['Post']['published'] == 1', 
'Published',
'Unpublished),
'/posts/'.ife($post['Post']['published'] == 1',
'disabled','enable).'/'.$post['Post']['id']
);
?>

You just needed to remove the single quote right before $post

like image 142
Michael King Avatar answered Feb 24 '23 01:02

Michael King


Try and make it a bit more readable:

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

echo $html->link(
  ife($isPublished, 'Published','Unpublished'),
  '/posts/' . ife($isPublished, 'disabled', 'enable') . '/' . $post['Post']['id']
);
like image 45
AlexP Avatar answered Feb 24 '23 02:02

AlexP