Welcome Guest, Not a member yet? Register   Sign In
Please help with the memory exhausting error
#1

[eluser]sanea[/eluser]
Hi to everyone!
I the begginer in PHP programming and CI use and i'm trying to do my first website following some lessons. It should take some data from table of DB created using denwer and display the information from there on the main page.
The thing i did is a constructor:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//ini_set('memory_limit', '50M');
class Pages extends CI_Controller
{
    
    public function __construct()
    {
        parent::__construct('CI_Controller');
        $this->load->model('pages_model');        
    }
public function show ($page_id)
{
    $data = array();
    $data['main_info'] = $this->pages_model->get($page_id);
    
    switch($page_id)
    {
        case 'index':
        $name = 'pages/mainpage';
        $this->display_lib->user_page($data,$name);
        break;        
    }
}    
}
?>


a library with my view pages:

Code:
[b]
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Display_lib
{
    
    //data- array whit variables, name - beggining of the name of view
    public function user_page($data,$name)
    {
        $CI =& get_instance();
        
        $CI->load->view('preheader_view',$data);
        $CI->load->view('header_view');
        $CI->load->view('top_navigation_view');
        $CI->load->view($name.'_view',$data);
        $CI->load->view('leftblock_view',$data);
        $CI->load->view('rightblock_view',$data);
        $CI->load->view('footer_view');
    }    
}
?>
[/b]


and models:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Crud extends CI_Model
{
    public $table = ''; //table name
    public $idkey = ''; //id name
    
    public function __construct()
    {
        parent::__construct('CI_Model');
    }
    
    public function get($obj_id)
    {
        $this->db->where($this->idkey,$obj_id);
        $query = $this->get($this->table);
        return $query->row_array();
    }    
}
?>

and extending model

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pages_model extends Crud
{
    public $table = 'pages';  //table name
    public $idkey = 'page_id';  //id name    
}
?>

The error i get trying to acces the page si:
Quote:Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in Z:\home\xxxxxx\www\system\database\drivers\mysql\mysql_driver.php on line 1388

I would appreciate any help in that problem cause it will help me i my future learning and understanding of php programming and CI framework utilization.
Thanks for your attention and help!




#2

[eluser]InsiteFX[/eluser]
IF you want users to help you please wrap your code in code tags or it will not get answered.
#3

[eluser]wiredesignz[/eluser]
@sanea, Your Crud model get() method makes a recursive call to itself and establishes an endless loop.
#4

[eluser]sanea[/eluser]
[quote author="InsiteFX" date="1344685995"]IF you want users to help you please wrap your code in code tags or it will not get answered.
[/quote]
Thx for sugestion that's really much more better!
#5

[eluser]sanea[/eluser]
[quote author="wiredesignz" date="1344686726"]@sanea, Your Crud model get() method makes a recursive call to itself and establishes an endless loop.[/quote]

Any suggestion in solving it )?
#6

[eluser]wiredesignz[/eluser]
[quote author="sanea" date="1344688452"]...Any suggestion in solving it )?[/quote]

Yeah, don't make a recursive call.
#7

[eluser]sanea[/eluser]
Quote:Yeah, don't make a recursive call.

Nice ))!!!!
I can't get one thing , why it is recursive? i got no cycle in it (for,while).....
There is something i really don't get )
#8

[eluser]wiredesignz[/eluser]
Code:
public function get($obj_id)
{
    ...
    $query = $this->get($this->table); // recursive call to $this->get()
    ...
}
#9

[eluser]sanea[/eluser]
[quote author="wiredesignz" date="1344690274"]
Code:
public function get($obj_id)
{
    ...
    $query = $this->get($this->table); // recursive call to $this->get()
    ...
}
[/quote]
thx a lot you opened my eyes Smile)))))

the code had to be like that:
Code:
public function get($obj_id)
    {
        $this->db->where($this->idkey,$obj_id);
        $query = $this->db->get($this->table);
        return $query->row_array();
        
    }

and now it works like it should !!!
#10

[eluser]wiredesignz[/eluser]
[quote author="sanea" date="1344690699"]
...thx a lot you opened my eyes Smile)))))

the code had to be like that:
Code:
public function get($obj_id)
    {
        $this->db->where($this->idkey,$obj_id);
        $query = $this->db->get($this->table);
        return $query->row_array();
        
    }
and now it works like it should !!!
[/quote]

Awesome. Wink




Theme © iAndrew 2016 - Forum software by © MyBB