• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Models won't load

#11
(12-08-2014, 06:21 PM)afenker1985 Wrote: Okay, let me lay this out again. I'm developing on OpenShift by Red Hat. I've setup application just as the tutorial/walkthrough says to. I can't get models to load, and I keep getting a 500 error. I've checked the log files.

When I load the webpage I get this in the logs:

Code:
[08/Dec/2014:20:13:52 -0500] "GET / HTTP/1.1" 500 - "http://2scsb-aaronfenker.rhcloud.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25"

If the filename of my model includes "_model, “ the page gives the CI error message, but it still throws the 500 error. If I don't include "_model" in the filename, then the page doesn't load at all, but it still throws the 500 error.

When I do a git push I get the following errors:

Code:
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"

I deleted my original app, and started fresh just in case I goofed on something in pushes. (Git is new to me too.)

Here's my code again.

controllers/welcome.php

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {

    
/**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -  
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    
public function index()
    {
        
$this->load->model('Nav_menu');
        
$this->load->view('header');
        
$this->load->view('welcome_message');
        
$this->load->view('footer');
    }
    private function 
create_menu() {
        
$data['query'] = $this->Nav_menu->get_active_albums();
     
   echo $data;
 
  }


models/nav_menu.php

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Nav_menu extends CI_Model {
    function 
__construct() {
     
       parent::__construct();
    }
    
    function 
get_active_albums() {
        
$query $this->db->get_where('albums', array('is_active' 1));
        
        return 
$query->result();
    }


Is there a setting that I'm missing somewhere?

Also set your methods in model to public.
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
Reply

#12
Thanks Dracula. I did all that. Still nothing. And yes, I am using CI 2.
Reply

#13
(12-09-2014, 06:57 AM)afenker1985 Wrote: Thanks Dracula. I did all that. Still nothing. And yes, I am using CI 2.

Oh...create a construct method an load the model there in your controller... like this:

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {
 
  

   
public function __construct() {
 
      parent::__construct();

 
      $this->load->model('nav_m');
 
  }


 
   public function index()
 
     
        $this
->load->view('header');
 
       $this->load->view('welcome_message');
 
       $this->load->view('footer');
 
   }
 
   private function create_menu() {
 
       $data['query'] = $this->nav_m->get_active_albums();
 
       echo $data;
 
  }

Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
Reply

#14
I did all that. I decided to change my model's filename to "nav_m_model.php" When I do that, I at least get the CI error message: "Unable to locate the model you have specified nav_m." But I'm still throwing the error
Quote:"GET / HTTP 1.1" 500 1183 "-"
Reply

#15
(12-08-2014, 06:21 PM)afenker1985 Wrote: Okay, let me lay this out again. I'm developing on OpenShift by Red Hat. I've setup application just as the tutorial/walkthrough says to. I can't get models to load, and I keep getting a 500 error. I've checked the log files.

When I load the webpage I get this in the logs:

Code:
[08/Dec/2014:20:13:52 -0500] "GET / HTTP/1.1" 500 - "http://2scsb-aaronfenker.rhcloud.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25"

If the filename of my model includes "_model, “ the page gives the CI error message, but it still throws the 500 error. If I don't include "_model" in the filename, then the page doesn't load at all, but it still throws the 500 error.

When I do a git push I get the following errors:

Code:
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"
[08/Dec/2014:20:11:04 -0500] "HEAD / HTTP/1.1" 500 - "-" "Ruby"

I deleted my original app, and started fresh just in case I goofed on something in pushes. (Git is new to me too.)

Here's my code again.

controllers/welcome.php

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {

    
/**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -  
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    
public function index()
    {
        
$this->load->model('Nav_menu');
        
$this->load->view('header');
        
$this->load->view('welcome_message');
        
$this->load->view('footer');
    }
    private function 
create_menu() {
        
$data['query'] = $this->Nav_menu->get_active_albums();
     
   echo $data;
 
  }


models/nav_menu.php

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Nav_menu extends CI_Model {
    function 
__construct() {
     
       parent::__construct();
    }
    
    function 
get_active_albums() {
        
$query $this->db->get_where('albums', array('is_active' 1));
        
        return 
$query->result();
    }


Is there a setting that I'm missing somewhere?

Call the method with all lower letter 
PHP Code:
$this->load->model('nav_menu'); 

...and use it with $this->nav_menu->..........
Reply

#16
also... you can't just echo an object. you can print_r($data); or var_dump($data);
Reply

#17
(12-09-2014, 07:34 AM)afenker1985 Wrote: I did all that. I decided to change my model's filename to "nav_m_model.php" When I do that, I at least get the CI error message: "Unable to locate the model you have specified nav_m." But I'm still throwing the error
Quote:"GET / HTTP 1.1" 500 1183 "-"

And...if your model name is nav_m_model.php you will have to load it like this $this->load->('nav_m_model'); and use it like this $this->nav_m_model->.....etc.

Try to load the models in your contructor method if you need them globally within your controller or load them just in the method that requires them.
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
Reply

#18
I keep going around in circles on this. Here's all my updated code:

controllers/welcome.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {
    public function 
__construct() {
        
parent::__construct();
        
        
$this->load->model('nav_m');
    }
    
    public function 
index()
    {
        
$this->load->view('header');
        
$this->load->view('welcome_message');
        
$this->load->view('footer');
    }
    private function 
create_menu() {
        
$data['query'] = $this->nav_m->get_active_albums();
        
print_r($data);
   }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */ 

models/nav_m_model.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Nav_m_model extends CI_Model {
    public function 
__construct() {
            
parent::__construct();
    }
    
    public function 
get_active_albums() {
        
$query $this->db->get_where('albums', array('is_active' 1));
        
        return 
$query->result();
    }


Let me try and explain this clearly. In the constructer, I will get a blank screen if I do this:
Code:
$this->load->model('nav_m_model');

In the constructer, I will get the CI error message if I do this:
Code:
$this->load->model('nav_m');

What am I missing?
Reply

#19
(12-09-2014, 08:02 AM)afenker1985 Wrote: I keep going around in circles on this. Here's all my updated code:

controllers/welcome.php



PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {
    public function 
__construct() {
        
parent::__construct();
        
        
$this->load->model('nav_m');
    }
    
    public function 
index()
    {
        
$this->load->view('header');
        
$this->load->view('welcome_message');
        
$this->load->view('footer');
    }
    private function 
create_menu() {
        
$data['query'] = $this->nav_m->get_active_albums();
     
   print_r($data);
 
  }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */ 

models/nav_m_model.php



PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Nav_m_model extends CI_Model {
    public function 
__construct() {
     
       parent::__construct();
    }
    
    public function 
get_active_albums() {
        
$query $this->db->get_where('albums', array('is_active' 1));
        
        return 
$query->result();
    }


Let me try and explain this clearly. In the constructer, I will get a blank screen if I do this:



Code:
$this->load->model('nav_m_model');

In the constructer, I will get the CI error message if I do this:



Code:
$this->load->model('nav_m');

What am I missing?


You have to load your model like this:

PHP Code:
$this->load->model('nav_m_model'); 

Replace

PHP Code:
$data['query'] = $this->nav_m->get_active_albums(); 

With

PHP Code:
$data['query'] = $this->nav_m_model->get_active_albums(); 

replace print_r with
PHP Code:
var_dump($data['query']); 
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
Reply

#20
I did what you asked, and now I just get a blank screen instead of the CI error message.

controllers/welcome.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {

    
/**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -  
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    
public function __construct() {
        
parent::__construct();
        
        
$this->load->model('nav_m_model');
    }
    
    public function 
index()
    {
        
$this->create_menu();
        
$this->load->view('header');
        
$this->load->view('welcome_message');
        
$this->load->view('footer');
    }
    private function 
create_menu() {
        
$data['query'] = $this->nav_m_model->get_active_albums();
        
print_r($data);
   }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.