简体   繁体   中英

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

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?

Any help would be appreciated.

Thanks.

Solved.

The form sends the data via Ajax rather than submit. Using ajax "get" turns the textarea data into single line. Changing this to ajax "post" fixes the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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