V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
cheng12308
V2EX  ?  问与答

一个 Yii 初学者的困扰,百思不得其解。

  •  
  •   cheng12308 · 2017-04-20 10:01:13 +08:00 · 1709 次点击
    这是一个创建于 2578 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    需求是这样的:在上传文件的同时让选择文件所属的分类。

    1.Model 中:一个 uploadForm 继承 model 。字段 public $reportFiles; public $category;

    2.controller 中是这样。 $model = new UploadForm(); $cat=Category::getAllCats();

        if ($model->load(Yii::$app->request->post()) ) {}
    

    可是能获取到文件,获取到的 category 为空。 ["category"]=> NULL ["_errors":"yii\base\Model":private]=> NULL

    3.view 中:

    field($model,'category')->dropDownList($cat)?>

    这是什么问题啊,困扰了一天了。取不到分类的值。

    3 条回复  ?  2017-04-20 11:15:14 +08:00
    cheng12308
        1
    cheng12308  
    OP
       2017-04-20 10:02:24 +08:00
    1
    cheng12308
        2
    cheng12308  
    OP
       2017-04-20 10:04:51 +08:00
    被降权了,没人看的着,郁闷。
    young
        3
    young  
       2017-04-20 11:15:14 +08:00
    试一下, 在 model 文件中 rules 方法里设置一下这个 category 字段的 validator
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2876 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:46 · PVG 20:46 · LAX 05:46 · JFK 08:46
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com