To be fair, a properly mulched bed is going to suffer very little loss from dogs walking across them or even laying down on top of them. However, if you get playful dogs accelerating, decelerating and making 180 degree racing turns on top of the freshly transplanted broccoli, its going to be a brassica holocaust.
When you want to teach a new rule to a dog, there are 3 things to keep in mind: make sure the dog understands what the rule is, give the dog incentive to follow the rule and be realistic about the dogs cognitive ability. In this case, the dog needs to be taught which areas are off limits (the vegetable beds) reprimanded immediately when it transgresses the boundaries, and the human needs to realize that the dog can not distinguish between your prized cabbage and the bush it pees on every morning. After all, they are both green and leafy.
First strategy i heard second hand but have not tried it myself, is to teach the dog to fear wire. Get a 9 volt battery and connect a length of wire. Stretch the wire somewhere that Fido is going to go snooping (I might leave this in front of my open bedroom door since that is off limits anyways, and kill two birds with one stone) and assuming Fido is anywhere near average intelligence, he will quickly learn an aversion to wire. After this, it is a simple matter of bordering the no-go zones with wire in order to repel the furry marauder. Is it mean to let your beloved pooch get zapped a few times? Perhaps. But it is much more humane than letting him piss off your neighbors until they start leaving out rat poison laced meat (true story). The dog understands that wire bordered territory is off limits, anticipates a shock if it trasngresses this border (incentive) and is more than capable of learning that wire = pain. Now if only I can find a way to equate garbage can contents = ass whoopin', i'll be a happy dog owner.
The strategy i personally employed is to encircle the growing area with three strands of cord with the top one being knee height. This very clearly marks an area in a way that even a dog can understand. The incentive, however needs to come from the humans. Rocks work very well for this (fuck you PETA). the dog wont need to get pelted with a pebble more than once or twice to get the message. This is going to work even better if your dog already knows the "leave it" and "out" commands.
Like almost every situation, an untrained dog is a liability while a trained one is the ultimate companion. Once Fido gets the message, there is no reason to expel him from the garden.