Welcome Guest, Not a member yet? Register   Sign In
Undefined property: CodeIgniter\View\View::$db
#1

(This post was last modified: 01-16-2021, 05:07 PM by yuma2020.)

Hi, need help to solve this problem: 
ErrorException
PHP Code:
Undefined propertyCodeIgniter\View\View::$db 
PHP Code:
$this->db->limit 
Need create query to present here:
PHP Code:
90             $this->db->limit(9);
91             $categories $this->db->get_where('category', array('parent' => 0))->result_array(); 
My proporsal to query is:
PHP Code:
      public function getCategoriesNine($category_id 0) {
        $getTable $this->db->table('category')->get();
        if ($category_id 0) {
          $query $this->db->table('category', array('parent' => 0))
          ->where(['id' => $category_id ])
          ->limit(9)
          ->get()
          ->getFirstRow();
          return $query $query null;
        }
        return $getTable $getTable  null;
      

Please need help if valir of query parse
PHP Code:
->limit(9

present in the view is this proporsal
PHP Code:
                            $queryCatNine = (new \App\Models\CommonQueries())->getCategoriesNine();
                            
$categories $queryCatNine->getResultArray(); 
or I'd like to know how to define this property.

Update example need know is valid in the view:
PHP Code:
                            $queryCat = (new \App\Models\CommonQueries())->getCategoriesNine();
                            
$categories $queryCat->getResultArray();
                            
$categories->limit(10); 
Reply
#2

Why don't you pass the query result to your view instead of creating the model in the view?
Reply
#3

(01-16-2021, 07:54 PM)kenjis Wrote: Why don't you pass the query result to your view instead of creating the model in the view?
incomplete documentThans for the answer, you are right, I understand, for this reason it was the doubt, I simply wanted to know how to apply it correctly.
Reply
#4

How about this?
Code:
      public function getCategoriesNine($category_id = 0) {
        $getTable = $this->db->table('category')->get();
        if ($category_id > 0) {
          $query = $this->db->table('category', array('parent' => 0))
          ->where(['id' => $category_id ])
          ->limit(10)
          ->get()
          ->getFirstRow();
          return $query ? $query : null;
        }
        return $getTable ? $getTable  : null;
      }
Reply
#5

(This post was last modified: 01-19-2021, 07:51 AM by nicojmb.)

This function not its optimal, always get  all rows in category tables though the $category_id is set.

I would trade it for this:

PHP Code:
public function getCategoriesNine($category_id 0
{
  $categories $this->db->table('category');

  if ($category_id 0
  {
        // Limit 10?  getFirtsRow??? i dont understand this...
        return $categories->where(['id' => $category_id ])->limit(10)->get()->getFirstRow();
  }

  return $categories->get();

Reply
#6

What do you want to do?

First of all, I recommend you read https://codeigniter4.github.io/CodeIgnit...ilder.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB