I probably haven't made the best first impression by misspelling the title

Basically I was wondering if anyone had tips on adjusting the position of your army on a defence. It's a pretty basic question, but often when the cavalry moves around to the side of my infantry line, I get stuck as to what to do. Often I play as the muslims, and I have nothing but spears to combat the cavalry with, and it's rather cumbersome to change their position.

Do I just need to have a longer infantry line, or should I try and attack their cavalry as soon as I see it getting ready to flank?

Thanks