You don't have to search the students. Or even put the phones in a locker. You just make the rules about them known, and if students are found using a phone during class, they can just be punished with detention/suspension.
I don't understand why this is hard to enforce, or requires special laws. We had rules about not using (feature) phones back when I was in middle school (~2002), and you just kept your phone in your backpack/pocket until the class was over. It worked.