-3

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

Simone Rossaini
  • 8,115
  • 1
  • 13
  • 34
Atria
  • 1
  • have you try to print this `$temp`? – Simone Rossaini Mar 01 '21 at 09:54
  • 2
    You have to add more information, it's impossible to determine based on the code. what's the value of $temp. please log it and add it to the question. – vlad katz Mar 01 '21 at 09:59
  • If `$temp` is set to null, a string, an object (without Countable implementation), the `count($temp)` will generate an error. Perhaps you should use another validation method, such as `if (!is_null($temp))...` – Gowire Mar 01 '21 at 10:27
  • thank you, use if (!is_null($temp))... is work – Atria Mar 02 '21 at 02:31

2 Answers2

0

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

Haithem
  • 1
  • 2
0

use

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

instead of

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

Huzaifa Qidwai
  • 239
  • 1
  • 3