Welcome Guest, Not a member yet? Register   Sign In
Trouble loading model
#1

[eluser]nathj07[/eluser]
Hi,

I'm new to the CI framework but so far so good.

I'm currently working on a simple proof of cncept thing to write some form information to a database. With a background in Java I am keen to keep to the MVC way of doing things and so I have created a MY_Controller and a MY_Model. Both of these extend their CI_ counterparts and exist in application/core directory. The MY_Controller class seems just fine.

So all my controller classes extend MY_Controller and this works just fine. I have sketched the early beginnings of a model class within the application/models directory and am attempting to load this in a controller. However, the load line causes a 500 Internal Server error.

Here is the code for the 2 custom model classes:

MY_Model
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');



class MY_Model extends CI_Model

{

    

    public function __construct()

    {

            parent::__construct();

            $this->load->helper('url');

            $this->load->helper('form');

            $this->load->helper('typography');

            $this->load->library('form_validation');            
            
            $this->load->dbutil();

    }

}
/* End of file MY_Model.php */

/* Location: ./application/core/my_model.php */

/* Last edit: Nathan - initial Creation 04/03/2011 */

The news_model class (snippet):

Code:
<?php

class News_model extends MY_Model

{
    private $_news_data;
    
     function __construct()
    {
           parent::__construct();

            $this->load->helper('url');

            $this->load->helper('form');

            $this->load->helper('typography');

            $this->load->library('form_validation');            
            
            $this->load->dbutil();
    }
    
    // functions for creation
In the news.php class I have (snippet):
Code:
class News extends MY_Controller

{

    

    function __construct()

    {

        parent::__construct();        
    }

    

    function index()

    {

        $this->load->model('News_model');        
        $this->load->view('writeNews_view');
    }
    
    // functions for creation    
    function collect_news_data()
    {
        $this->load->view('writeNews_view');
    }
    
    function write_news_data()
    {
It doesn't matter where I put the model load line - index() or collect_news_data() and I still get the error.

This is really annoying me now as I cannot figure out how to do it. Any help on this would be greatly appreciated.

Many thanks
Nathan
#2

[eluser]danmontgomery[/eluser]
What does the apache error log say?
#3

[eluser]nathj07[/eluser]
Hi,

I'm running IIS7 and the log simply reports Internal Server error:

2011-03-29 14:36:23 ::1 GET /index.php/news - 99 - ::1 Mozilla/5.0+(Windows+NT+6.1;+WOW64;+rv:2.0)+Gecko/20100101+Firefox/4.0 500 0 0 51

So that doesn't shed any light on it for me.

I was hoping that would show something wrong with my PHP but alas nothing that straight forward.

Any other ideas?

Thanks
Nathan
#4

[eluser]@li[/eluser]
I would recommend that you use apache.
#5

[eluser]nathj07[/eluser]
Thanks for that. When we move to a live environment it will be Apache based. But as I am developing on a Windows box IIS7 is the easiest thing to set up and get running.

So apart from 'change the hardware, change the software or change the web server' are there any other suggestions?

Many thanks
Nathan
#6

[eluser]sirfilip[/eluser]
Well i have copy pasted your code (the models part) into my ci installation and it worked no error was thrown. How ever it is not an codeigniter problem cause if it was it would throw an error. The server error that you are receiving could be caused by the IIS. The best way to check is by installing wamp http://www.wampserver.com/en/ it is free and one click install away, and try your code there. Dont forget to free the port 80 (turn off your IIS) before you try to start apache.
#7

[eluser]nathj07[/eluser]
Hi,

I meant to come back here sooner and say that I had figured out it was not a CI issue. I scrapped the code and started again and I have it working so there was something in the config somewhere that was not right.

Anyway thanks for the help and the advice, I may yet install WAMP. The issue I have is that I am already running Apache on port 90 to serve SVN to the team (there's only 2 of us).

Cheers
nathj07




Theme © iAndrew 2016 - Forum software by © MyBB