Since you're new to cake,I think it's not a good idea to start from HABTM relationship which is what you need in your question and also the most complicated one.So I assume your models relationship as a easier one :hasMany.E.g as follows:
/*this is your state model
*state table in database should like:id,name
*and business table in database:id,name,state_id
*/
class State extends AppModel
{
var $name = 'State';
var $hasMany = array(
'Business'=>array(
'className'=>'Business',
'foreignKey'=>'state_id',
)
); //this means a State can hasMany Businesses while a Business only belongs to one State
}
Then make the action in your state controller as this:
/*in your state controller*/
function showBusinessesByState($statename)
{
if($statename && $thestate = $this->State->findByName($statename))
{
$this->set('state',$thestate);//debug $thestate you'll find data you need
}
else
{
$this->Session->setFlash("something wrong happens!");
}
}
Now I think you may handle the view file yourself,with a $state
variable to retrieve the data $thestate
which also contains a businesses list in it.
Now in the /app/config/routes.php do the routing part:
Router::connect('/states/*',array('controller'=>'states','action' => 'showBusinessesByState'));
After finish that you may get what you need with /states/somestate
.When you go through this,you may try to solve this with the best way --hasAndBelongsToMany.