A predatory sixth-grade teacher used cellphone code names to keep his wife in the dark about an affair with his 14-year-old former student, whom he bedded at least a dozen times in his family home, Queens prosecutors said yesterday.

Daniel Reilly, 36, was arraigned on statutory-rape charges yesterday for allegedly preying on the teenager, to whom he once taught English at IS 237.

His humiliated lawyer wife, Annemarie, and her mom showed up to court to pay his $30,000 bail.

Reilly, an ex-Marine with an 11-month-old girl, initiated the relationship last year by texting “sexually graphic” messages, but she “just wanted to be friends,” law-enforcement sources told The Post.

He refused to take no for an answer, and continued to pursue her — eventually roping her into a sexual affair starting in August, prosecutors said.

He allegedly used a code name to conceal her identity on his cellphone so his wife wouldn’t find out.

The girl also used a code name for the teacher to keep it from her family and friends, authorities said.

Investigators would not release the code names because they believed it would reveal the young victim’s identity.

For their first encounter, Reilly waited until his wife and baby were away from their Forest Hills home and had the girl come over, according to the sources.

He then repeatedly asked her back to his place, where they had intercourse at least 10 times and oral sex at least twice, authorities said. They most recently hooked up on Monday, just hours before he was arrested, the sources said.

The victim’s sister allegedly discovered their secret relationship when she saw several text messages on the girl’s cellphone.

The girl — who no longer attends the school — came clean and admitted to the affair with Reilly, prosecutors said.

Her panicked mother called the school on Monday, and Reilly was yanked from his classroom until cops showed up to haul him away.

“The defendant planned to keep the relationship a secret,” a prosecutor in Queens Criminal Court charged yesterday.

Reilly is charged with second-degree rape, criminal sexual acts and endangering the welfare of a child. Prosecutors issued an order of protection for the teen.

“This case is particularly disturbing,” Queens DA Richard Brown said. “Schools should be safe havens for children. Instead, this defendant is accused of sexually preying upon one of his former students and rendezvousing with her at his residence.”

Defense attorney Eric Franz said Reilly’s family is “just happy he’s back home.”

Reilly joined the city Department of Education in 2007, when he was hired to teach English at IS 237. He earns $61,000 per year.

The teacher, who has a clean employment record, has been reassigned from the classroom while the case is investigated.

Reilly was honorably discharged in 2000 from the Marines, his lawyer said. He served in the Aircraft Maintenance Administration for five years.

He was stationed in Japan and Cherry Point, NC — and was discharged with multiple awards in 2000, a Marine spokeswoman said.

Additional reporting by Yoav Gonen