• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error 'Undefined property' when loading model to controller

#1
[eluser]Tortoise[/eluser]
Hello to everyone!

I have the code:
news.php:
Code:
<?php
  class News extends Controller
  {
    public function ru()
    {
      $data['xml_lang'] = 'ru';
      $data['title'] = 'Официальный сайт брутал-дэт группы Fleshbomb - Новости';      
      /*$this->load->helper('url');
      $data['main'] = anchor('news/ru', 'Главная');*/
      $data['published'] = 'Опубликовано';
      $this->load->model('news_model');
      $data['news'] = $this->news_model->get_last_three_entries($data['xml_lang']);
      $this->load->view('newsview', $data);
    }
    
    public function en()
    {
      $data['xml_lang'] = 'en';
      $data['title'] = 'Fleshbomb brutal-death band Official Site - News';
      /*$this->load->helper('url');
      $data['main'] = anchor('news/en', 'Main');*/
      $data['published'] = 'Published';
      $this->load->model('news_model');
      $data['news'] = $this->news_model->get_last_three_entries($data['xml_lang']);
      $this->load->view('newsview', $data);
    }
  }
?>
news_model.php:
Code:
<?php
  class News_model extends Model
  {
    public function __construct()
    {      
            parent::Model();
            $this->load->database();
    }
    
    public function get_last_three_entries($lang)
    {      
      $sql = "SELECT p_date AS date, p_title_$lang AS title, p_content_$lang AS content FROM site_news LIMIT 3";            
      $query = $this->db->query($sql);
      return $query->result_array();
    }
  }
?>
and newsview.php:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="&lt;?php echo $xml_lang; ?&gt;" lang="&lt;?php echo $xml_lang; ?&gt;"&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
  &lt;meta name="keywords" content="brutal-death, grindcore, grind-core, goredeath, gore-death, fleshbomb, nosorog" /&gt;
  &lt;meta name="description" content="Moscow gore-death band official site. Full discography, biography, gigs, videos" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="../../system/application/media/css/style.css" /&gt;
&lt;/head&gt;  
&lt;body&gt;
    <div id="sidebar-left">
        <ul id="menu-list">
            <li><a href="#">Menu item</a></li>
        </ul>
    </div>
  &lt;?php foreach($news as $item): ?&gt;
  <div class="news-block">    
    <h3 class="news-title">&lt;?php echo $item['title']; ?&gt;</h3>
    <div class="news-date">&lt;?php echo $published . ': ' . date('d.m.Y H:i:s', $item['date']); ?&gt;</div>
    <div class="news-body">&lt;?php echo $item['content']; ?&gt;</div>
    <hr />
  </div>
  &lt;?php endforeach; ?&gt;
&lt;/body&gt;
&lt;/html&gt;
On my local server (MAMP 1.7.1) it works just fine. Even if I used $this->load->model(Uppercase_name) or $this->load->model(lowercase_name).
But when I put it on hosting server I have get error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: News::$news_model
Filename: controllers/news.php
Line Number: 12
Fatal error: Call to a member function get_last_three_entries() on a non-object in /pub/home/artwiko/htdocsfb/dev/system/application/controllers/news.php on line 12
For the /news/ru.html.
And:
Fatal error: Call to a member function get_last_three_entries() on a non-object in /pub/home/artwiko/htdocsfb/dev/system/application/controllers/news.php on line 24
For the /news/en.html
I can't understand what I doing wrong.
Could somebody help please?

#2
[eluser]Seppo[/eluser]
Probably you are running Windows and your server Unix... How are your model file and class named (edit: I mean the lowercases/uppercases)?

#3
[eluser]Tortoise[/eluser]
[quote author="Seppo" date="1212944779"]Probably you are running Windows and your server Unix...[/quote]
Not right. I'm running Mac OS X (Unix) and the server is Unix too.
[quote author="Seppo" date="1212944779"]How are your model file and class named (edit: I mean the lowercases/uppercases)?[/quote]
The model file name is - news_model.php and the model class definition is - class News_model extends Model.
The view file name is - newsview.php and the view class definition is - class News extends Controller.

#4
[eluser]Tortoise[/eluser]
[quote author="Seppo" date="1212944779"]Probably you

#5
[eluser]Jim Higgins[/eluser]
Have you been able to run any other applications or load other models on this hosting server or is this your first attempt?

If this is your first attempt to run CI on this hosting server, double check to make sure you've adjusted your system/application/config/config.php

You need to have your $config['base_url'] set. Although, I'm sure you've done that. Just trying to eliminate possible problems.

Also, if you have this set in your config... $config['uri_protocol'] = "AUTO"
Try changing it to... $config['uri_protocol'] = "REQUEST_URI";

#6
[eluser]Gavin Blair[/eluser]
You say 'lowercase_name' doesn't work on the hosting server, but 'Uppercase_name' and 'lowercase_name' both work on localhost.

Does 'Uppercase_name' work on the hosting server?

If so, you can fix everything by just editing the load line:
$this->load->model('Uppercase_name', 'lowercase_name');

That way referring to $this->lowercase_name will still work.

#7
[eluser]Tortoise[/eluser]
[quote author="Jim Higgins" date="1212961954"]If this is your first attempt to run CI on this hosting server, double check to make sure you've adjusted your system/application/config/config.php[/quote]
Yes it is my first attempt to run CodeIgniter on this hosting server.

[quote author="Jim Higgins" date="1212961954"]You need to have your $config['base_url'] set. Although, I'm sure you've done that. Just trying to eliminate possible problems.[/quote]
Yes, $config['base_ur'] is already set. And links generated with URL helper has right address.

[quote author="Jim Higgins" date="1212961954"]Also, if you have this set in your config... $config['uri_protocol'] = "AUTO"
Try changing it to... $config['uri_protocol'] = "REQUEST_URI";[/quote]
I have tryed both variants and nothing changed.

#8
[eluser]Tortoise[/eluser]
[quote author="Gavin Blair" date="1212987743"]You say 'lowercase_name' doesn't work on the hosting server, but 'Uppercase_name' and 'lowercase_name' both work on localhost.

Does 'Uppercase_name' work on the hosting server?[/quote]

I was incorrect. Both versions (lowercase and uppercase) works just fine on local server. And them both again on hosting server doesn't work at all.

#9
[eluser]Tortoise[/eluser]
Experiments show that model's constructor is invoked and also invokes parent constructor of Model class. But the functions after it doesn't invokes.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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