[eluser]ibnu drim[/eluser]
Hello,
I want to display in the gallery child view,, I select from the gallery where Id = child ,,,
but why do I find the error
Code:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
and
Code:
A PHP Error was encountered Severity: Notice Message: Uninitialized string offset: 0
Filename: libraries/Loader.php(673) : eval()'d code
I have several functions in my Model that all look like this (that find various things):
this is my controller :
Code:
<?php
class Gallery extends Controller {
function Gallery()
{
parent::Controller();
$this->load->helper('image_helper');
}
function index( $slug = FALSE )
{
#show lists or post?
if( empty( $slug ) )
$this->lists();
else
$this->post( $slug );
}
function lists()
{
$this->load->model('model_posts');
$this->load->model('model_gallery');
$posts = $this->model_gallery->getPosts();
$post = $this->model_gallery->getChild();
$data = array(
'contentPage' => 'gallerys',
'breadcrumb' => $this->model_posts->createBreadCrumb(),
'advTop' => FALSE,
'posts' => $posts,
);
$this->load->view('index', $data);
}
function post( $slug = FALSE )
{
if( empty( $slug ) )
show_404();
$this->load->model('model_posts');
$this->load->model('model_gallery');
$posts = $this->model_gallery->getPosts();
$post = $this->model_gallery->getChild($slug);
$data = array(
'contentPage' => 'gallery',
'breadcrumb' => $this->model_posts->createBreadCrumb(),
'advTop' => FALSE,
'posts' => $post
);
if($post)
$data['show'] = $post->title;
$this->load->view('index', $data);
}
}
this my model :
Code:
<?php
class Model_gallery extends Model {
function Model_gallery()
{
parent::Model();
}
function getPosts()
{
$this->db->where('status', 1)
->where('parent', 0)
->order_by('date_add', 'DESC')
->from('gallery');
$RES = $this->db->get();
return $RES->num_rows() <= 0? FALSE:$RES;
}
function getPost( $slug = FALSE )
{
$this->db->where('status', 1)
// ->where('parent', $slug->ID)
->where('slug', $slug)
//->where('parent', $slug->ID)
->from('gallery');
$RES = $this->db->get()->row();
return empty( $RES )? FALSE:$RES;
}
function getChild( $slug = FALSE )
{
$this->db->where('status', 1)
//->where('parent', 0)
->where('slug', $slug)
->from('gallery');
$Query = $this->db->get();
if( $Query->num_rows <= 0 )
return FALSE;
$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;
}
function getByID( $ID )
{
$this->db->where('ID', $ID)
->from('gallery');
$query = $this->db->get();
if( $query->num_rows() <= 0 )
show_error('Not found Content with ID = ' . $ID);
else
return $query->row();
}
}
this my view :
Code:
if( $posts ):
?>
<table class="gallery-lists">
<?php
$count = 1; $tCount = 1;
foreach( $posts as $post ):
if( !isset( $post['parent'] ) )
continue;
$post = $post['child'];
echo print_r($post);
$primaryImg = $this->models->_unserialize( $post->image_primary );
$secondaryImg = $this->models->_unserialize( $post->image_secondary );
if( $count <= 1 ):
?>
<tr>
<?php
endif;
?>
<td>
<a href="<?php echo base_url(); ?>img.php?act=view&src;=<?php echo $primaryImg['file_name']; ?>" rel="group" class="colorbox">title; ?>">
<span class="img"><span><?php echo auto_resize( !$secondaryImg? $primaryImg:$secondaryImg, 100, 0, base_url(), FALSE ) ?></span></span>
<span class="description">
<span class="title"><?php echo $post->title; ?></span>
<span class="text"><?php echo $post->content; ?></span>
</span>
Any idea ? Thanks