1

I'm getting this Fatal Error Message in my codeIgniter, I've already tried some answers which has the same question.

I've already set my php.ini


    max_execution_time = 300
    max_input_time = 600
    memory_limit = 128M

But still I'm getting the same Fatal error message, I don't know if the problem is in my code or in php settings.

Here are some my of codes in controller:

public function blog(){
    $this->load->model("blog_model");
    $data["title"] = "CodeIgniter Projects - Blog";
    if($this->getLastUrl() == 'blog'){
        $data["result"] = $this->blog_model->getBlogs();
        $this->load->view("view_blog", $data);  
    }else{
        $blog_name = $this->getLastUrl();
        $data["result"] = $this->blog_model->getBlogDetails($blog_name);
        $data["comment"] = $this->blog_model->getBlogComments($blog_name);
        $this->load->view("view_blog_details", $data);
        //check for reply
        $url =$_SERVER['REQUEST_URI'];
        $getLast = explode("/", $url);
        $last = end($getLast);
        if($last == 'reply'){
            $this->load->library('form_validation');
            $this->form_validation->set_rules('name', 'Name', 
                'trim|required|min_length[4]|xss_clean');
            $this->form_validation->set_rules('message', 'Comment', 
                'trim|required|min_length[4]|xss_clean');
            $this->form_validation->set_rules('email', 'Email Address', 
                'trim|required|valid_email');

            if($this->form_validation->run() == FALSE)
            {
                $this->blog();
            }
            else
            {
                $msg = 'Message sent.';
                $this->blog_model->addBlogComment();
                $this->blog();
            }
        }

    }
}

My main function is to add new comment in a blog, it works but it inserts duplicate data and I cant get rid of the fatal error message.

addBlogComment Function


    function addBlogComment(){
    $data=array(
    'blog_id'=> $this->input->post('blog_id'),
    'name'  => $this->input->post('name'),
    'email' => $this->input->post('email'),
    'message' => $this->input->post('message'),
    'created'   => date('Y-m-d H:i:s')
    );

    $this->db->insert('comment',$data);
    }

FoolishSeth
  • 3,632
  • 1
  • 15
  • 28
khatzie
  • 2,329
  • 4
  • 20
  • 37
  • how about sharing the `addBlogComment()` function code, as the problem seems to originate from there? – Zathrus Writer Feb 06 '13 at 10:07
  • What line of your code does the error point to? – Jeemusu Feb 06 '13 at 10:10
  • I don't think it is from addBlogComment because even if it does not pass in the validation i'm always getting the fatal error message. But any ways I'll add it. – khatzie Feb 06 '13 at 10:10
  • This is the exact fatal error message Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 29415322 bytes) in D:\xampp\htdocs\katherine_petalio\codeigniter\system\core\Output.php on line 164 – khatzie Feb 06 '13 at 10:11
  • 1
    Is this only happening when the uri is something like: `foo/bar/reply` ? Where the last segment is 'reply' ? Also, not related, but you could be using codeigniters uri library http://ellislab.com/codeigniter/user-guide/libraries/uri.html – Jeemusu Feb 06 '13 at 10:19
  • yes your right, is there a problem with that? – khatzie Feb 06 '13 at 10:24
  • 4
    I would assume it's because your calling `$this->blog();` which is the same function, so it would seem to be stuck in some kind of infinite loop of calling itself over and over again. What exactly are your trying to achieve by `$this->blog();` ? – Jeemusu Feb 06 '13 at 10:29
  • I think that's really the problem. I'll try to fix it thanks for your help. :-) – khatzie Feb 06 '13 at 10:37
  • Try to turn off the "global_xss_filtering" in config.php and later manually filter some user inputs $config['global_xss_filtering'] = false; – FDisk Feb 06 '13 at 11:41

2 Answers2

2

I just found out the wrong loop in my code. The loop will has no exit and it will turns back all over again.

if($this->form_validation->run() == FALSE)
{
      $this->blog();
}
else
{
      $msg = 'Message sent.';
      $this->blog_model->addBlogComment();
      $this->blog();
}

it will always return a false value so it will execute and execute no end of loop.

khatzie
  • 2,329
  • 4
  • 20
  • 37
1

Try construct your controller like so:

public function blog( $blog_name = '', $action = '' ){

    $this->load->model("blog_model");

    // What if there is no blog name in the url
    if ( empty( $blog_name ) ) {

        // Load the list of blogs
        $data["result"] = $this->blog_model->getBlogs();
        $this->load->view("view_blog", $data);

    } else {

        // If the blog name in url exists and there is no action display the blog
        if ( !empty( $blog_name ) && empty( $action ) ) {

            $blog_name = $this->getLastUrl();
            $data["result"] = $this->blog_model->getBlogDetails( $blog_name );
            $data["comment"] = $this->blog_model->getBlogComments( $blog_name );
            $this->load->view("view_blog_details", $data);

        }
        // else If there is the action "reply" check if there is some post
        else if ( $action == 'reply' && $this->input->post( 'Comment' ) ) {

            $this->load->library( 'form_validation' );
            $this->form_validation->set_rules( 'name', 'Name', 'trim|required|min_length[4]|xss_clean' );
            $this->form_validation->set_rules( 'message', 'Comment', 'trim|required|min_length[4]|xss_clean' );
            $this->form_validation->set_rules( 'email', 'Email Address', 'trim|required|valid_email' );

            if($this->form_validation->run() == FALSE) {

                redirect( site_url( $blog_name ) );

            } else {

                $msg = 'Message sent.';
                $this->blog_model->addBlogComment();

                // Redirect to prevent F5 submitting duplicate data
                redirect( site_url( $blog_name ) );
            }
        }
    }
}
FDisk
  • 6,213
  • 1
  • 38
  • 45