Welcome Guest, Not a member yet? Register   Sign In
Model files in CI4
#7

(This post was last modified: 07-13-2021, 03:30 AM by davis.lasis.)

Your files and code should look something like this:

Entities/ComuniEntity.php
PHP Code:
<?php
namespace App\Entities;

use 
CodeIgniter\Entity\Entity;

class 
ComuniEntity extends Entity
{
    protected $datamap = [];

    /**
    * Define properties that are automatically converted to Time instances.
    */
    protected $dates = ['updated_at''created_at'];

    /**
    * Array of field names and the type of value to cast them as
    * when they are accessed.
    */
    protected $casts = [];


Models/ComuniModel.php
PHP Code:
<?php
namespace App\Models;

use 
CodeIgniter\Model;
use 
App\Entities\ComuniEntity;

class 
ComuniModel extends Model
{
    protected $table 'AA_Tabella1';
    protected $returnType ComuniEntity::class;
    protected $allowedFields = ['column_1''column_2''column_3'];

    public function Leggi(string $Lingua ''
    {
        if (!empty($Lingua)) {
            return $this->where('Lingua'$Lingua)->first();
        }

        return $this->findAll();
    }


Controllers/Prova1.php
PHP Code:
<?php
namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
App\Models\ComuniModel;

class 
Prova1 extends BaseController
{
    public function index(string $Lingua 'en')
    {
        $modello = new ComuniModel();

        $Dati = [
            'Lingua' => $Lingua,
            'ListaLingue' => $modello->Leggi($Lingua),
        ];

        echo view('pagprova2'$Dati);
    }



I hope this will help you to get one "module" going and to continue on other 49...ish
Reply


Messages In This Thread
Model files in CI4 - by Filippo65 - 07-06-2021, 10:39 AM
RE: Model files in CI4 - by MGatner - 07-07-2021, 06:14 AM
RE: Model files in CI4 - by paliz - 07-07-2021, 09:17 AM
RE: Model files in CI4 - by Filippo65 - 07-12-2021, 10:06 AM
RE: Model files in CI4 - by includebeer - 07-12-2021, 03:44 PM
RE: Model files in CI4 - by InsiteFX - 07-12-2021, 09:04 PM
RE: Model files in CI4 - by davis.lasis - 07-13-2021, 03:29 AM
RE: Model files in CI4 - by Filippo65 - 07-14-2021, 11:18 AM
RE: Model files in CI4 - by includebeer - 07-14-2021, 02:23 PM
RE: Model files in CI4 - by Filippo65 - 07-19-2021, 10:57 AM
RE: Model files in CI4 - by includebeer - 07-19-2021, 02:45 PM
RE: Model files in CI4 - by Filippo65 - 07-20-2021, 10:52 AM
RE: Model files in CI4 - by Filippo65 - 07-20-2021, 12:47 PM
RE: Model files in CI4 - by Filippo65 - 07-21-2021, 10:30 AM
RE: Model files in CI4 - by includebeer - 07-23-2021, 04:52 AM
Model files in CI4 - by Filippo65 - 08-20-2021, 09:28 AM
RE: Model files in CI4 - by ikesela - 08-20-2021, 12:50 PM
RE: Model files in CI4 - by includebeer - 09-05-2021, 03:39 PM
RE: Model files in CI4 - by Filippo65 - 09-23-2021, 07:44 AM
RE: Model files in CI4 - by InsiteFX - 09-06-2021, 12:56 AM
RE: Model files in CI4 - by Filippo65 - 09-25-2021, 09:34 AM
RE: Model files in CI4 - by InsiteFX - 09-26-2021, 12:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB