The use of short, crude, iron knives or delicate, decorative, silver-forged utensils employed as cutlery and existing distinct and separately from things like dirks, swords, maces, bows, is not restricted.
Not every knife is a weapons and, as previously noted, the laws are not enacted with the goal to eliminate
all weapons within a city (an unrealistic goal), but to
restrict weapons within a city.
Try stuffing a morning star up your pants, Ed. I think that you'll agree that asking people to check certain weapons at a city gate will accomplish the aforementioned goal.
And, much more importantly, what about the mage who knows Fireball? Do they make him check his brain at the gates?
Why so angry with me, Ed?

To your question, laws are in place that forbid the practice of combat magic in towns and cities, though there is little that can be done to prevent its use past a polite request. After its use, however, the full force of the law (including other spell casters) can be brought to bear upon an offender.
As for fighting off the whole town, if they're gonna string you up for defending yourself, destroying them is not an evil act. Did I mention Fireball?
My point was that, unless you're playing a highly mucnhkin-ized character, killing the entire populace of a small town isn't a task easily accomplished. Further, if the legal penalty for murder is hanging and you kill the townsfolk for attempting to carry out the letter of the law, I'd argue that it's not the townsfolk who are evil —
you are.
Now, in modern law, one who commits murder may argue self defense before a jury. And if there were juries in my campaign settings, that might be a viable defense for breaking the law. At
best you get to argue self defense before a council of town elders in my settings (usually, your fate is decided by a single man, such as a Sheriff ).
So, you may (or may not) get to argue self defense in one of my campaign settings, but it isn't a "Get Out of Jail Free" card and you can't automatically assume that the friends and neighbors of the guy you just gutted are going to go out of their way to help you — a total stranger — out.
I guess a lot of that just seems like common sense to me. That said, I have been accused of placing a premium on verisimilitude when I DM. When I DM, I
also expect my players to think before they act. If you can't be bothered to do that, you'll burn through characters pretty quickly.