Yes you are right. I tried to change the mediumtext to text and still the same error.
I can’t use that memory_get_usage() function because right now I noticed that this error occurs when I try to load a model. I realized this when I tried to use memory usage function at the beginning of my controller method (before performing any db operation). So it means it’s giving the error during the loading of model class (even if I don’t call a single method from that model, it’s giving the same error). That’s why the error occurs in Loader class.
When I comment out this statement $this->load->model( ‘myModel’ ); it starts working. I mean at least the page loads. After making few changes, now it’s giving the same error but in different class (Base class instead of Loader)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261900 bytes) in C:\wamp\www\jinnahsequaid\system\codeigniter\Base5.php on line 50
I think I have to show you the models. This is specially happening with 2 model classes. First is BlogPosts and second is Users.
This is the BlogPosts model class:
<?php
class BlogPosts extends Model {
function __construct() {
parent::Model();
$this->load->database();
$this->load->model( 'Users' );
$this->load->model( 'Comments' );
$this->load->model( 'ColAuthors' );
}
function countAll( $category ) {
$this->db->where( 'category', $category );
$this->db->where( 'status', 'active' );
return $this->db->count_all_results( 'posts' );
}
function getArticleById() {
$this->load->helper( 'MY_security_helper' );
$query = 'SELECT * FROM posts WHERE id = ? AND status = \'active\' LIMIT 1';
$results = $this->db->query( $query, id_clean( $this->uri->segment( 3 ) ) );
$data = $results->row_array();
if( !empty( $data ) && $data[ 'category' ] == 'Columns' ) {
$data[ 'author_name' ] = $this->ColAuthors->getAuthorById( $data[ 'author' ] );
}
$results->free_result();
return $data;
}
function getLast5Posts( $category ) {
$query = 'SELECT * FROM posts WHERE category = ? AND status = \'active\' ORDER BY date DESC LIMIT 5';
$results = $this->db->query( $query, array( $category ) );
foreach( $results->result_array() as $row ) {
$row[ 'body' ] = $this->strip_body( $row[ 'body' ] ); //add the limited version of article to the record
//$row[ 'total_comments' ] = $this->Comments->countCommentsByPostId( $row[ 'id' ] );
if( $category == 'Columns' )
$row[ 'author_name' ] = $this->ColAuthors->getAuthorById( $row[ 'author' ] );
$data[] = $row;
}
$results->free_result();
return $data;
}
function getAllPosts( $category ) {
$this->load->helper( 'MY_security_helper' );
define( 'LIMIT', 10 );
$query = 'SELECT * FROM posts WHERE category = ? AND status = \'active\' ORDER BY date DESC LIMIT ?, ' . LIMIT;
$results = $this->db->query( $query, array( $category, id_clean( $this->uri->segment( 3 ) ) ) );
foreach( $results->result_array() as $row ) {
$row[ 'body' ] = $this->strip_body( $row[ 'body' ] ); //add the limited version of article to the record
$row[ 'total_comments' ] = $this->Comments->countCommentsByPostId( $row[ 'id' ] );
if( $category == 'Columns' )
$row[ 'author_name' ] = $this->ColAuthors->getAuthorById( $row[ 'author' ] );
$data[] = $row;
}
$results->free_result();
return $data;
}
function getPostsByAuthor( $user, $category ) {
$query = 'SELECT * FROM posts WHERE category = ? AND author = ? AND status = \'active\'';
$results = $this->db->query( $query, array( $category, $user ) );
$data = $results->result_array();
$results->free_result();
return $data;
}
//utility methods
private function strip_body( $text ) {
$body = '';
foreach( explode( ' ', $text ) as $word ) {
if( strcmp( $word, '<!--more-->' ) == 0 )
break;
$body .= $word . ' ';
}
return $body;
}
}