Im creating a dependent dropdown & everything works fine for me.
CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('ajax/subcategories'),
'update'=>'#city_id', //selector to update
)));
AjaxController.php
class AjaxController extends Controller
{
...
}
Now I want to hide the url "mydomain.com/ajax/subcategories". If anyone tries to directly access this url it'll show a 404 error page. Is this possible?
If you are issuing a POST ajax request (which it looks like you are), you can wrap your action in a check like this:
class AjaxController extends Controller {
public function actionSubcategories() {
if(Yii::app()->request->isPostRequest) { // check if POST
// your action logic goes here
} else { // direct URL request will be GET, so show error
throw new CHttpException(404, Yii::t('app', 'Invalid request.'));
}
}
}
I regular "direct" request for that URL will be a GET request, so this will show them a 404 error.