I have a section of my code that is causing my whole page to load white with no error message.
I have debuged my code and the following section is causing my issue but I cannot work out why:
Problem Code:
if($this->image_model->updatePage($id, $caption)) {
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
}//END if updatePage
Full Controller Document:
function index(){
if(!$this->session->userdata('logged_in'))redirect('admin/home');
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
if ($this->input->post('submit')){
#The User has submitted updates, lets begin!
#Set The validation Rules
$this->form_validation->set_rules('captionInput', 'Caption', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE){ #Form Validation Fails Load The Default Page
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['con开发者_运维知识库tent'] into it
}// END Form Validation
#Form Validation passed, so lets continue updating.
#lets set some variables to pass into the database for editing.
$caption = $this->input->post('captionInput', TRUE);
$this->db->escape($caption); # Lets check for security and mel objects :)
#Now if imageCaption fails to update the database then show "there was a problem".
if($this->image_model->updatePage($id, $caption)) {
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
}//END if updatePage
}else{
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
} //END Submit
} //END function index()
}
Image Model:
class Image_model extends CI_Model
{
function __construct() {
parent::__construct();
}
function getImages($path = NULL) {
foreach($this->db->get('images')->result_array() as $r) {
$rows[] = $r;
}
return $rows;
}
function addImage($imgdata) {
$this->db->insert('images',$imgdata);
return;
}
function deleteimage($id){
$this->db->where('id', $id);
$q = $this->db->get('images');
$row = $q->row_array();
if ($q->num_rows() > 0){
//delete from the database
$this->db->where('id', $id);
$this->db->delete('images');
//lets delete the image
unlink("includes/uploads/gallery/".$row['imagename']);
//lets delete the thumb.
unlink("includes/uploads/gallery/thumbs/".$row['thumbname']);
}//END if num_rows
}//END function deleteImage($id)
function updateCaption($id = NULL, $caption = NULL){
#set the $data passed to the function into an array, content being the column name.
$data = array('description' => $caption);
$this ->db->where('id',$id);
$this->db->update('images', $data);
return TRUE;
}
}//END class Image_model
In your controller is $this->image_model
an instance of your Image_Model
class? If so, in the model you posted, there does not appear to be an updatePage()
method .
Assuming that it has nothing to do with this:
} //END function index()
}
Have you confirmed that you're not suppressing errors? What do your error logs say?
In your controller document, where you have this block of code towards the end, remove the extra } that you have before the else keyword
if($this->image_model->updatePage($id, $caption)) {
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
}/*END if updatePage*/
}else{
$data['title'] = 'Image Captions';
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['get_images'] = $this->image_model->getImages();
$data['content'] = $this->load->view('admin/imagecaption', $data, TRUE); #Loads the "content"
$this->load->view('admintemplate', $data); #Loads the given template and passes the $data['content'] into it
}
精彩评论