简体   繁体   English

原则:textarea换行符和nl2br

[英]Doctrine: textarea line breaks & nl2br

I'm pulling my hair out with something that should be very simple: getting line breaks to show up properly in text that's returned from the database with Doctrine 1.2 我要用一种非常简单的方法来解决问题:使用Doctrine 1.2从数据库返回的文本中获得换行符以正确显示

I'm saving a message: 我正在保存一条消息:

    $body = [text from a form textarea];

    $m = new Message();
    $m->setSubject($subject);
    $m->setBody($body);
    $m->save();

Querying the message: 查询消息:

$q = Doctrine_Query::create()
    ->from('Message m')
    ->where('m.message_id = ?', $id)
    ->limit(1);
$this->message = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);

In my template: 在我的模板中:

echo $message[0]['body'] ... outputs the text without line breaks
echo nl2br($message[0]['body']) ... no difference

... and I've tried every combination I could think of. ...并且我尝试了所有我能想到的组合。

Is Doctrine doing something to line breaks that's affecting this, or is there something that I'm just missing? Doctrine是否正在做一些换行符来影响这一点,或者我只是缺少什么?

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks. 谢谢。

Solved. 解决了。

The form sends the data via Ajax rather than submit. 该表单通过Ajax发送数据,而不是通过提交。 Using ajax "get" turns the textarea data into single line. 使用ajax“ get”可以将textarea数据转换为单行。 Changing this to ajax "post" fixes the problem. 将此更改为ajax“发布”即可解决此问题。

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

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