当我更改此$ this-> load-> view('profile',['getPlacetype'=> $ getPlacetype],$ custom_errors)时,我在做什么方面遇到麻烦。对此 $ this-> load-> view('profile',['getPlacetype'=> $ getPlacetype],$ custom_errors); 没有未定义的索引,但是选择数据将没有
profilecon
public function index(){
$this->load->model('Placetype');
$getPlacetype = $this->Placetype->getPlacetype();
if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {
header("Location: ".base_url()."index.php/login_con/login");
die();
}
$custom_errors["nadate"] = false;
if (isset($_POST['profile'])) {
$this->form_validation->set_rules('mobilenum', 'Mobile Number',
'required');
$this->form_validation->set_rules('homeadd', 'Home Address',
'required');
$this->form_validation->set_rules('startdate', 'Start Date',
'required');
$this->form_validation->set_rules('enddate', 'End Date',
'required');
$custom_errors["nadate"] = ($this->verifydate($_POST["startdate"],
$_POST["enddate"]) < 3 ? false : true);
//if form validation true
if($this->form_validation->run() == TRUE && $this-
>verifydate($_POST["startdate"], $_POST["enddate"]) < 3) {
$data = array(
'username' => $this->session->userdata("username"),
'mobilenum' => $_POST['mobilenum'],
'homeadd' => $_POST['homeadd'],
'startdate' => $_POST['startdate'],
'enddate' => $_POST['enddate'],
);
$_SESSION["profile_data"] = $data;
redirect("shopping_cart","refresh");
}
}
$this->load->view('profile',
['getPlacetype'=>$getPlacetype],$custom_errors );
}
placetype_model
<?php
class Placetype extends CI_MODEL{
public function getPlacetype(){
$query = $this->db->get('placetype');
if($query->num_rows() > 0){
return $query->result();
}
}
}
profile_view
<div class="form-group">
<label for="place_type">City/Province</label>
<select name="place_type">
<option value="place_type">-Please Select One-</option>
<?php if(count($getPlacetype)):?>
<?php foreach($getPlacetype as $getplacetype):?>
<option value=
<?php echo $getplacetype->place_id;?>>
<?php echo $getplacetype->place_type;?>
<?php echo $getplacetype->place_price;?><span> PHP Shipping
Fee</span>
</option>
<?php endforeach;?>
<?php else:?>
<?php endif;?>
</select>
</div>
<button class="btn btn-primary btn-block"
name="profile">Proceed</button>
</div>
</form>
</div>
答案 0 :(得分:0)
向视图发送大量数据并不难。要了解的是如何使用发送到视图的数组。简而言之,数组中的每个key
都是视图中variable
的名称。该数组必须是关联数组。
请记住
//this line
$getPlacetype = $this->Placetype->getPlacetype();
// should be changed to this
$view_data['getPlacetype'] = $this->Placetype->getPlacetype();
然后
$custom_errors["nadate"] = ($this->verifydate($_POST["startdate"],
// changed to
$nadate = ($this->verifydate($_POST["startdate"],
$_POST["enddate"]) < 3 ? false : true);
您可以删除该行
$custom_errors["nadate"] = false;
更改此
if($this->form_validation->run() == TRUE &&
$this->verifydate($_POST["startdate"], $_POST["enddate"]) < 3) {
到
if($nadate === TRUE && $this->form_validation->run() === TRUE) {
如果未执行上述代码,则创建一条错误消息并加载视图
$view_data['custom_errors'] = "Start and End dates were wrong";
$this->load->view('profile', $view_data);
视图的相关部分可以这样完成。
<div class="form-group">
<label for="place_type">City/Province</label>
<select name="place_type">
<option value="place_type">-Please Select One-</option>
<?php
if(count($getPlacetype)) :
foreach ($getPlacetype as $getplacetype):
?>
<option value=<?php echo $getplacetype->place_id; ?>>
<?php
echo $getplacetype->place_type;
echo $getplacetype->place_price;
?>
<span> PHP Shipping Fee</span>
</option>
<?php
endforeach;
else:
echo isset($custom_errors) ? $custom_errors : NULL;
endif;
?>
</select>
</div>
希望这演示了如何做您想做的事。
答案 1 :(得分:0)
尝试一下:将数组定义为空白。
public function index(){
$data = array();
///在这里您可以使用$ data和firstArray之类的内容,您可以在视图页面中传递。
$data['firstArray']=get data;
$data['secondArray']=get data;
$this->load->view(''profile', $data);
}