Message: count(): Parameter must be an array or an object that implements Countable

140 views Asked by At

Please tell me whats wrong ?

public function view($link = null) {
    $temp = $this->BlogModel->getDetail('link', $link);
    
    if (count($temp) == 1) { "this countable"
        $data = array(
            'app' => $this->app(),
            'data' => $temp,
            'comments' => $this->BlogCommentModel->getAll(['blog_id' => $temp->id], 'id asc'),
            'data_latest' => $this->BlogModel->getLatest(6)
        );
        $this->BlogModel->updateVisitCount($link);
        $this->template->set('title', $data['data']->title . ' | ' . $data['app']->app_name, TRUE);
        $this->template->load_view($data['app']->template_frontend.'/detail', $data, TRUE);
        $this->template->render();
    } else {
        redirect(base_url('blog/'));
    };
}

Thank you

2

There are 2 answers

0
Haithem On

what is this line ? if (count($temp) == 1) { "this countable" you must delete "this countable" first can you post the error ?

0
Huzaifa Qidwai On

use

if (is_array($temp) && count($temp) == 1) { "this countable"

instead of

if (count($temp) == 1) { "this countable"