Welcome Guest, Not a member yet? Register   Sign In
$db is confusing in the docs.
#1

When I enter the docs and see something like this:

[size=1]Code:
[/size]
Code:
$fields = $db->getFieldNames('table_name');


It confuses the hell out of me to figure out WHERE $db 'magically' comes from ... I see it NOWHERE in MY ResourceControllers ... and if I try to define it all hell breaks loose ...

Now, please add some understandable CONTEXT when writing docs.

Can someone please shed some light on HOW to understand the docs when trying to use it as a reference?
Reply
#2

works though consider :
Code:
public function getCountByCategory($category)
    
    {
          $db      = \Config\Database::connect();
//  from memory it gets from /app/config/Database.php
         $fields= $db->getFieldNames('products');
         var_dump($fields);

// output was array(7) { [0]=> string(2) "Id" [1]=> string(5) "image" [2]=> string(10) "imageTitle" [3]=> string(4) "slug" [4]=> string(8) "category" [5]=> string(4) "info" [6]=> string(5) "price" }
I use Arch Linux by the way 

CMS in Action
Reply
#3

Thank you for reporting.
I sent a PR to improve:
https://github.com/codeigniter4/CodeIgni...6307/files
Reply
#4

@erlingdoyle See https://codeigniter4.github.io/CodeIgnit...adata.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB