[eluser]Unknown[/eluser]
Hi guys,
I was wondering if you could shed a little light on my current dilemma.
Basically, I'm using $this->load->model(X) and $this->load->model(Y)
Both files X and Y exist, are identically located with identically formatted names ('posts' and 'pages' in minuscule).
Both models X and Y are at the moment identical apart from their name (and the appropriate function name changes).
However, I can call $this->X but not $this->Y - see the error message
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Sidebars::$Posts
Filename: models/sidebars.php
Line Number: 97
Fatal error: Call to a member function getRows() on a non-object in /****/application/models/sidebars.php on line 97
Best explained through code, the relevant files (various comments removed) are below:
Model: Sidebars (application/models/sidebars.php)
Code:
<?php
class Sidebars extends Model
{
function Sidebars()
{
parent::Model();
}
function loadSidebar($type)
{
$sidebar = array();
switch( $type )
{
case "pages":
$sidebar['pages'] = $this->pageList();
$sidebar['popular'] = $this->popularPosts();
break;
}
return $sidebar;
}
function pageList()
{
$pageList = array();
$this->load->model("Pages");
foreach( $this->Pages->getRows(NULL, "method, title") as $row )
{
$pageList[ $row['method'] ] = $row ['title'];
}
return $pageList;
}
function popularPosts()
{
$popularPosts = array();
$this->load->model("Posts");
foreach( $this->Posts->getRows(NULL, "id, method, title", "views DESC", "5") as $row )
{
$popularPosts[ $row['id']."/".$row['method'] ] = $row ['title'];
}
return $popularPosts;
}
}
?>
Model: Pages (application/models/pages.php)
Code:
<?php
class Pages extends SpecialActiveRecord
{
function Pages()
{
parent::SpecialActiveRecord();
$this->loadColumnsFromTable("pages");
}
}
?>
Model: Posts (application/models/posts.php)
Code:
<?php
class Posts extends SpecialActiveRecord
{
function Posts()
{
parent::SpecialActiveRecord();
$this->loadColumnsFromTable("posts");
}
}
?>
Note: The class SpecialActiveRecord is just an extension to the standard Model class. It actually provides me with quick shortcuts to the combination of ActiveRecord functions I use most (another layer of abstraction! yipee). This shouldn't be causing the error as it is identically loaded by both X and Y classes!
---
So basically the first call to $this->pageList() is working fine but not $this->popularPosts();
Many thanks for any help you can give me!