1
我可以設置動態max_length驗證嗎?例如max_length['.$this->store->select($id)->stock.']
< - 它不工作Codeigniter中的動態最大長度值
我可以設置動態max_length驗證嗎?例如max_length['.$this->store->select($id)->stock.']
< - 它不工作Codeigniter中的動態最大長度值
只要確保,$this->store->select($id)->stock
返回有效數字:
$this->form_validation
->set_rules(
'your_field',
'Label',
'max_length['.$this->store->select($id)->stock.']'
// You can also trim it before checking length like below
//'trim|max_length['.$this->store->select($id)->stock.']'
);
這是我的模型:功能選擇(的$ id){$返回這 - > DB-> get_where( 'store',array('id'=> $ id)) - > row(); } – user3206703
@ user3206703可能存在'id'記錄可能不存在的情況,在這種情況下,如果使用'row()',然後通過' - > stock'訪問它,它可能不起作用,所以'$' row = $ this-> store-> select($ id); if(isset($ row)){$ stock = $ row-> stock; } else {/ *其他數字* /}',如果你想限制,沒有股票,那麼你可以使用'less_than [10]','max_length'是字符長度 –
@ user3206703:不用謝謝,謝謝在問題解決後接受。 –