echo '<tr class="class_row">';
echo '<td>';
echo $this->Html->link($post['Post']['title'],
array('controller'=>'posts','action'=>'view',$post['Post']['id']),
array('id'=>'id_anchor_title','class'=>'class_anchor_title') );
echo '<h6><i>'.$this->Time->format('d-M-Y',strtotime($post['Post']['created'])).'</i></h6>';
echo '<br/>';
$last_paragraph=$post['Post']['body'];
$length = strlen($last_paragraph);
echo $this->Text->truncate($last_paragraph,150,array('ending' => '...','exact' => false));
echo '<br/>';
//echo debug($last_paragraph);
if($length > 151){
echo $this->Html->link('more',
array('controller'=>'posts','action'=>'view',$post['Post']['id']),
array('id'=>'id_anchor_more','class'=>'class_anchor_more') );
}
echo '</td>';
echo '<td>'.$this->Html->link('Edit',
array('controller'=>'posts','action'=>'edit',$post['Post']['id']) ).'</td>';
echo '<td>'.$this->Html->link('Delete',
array('controller'=>'posts','action'=>'delete',$post['Post']['id'])).'</td>';
echo '</td>';
echo '</tr>';
The 'more' link/anchor is appended as a content/body of a post when I post something.
How can I make/put a break and stop 'more' being an element of body?
I got the following line as a content or body of a post, but it will a separate link.
<a href="/posts/view/37" id="id_anchor_more" class="class_anchor_more">more</a>
The link should be inside:
<tab开发者_开发知识库le>
<tr>
<td>Content..Data.. <br/>'more' </td>
<td>Edit</td>
<td>Delete</td>
</tr>
</table>
Can someone help me to fix this problem ?
Isn't possible to have the body and 'more' in same column <td>
the problem is I'm using syntaxhighlighter http://alexgorbatchev.com/SyntaxHighlighter/, when I put some code inside tag <pre class="brush: cpp"> ...body.. </pre>
then the problem occurs.
<style>
table tr td h6{font-style: italic;}
</style>
<tr class="class_row">
<td>
<?php
echo $this->Html->link($post['Post']['title'],
'/posts/view'.$post['Post']['id'],
array('id'=>'id_anchor_title','class'=>'class_anchor_title')
);?>
<h6><?php echo $this->Time->format('d-M-Y',strtotime($post['Post']['created']));?></h6>
<br/>
<?php
$last_paragraph=$post['Post']['body'];
$length = strlen($last_paragraph);
echo $this->Text->truncate($last_paragraph,150,array('ending' => '...','exact' => false));
?>
<br/>
<?php
if($length > 151){
echo $this->Html->link('more', '/posts/view'.$post['Post']['id'],
array('id'=>'id_anchor_more','class'=>'class_anchor_more')
);
}
?>
</td>
<td><?php echo $this->Html->link('Edit', '/posts/edit'.$post['Post']['id']);?></td>
<td><?php echo $this->Html->link('Delete', '/posts/delete'.$post['Post']['id']);?></td>
</tr>
I think it would be easier to read by writing it this way, and i have tested this on my working cakePHP project, replacing $post['Post']['body']
with some text with html tags in it, and it works just fine, notice that i don't change your original codes, just removing the echos.
i suspect that your $post['Post']['body']
probably contain something that make your link a plain text, try enclosing it with a div or something
<div>
<?php
echo $this->Text->truncate(
$last_paragraph,
150,
array('ending' => '...', 'exact' => false)
);?>
</div>
The HTML structure is invalid. You're missing a closing </td>
after the link.
This is also why it's a good idea to use the HTML helper to create tables: it eliminates the chance of missing tags by mistake.
Try this
echo '<tr class="class_row">';
echo '<td>';
echo $this->Html->link($post['Post']['title'],
array('controller'=>'posts','action'=>'view',$post['Post']['id']),
array('id'=>'id_anchor_title','class'=>'class_anchor_title') );
echo '<h6><i>'.$this->Time->format('d-M-Y',strtotime($post['Post']['created'])).'</i></h6>';
echo '<br/>';
$last_paragraph=$post['Post']['body'];
$length = strlen($last_paragraph);
echo $this->Text->truncate($last_paragraph,150,array('ending' => '...','exact' => false));
echo '</td>';
if($length > 151){
echo '<td>'.$this->Html->link('more',
array('controller'=>'posts','action'=>'view',$post['Post']['id']),
array('id'=>'id_anchor_more','class'=>'class_anchor_more') ).'</td>';
}
echo '</td>';
echo '<td>'.$this->Html->link('Edit',
array('controller'=>'posts','action'=>'edit',$post['Post']['id']) ).'</td>';
echo '<td>'.$this->Html->link('Delete',
array('controller'=>'posts','action'=>'delete',$post['Post']['id'])).'</td>';
echo '</tr>';
精彩评论