CodeIgniter Forums
table name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: table name (/showthread.php?tid=90260)



table name - Arquero - 02-26-2024

I have a model in CI 4.1 than only has a method that do something like 

PHP Code:
public function myfunction() {
  return $this->query('select XXX from XXX where XXX')->getRowArray();


I have updated to CI 4.4.5 and now I must set a table, that does nothing, because I only use ->query. Indeed I can type anything in $this->table cause no real efect.

PHP Code:
public function myfunction() {
  $this->table 'YYY';
  return $this->query('select XXX from XXX where XXX')->getRowArray();


¿Why is needed set table for query? for other methods usage it is ok, but is weird and counter intuitive for only cast a query.


RE: table name - badger - 02-26-2024

(02-26-2024, 10:30 AM)Arquero Wrote: I have a model in CI 4.1 than only has a method that do something like 

PHP Code:
public function myfunction() {
  return $this->query('select XXX from XXX where XXX')->getRowArray();


I have updated to CI 4.4.5 and now I must set a table, that does nothing, because I only use ->query. Indeed I can type anything in $this->table cause no real efect.

PHP Code:
public function myfunction() {
  $this->table 'YYY';
  return $this->query('select XXX from XXX where XXX')->getRowArray();


¿Why is needed set table for query? for other methods usage it is ok, but is weird and counter intuitive for only cast a query.

you don't need a model, in your controller just write
PHP Code:
$rows$this->db->query('select xxx from xxx where xxx')->getResult() or $row=$this->db->query('select....')->getRow() 



RE: table name - kenjis - 02-26-2024

Because CodeIgniter Model is designed to work with a single table.
https://codeigniter4.github.io/CodeIgniter4/models/model.html#models

And yes, you don't need to use CodeIgniter Model if you use only DB query() and/or Query Builder.
https://codeigniter4.github.io/CodeIgniter4/models/model.html#manual-model-creation