【问题标题】:cakePHP - how can i manipulate fields before query?cakePHP - 我如何在查询之前操作字段?
【发布时间】:2014-05-26 09:40:09
【问题描述】:

在我的数据库中有几个常见的列(nametype)。例如:notesremarks等。

我想操纵每个查询以将它们格式化。继续示例:在查询本身中替换 /n/r/n,使用 <br/>

问题是:如果我将在beforeFind() 中添加此过滤器,我将不得不为每个查询指定字段。毫无意义。

afterFind() 中这样做,使用nl2br() 将是一种过度杀伤,将需要不需要的资源,因为此查询不到所有查询的 10%。

【问题讨论】:

    标签: mysql callback cakephp-1.3


    【解决方案1】:

    beforeFind 肯定是放错地方了,因为还没有返回任何数据。

    在 afterFind 中是可能的,但不是很明智。

    为什么不创建一个 Helper 并直接在 View 中调用呢?

    <?= $this->Helpername->methodname($input) ?>

    而且因为 CakePHP 开箱即用地解决了您的大部分问题,请查看 TextHelper::autoParagraph 方法!

    http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoParagraph

    <?= $this->Text->autoParagraph($input) ?>

    【讨论】:

    猜你喜欢
    • 2011-09-19
    • 2012-01-01
    • 1970-01-01
    • 2015-06-06
    • 2018-10-09
    • 2022-01-15
    • 1970-01-01
    • 2022-07-07
    • 2016-01-30
    相关资源
    最近更新 更多