Welcome Guest, Not a member yet? Register   Sign In
table name
#1

(This post was last modified: 02-26-2024, 10:38 AM by Arquero. Edit Reason: fix update version CI 4.5 -> CI 4.4.5 )

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.
Reply
#2

(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() 
Reply
#3

Because CodeIgniter Model is designed to work with a single table.
https://codeigniter4.github.io/CodeIgnit...tml#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/CodeIgnit...l-creation
Reply




Theme © iAndrew 2016 - Forum software by © MyBB