CodeIgniter Forums
select only false - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: select only false (/showthread.php?tid=79618)



select only false - lucavalentino - 07-08-2021

I am trying to recover data from Mysql but I always get false.
Model

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;
use 
App\Entities\Studente_e;


class 
Studente_m extends Model
{
protected 
$table      'tblstud';
protected 
$primaryKey 'ID';
protected 
$useAutoIncrement true;
protected 
$returnType 'App\Entities\Studente_e';
protected 
$useSoftDeletes true;

protected 
$allowedFields = ['name''email'];

/*protected $useTimestamps = false;
protected $createdField  = 'created_at';
protected $updatedField  = 'updated_at';
protected $deletedField  = 'deleted_at';*/

protected $validationRules    = [];
protected 
$validationMessages = [];
protected 
$skipValidation    false;
protected 
$useTimestamps true;

]public function 
__construct()
{
$this->db = \Config\Database::connect();
$this->db db_connect();
$this->builder $this->db->table($this->table);
}

  function check($id$email){

  $this->builder->select('ID, NAME, EMAIL');
$this->builder->from('tblstud');
  $this->builder->where('ID'$ID);
  $this->builder->where('EMAIL',$email);
  $query=$this->builder->get();
  var_dump($this->builder->get()); 



RE: select only false - InsiteFX - 07-09-2021

You do not need this the model already has it intialized.

PHP Code:
// ] that will cause an error
]public function __construct()
{
    $this->db = \Config\Database::connect();
    $this->db db_connect();
    $this->builder $this->db->table($this->table);
}

// Just use this
public function __construct()
{
    parent::__construct();
}

// Example method:
public function getAllPosts() : PostModel
{
    $builder $this->builder();

    $builder->orderBy('created_at''desc');

    return $this;




RE: select only false - lucavalentino - 07-10-2021

I solved
Modeld

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;
use 
App\Entities\Studente_e;


class 
Studente_m extends Model
{
protected 
$table      'tblstud';
protected 
$primaryKey 'ID';
protected 
$useAutoIncrement true;
protected 
$returnType 'App\Entities\Studente_e';
protected 
$useSoftDeletes true;

protected 
$allowedFields = ['name''email'];

/*protected $useTimestamps = false;
protected $createdField  = 'created_at';
protected $updatedField  = 'updated_at';
protected $deletedField  = 'deleted_at';*/

protected $validationRules    = [];
protected 
$validationMessages = [];
protected 
$skipValidation    false;
protected 
$useTimestamps true;

//public function __construct(){ $this->db = \Config\Database::connect(); $this->db = db_connect(); $this->builder = $this->db->table($this->table); }

  function check($id$email){

  $this->select('ID, NAME, EMAIL');
$this->from('tblstud');
  $this->where('ID'$ID);
  $this->where('EMAIL',$email);
  $query=$this->builder->get()->getResultArray();
...

Now how do I use entities
Quote:
Code:
namespace App\Entities;

use CodeIgniter\Entity\Entity;

class Studente_e extends Entity
{
protected $datamap = [
'MATRICOLA'=>'ID'
...}





RE: select only false - includebeer - 07-11-2021

I have examples on how to use models and entities in part 2 and part 5 of this series of tutorials. In these examples the code is in a library, but you can adapt the code to the functions in your model.


RE: select only false - InsiteFX - 07-12-2021

I also recommend new users to read @includebeer tutorials well worth the read.


RE: select only false - includebeer - 07-12-2021

(07-12-2021, 01:38 AM)InsiteFX Wrote: I also recommend new users to read @includebeer tutorials well worth the read.
Thanks @InsiteFX  Cool


RE: select only false - lucavalentino - 07-19-2021

I tried to use entities, but it doesn't work

Model

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;
//use CodeIgniter\Database\ConnectionInterface;
use App\Entities\Stud_e;


class 
Stud_m extends Model
{
protected 
$table      'tblstud';
protected 
$primaryKey 'NUM_MATRIC';
protected 
$useAutoIncrement true;
protected 
$returnType 'App\Entities\Stud_e::class';
protected 
$useSoftDeletes true;

protected 
$allowedFields = ['NUM_MATRIC''E_MAIL'];

protected 
$useTimestamps true;
protected 
$createdField  'created_at';
protected 
$updatedField  'updated_at';
protected 
$deletedField  'deleted_at';

protected 
$validationRules    = [];
protected 
$validationMessages = [];
protected 
$skipValidation    false;

//protected $db;


public function __construct()
{
$stud_e = new \App\Entities\Studente_e();
$this->db = \Config\Database::connect();
$stud_e = new Stud_e();

function 
get_dati($matr){
$this->select('*');
$this->where('NUM_MATRIC'$matr);
return  $query$this->builder->get()->getResultArray($this->stud_e);


Entities

PHP Code:
namespace App\Entities;

use 
CodeIgniter\Entity\Entity;

class 
Studente_e extends Entity
{
protected 
$attributes  = [
'NUM_MATRIC'=>null,
'SURNAME'=>null,
....
];
protected 
$datamap = [
'ID'=>'NUM_MATRIC',
'NAME_SURNAME'=>'SURNAME',
...
];
public 
$stuD_e;
public function 
__construct (array $data null)
{
parent::__construct($data);
$this->stud_e = [];




RE: select only false - InsiteFX - 07-19-2021

Your class is wrong.
PHP Code:
// wrong
use CodeIgniter\Entity\Entity;

// should be
use CodeIgniter\Entity

Your class is wrong.
PHP Code:
// wrong
use CodeIgniter\Entity\Entity;

// should be
use CodeIgniter\Entity



RE: select only false - paulbalandan - 07-19-2021

@InsiteFX

CodeIgniter\Entity\Entity is correct. It is the new FQCN of the Entity class. The former is deprecated already.