繁体   English   中英

PHP,CakePHP,HTML:锚标签附加在代码标签内,如何分隔此锚标签?

[英]PHP,CakePHP,HTML: The anchor tag is appended inside a code tag, how can seperate this anchor tag?

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>';

“更多”链接/锚附加一个帖子的时候我交东西的内容/体。

我该如何休息/停止“更多”成为身体的要素?

我将以下行作为帖子的内容或正文,但这将是一个单独的链接。

<a href="/posts/view/37" id="id_anchor_more" class="class_anchor_more">more</a>

链接应该在里面:

<table>
<tr>
<td>Content..Data.. <br/>'more' </td>
<td>Edit</td>
<td>Delete</td>
</tr>
</table>

有人可以帮我解决这个问题吗?

无法将正文和“更多”放在同一列<td> ,问题是当我将某些代码放在标记<pre class="brush: cpp"> ...body.. </pre>时,我正在使用语法高亮http://alexgorbatchev.com/SyntaxHighlighter/ <pre class="brush: cpp"> ...body.. </pre>然后出现问题。

HTML结构无效。 链接后您缺少结束符</td>

这也是使用HTML帮助器创建表的一个好主意的原因:它消除了错误丢失标签的机会。

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

我认为通过这种方式编写起来会更容易阅读,并且我已经在我的工作CakePHP项目中对其进行了测试,将$post['Post']['body']替换$post['Post']['body']带有html标记的某些文本,并且可以正常工作很好,请注意,我不会更改您的原始代码,只是删除回声。

我怀疑您的$post['Post']['body']可能包含使您的链接成为纯文本的内容,请尝试使用div或其他内容将其括起来

<div>
    <?php 
    echo $this->Text->truncate(
        $last_paragraph,
        150,
        array('ending' => '...', 'exact' => false)
    );?>
</div>

尝试这个

    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>';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM