I am having a trouble on what ways will i do, when i change this $this->load->view('profile',['getPlacetype'=>$getPlacetype],$custom_errors ); to this $this->load->view('profile',['getPlacetype'=>$getPlacetype],$custom_errors ); there will be no undefined index but the selection data will be none
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>
It's not hard to send lots of data to a view. The thing to understand is how the array you send to the view is used. Put simply, each key
in the array will be the name of a variable
in the view. The array must be an associative array.
With that in mind
//this line
$getPlacetype = $this->Placetype->getPlacetype();
// should be changed to this
$view_data['getPlacetype'] = $this->Placetype->getPlacetype();
and then
$custom_errors["nadate"] = ($this->verifydate($_POST["startdate"],
// changed to
$nadate = ($this->verifydate($_POST["startdate"],
$_POST["enddate"]) < 3 ? false : true);
You can delete the line
$custom_errors["nadate"] = false;
Change this
if($this->form_validation->run() == TRUE &&
$this->verifydate($_POST["startdate"], $_POST["enddate"]) < 3) {
to
if($nadate === TRUE && $this->form_validation->run() === TRUE) {
If the above block is not executed then create an error message and load the view
$view_data['custom_errors'] = "Start and End dates were wrong";
$this->load->view('profile', $view_data);
The relevant part of the view could be done like this.
<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>
Hope this demonstrates how to do what you want.
try this:define array blank.
public function index(){
$data = array();
//here you can use $data and like firstArray you can pass in your view page.you can use multiple array like this and pass then in view.
$data['firstArray']=get data;
$data['secondArray']=get data;
$this->load->view(''profile', $data);
}