In my codeigniter form, I am trying to set an else if
for my data image. Currently it picks up if
when image exists. But need it to pick up my no_image.png , if no image exist using the same code below.
<?php
class Users extends MX_Controller {
public function index() {
$this->getForm();
}
protected function getForm($user_id = 0) {
$this->load->model('admin/user/users_model');
$user_info = $this->users_model->getUser($user_id);
if (trim($this->input->post('image'))) {
$data['image'] = $this->input->post('image');
} elseif (!empty($user_info)) {
// This Location Image Works Fine.
$data['image'] = config_item('base_url') . 'image/catalog/' . $user_info['image'];
} else {
// Should Display If No Image Present In Database Does Not Work.
$data['image'] = config_item('base_url') . 'image/'. 'no_image.png';
}
}
$this->load->view('user/users_form', $data);
}
View Page :
<div class="form-group">
<label for="input-image" class="col-lg-2 col-md-12 col-sm-2 col-xs-12"><?php echo $entry_image; ?></label>
<div class="col-lg-10 col-md-10 col-sm-10 col-xs-12">
<a href="" id="thumb-image" data-toggle="image" class="img-thumbnail">
<img src="<?php echo $image; ?>"/>
</a>
</div>
</div>
Make sure that in image folder the no_image.png exists. And it is accessible directly.Like , you can try directly open the link in your browser as http://www.yoursiteurl/image/no_image.png .
If it opens then there is two possibilities
in your config file there is no end slash for baseurl.
The code never executes the else block
If the dierct link does not open then a htaccess problem may exists.
Hope this will help you.
Or your elseif condition may be like this
elseif(!empty($user_info) && $user_info['image'] && file_exists(config_item('base_url') . 'image/catalog/' . $user_info['image'])){
...
}
// + so your user info is valid but user picture is not available
I had to create a if statement below to make it work for no_image.png now works this way.
if (trim($this->input->post('image'))) {
$data['image'] = $this->input->post('image');
} elseif (!empty($user_info)) {
$data['image'] = config_item('base_url') . 'image/catalog/' . $user_info['image'];
} else {
$data['image'] = '';
}
if ($user_info['image'] == FALSE) {
$data['image'] = config_item('base_url') . 'image/'. 'no_image.png';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.