Welcome Guest, Not a member yet? Register   Sign In
Screen is blank when I add call to another method in different model?
#1

[eluser]gypmaster[/eluser]
Hi,

Noob here ... just starting out (again) with CI and I'm messing around with it.
I've got my db set up and have started writing controllers, models and views.

The index() method in my controller generates a list of Properties, next to each Property is a link to view to view the Property details, the link is handled by the view() method. Got a problem though.

Here's my controller:
Code:
<?php
class Property extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('mproperty');
  $this->load->model('mroom');  
      $this->load->database();
      $this->load->helper('url');
      $this->load->library('firephp');

}

public function index()
{
  $data['property'] = $this->mproperty->get_all();
  $data['title'] = 'All Properties';
  $this->load->view('v_all', $data);
}


public function view($propid)
{

  $data['property'] = $this->mproperty->get_single($propid);
  $data['rooms'] = $this->mroom->get_all($propid);
  $data['title'] = 'View Property';
  $this->load->view('v_prop_single', $data);
}
  
}

Here are the models:
Code:
<?php
class Mproperty extends CI_Model {

public function __construct()
{
$this->load->database();
}

public function get_single($propid)
{
$query = $this->db->get_where('property', array('propid' => $propid));
return $query->row_array();
}

public function get_all()
{
$query = $this->db->get('property');
return $query->result_array();
}


}
<?php
class Mroom extends CI_Model {

public function __construct()
{
$this->load->database();
}

public function get_single($propid, $roomid)
{
$query = $this->db->get_where('room', array('propid' => $propid, 'roomid'=>$roomid));
return $query->row_array();
}

public function get_all($propid)
{
$query = $this->get_where('room', array('propid' => $propid));
return $query->result();
}


}
Problem is that the line:
Code:
$data['rooms'] = $this->mroom->get_all($propid);
seems to 'break the whole thing. I f I take that line out then the view displays as I would expect. I f I leave the line in, the view simply displays a blank screen.
Anyone know what I'm doing wrong?
Thanks,
Mark.
#2

[eluser]painkiller[/eluser]
How do you handle $rooms in your view? You use result_array() in all your models and result() in the one making you problems, result would return you the data wrapped around an stdObject ? Does the view load?
#3

[eluser]TheFuzzy0ne[/eluser]
There are two causes that I know of.

1) You have enabled compression, and you have a whitespace somewhere being output prematurely.
2) Error reporting is disabled, or set too low.

If it's the latter, try putting this at the top of your index.php file:
Code:
ini_set('display_errors','1');
error_reporting(E_ALL);

You should find all errors are now displayed.
#4

[eluser]gypmaster[/eluser]
When I click on the link to which calls the view method the following appears in my browser address bar:

http://localhost/codeIgniter/index.php/property/view/7

But the screen is completely blank.

btw, I've changed the model to use result_array() but it made no difference.

here's the view
Code:
<?php
echo '<h2>'.$property['title'].'</h2>';
echo $property['address1']."<BR>".$property['address2']."<BR>".$property['address3']."<BR>".$property['postcode']."<BR>".$property['area']."<BR>";

foreach ($rooms as $room_item)
{
  echo "<p>".$room_item['roomid']."<BR>";
}
Thanks
#5

[eluser]gypmaster[/eluser]
TheFuzzyOne, thanks.

setting the error reporting showed me that I'd mistyped the get_where in the mroom model.

I've corrected the error and now it works as it should.

thanks again.
#6

[eluser]TheFuzzy0ne[/eluser]
Glad to be of service. Just don't forget to disable error reporting on your production server. Wink




Theme © iAndrew 2016 - Forum software by © MyBB