dongtun1872 2011-10-29 19:58
浏览 37
已采纳

AjaxController yii

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?

  • 写回答

1条回答 默认 最新

  • duaijiao0648 2011-10-30 16:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器