[eluser]ibnu drim[/eluser]
I’m sure this is something trivial but I’ve spent the last hour scratching my head on this one!
I have several functions in my Model that all look like this (that find various things):
this is my controller :
Code:
function post( $slug = FALSE )
{
if( empty( $slug ) )
show_404();
$this->load->model('model_posts');
$this->load->model('model_gallery');
//$posts = $this->model_gallery->getPosts();
$posts = $this->model_gallery->getChild( $slug );
$data = array(
'contentPage' => 'gallery',
'breadcrumb' => $this->model_posts->createBreadCrumb(),
'advTop' => FALSE,
'posts' => $posts
);
?>
<pre><?php //echo print_r($posts); ?></pre>
<?php
if( $posts )
$data['show'] = $posts->title;
$this->load->view('index', $data);
}
this is my Model :
Code:
function getChild( $slug = FALSE )
{
$this->db->where('status', 1)
->where('parent', 0)
->where('slug', $slug)
->from('gallery');
$query = $this->db->get();
$posts = array();
foreach( $query->result() as $result )
{
$galler = array();
#has Child?
$child = $this->pagesHierarchy( $result->ID );
if( $child )
{
foreach( $child->result() as $c )
$galler['child'][] = $c;
}
$galler['parent'] = $result;
$posts[] = $galler ;
}
//return $posts ;
return !count( $posts )? FALSE:$posts;
}
function pagesHierarchy( $idParent = FALSE )
{
if( !$idParent || empty( $idParent ) )
return FALSE;
$this->db->where('parent', $idParent)
->from('gallery')
->order_by('ID', 'ASC');
$RES = $this->db->get();
return $RES->num_rows() <= 0? FALSE:$RES;
}
this is my View :
Code:
<?php
if( $posts ):
?>
<table class="gallery-lists">
<?php
$count = 1; $tCount = 1;
foreach( $posts as $post ):
$primaryImg = $this->models->_unserialize( $post->image_primary );
$secondaryImg = $this->models->_unserialize( $post->image_secondary );
if( $count <= 1 ):
?>
<?php
endif;
?>
<?php $slug = $post->slug ;
echo site_url( array('gallery', $slug ) ); ?>
please help me solve this error.
Trying to get property of non-object & uninitialized string offset :0
Thank you
Ibnudrim