codeigniter 9

Codeigniter 4🔥 [09.- model]

En este tutorial vamos a trabajar con los modelos y en particular vamos a extraer los datos que colocamos en nuestra base de datos del tutorial anterior.
Codigo en github.com: https://github.com/programadornovato/codeigniter4/commit/10129ef82d40f77990d18dd84795fe942aff06cd

///.env
#--------------------------------------------------------------------
# Example Environment Configuration file
#
# This file can be used as a starting point for your own
# custom .env files, and contains most of the possible settings
# available in a default install.
#
# By default, all of the settings are commented out. If you want
# to override the setting, you must un-comment it by removing the '#'
# at the beginning of the line.
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

 CI_ENVIRONMENT = development

#--------------------------------------------------------------------
# APP
#--------------------------------------------------------------------

 app.baseURL = 'http://localhost/ci4/'
# app.forceGlobalSecureRequests = false

# app.sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler'
# app.sessionCookieName = 'ci_session'
# app.sessionSavePath = NULL
# app.sessionMatchIP = false
# app.sessionTimeToUpdate = 300
# app.sessionRegenerateDestroy = false

# app.cookiePrefix = ''
# app.cookieDomain = ''
# app.cookiePath = '/'
# app.cookieSecure = false
# app.cookieHTTPOnly = false

# app.CSRFProtection  = false
# app.CSRFTokenName   = 'csrf_test_name'
# app.CSRFCookieName  = 'csrf_cookie_name'
# app.CSRFExpire      = 7200
# app.CSRFRegenerate  = true
# app.CSRFExcludeURIs = []

# app.CSPEnabled = false

#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

 database.default.hostname = localhost
 database.default.database = ci4
 database.default.username = eugenio
 database.default.password = 123456
 database.default.DBDriver = MySQLi

# database.tests.hostname = localhost
# database.tests.database = ci4
# database.tests.username = root
# database.tests.password = root
# database.tests.DBDriver = MySQLi

#--------------------------------------------------------------------
# CONTENT SECURITY POLICY
#--------------------------------------------------------------------

# contentsecuritypolicy.reportOnly = false
# contentsecuritypolicy.defaultSrc = 'none'
# contentsecuritypolicy.scriptSrc = 'self'
# contentsecuritypolicy.styleSrc = 'self'
# contentsecuritypolicy.imageSrc = 'self'
# contentsecuritypolicy.base_uri = null
# contentsecuritypolicy.childSrc = null
# contentsecuritypolicy.connectSrc = 'self'
# contentsecuritypolicy.fontSrc = null
# contentsecuritypolicy.formAction = null
# contentsecuritypolicy.frameAncestors = null
# contentsecuritypolicy.mediaSrc = null
# contentsecuritypolicy.objectSrc = null
# contentsecuritypolicy.pluginTypes = null
# contentsecuritypolicy.reportURI = null
# contentsecuritypolicy.sandbox = false
# contentsecuritypolicy.upgradeInsecureRequests = false

#--------------------------------------------------------------------
# HONEYPOT
#--------------------------------------------------------------------

#  honeypot.hidden = 'true'
#  honeypot.label = 'Fill This Field'
#  honeypot.name = 'honeypot'
#  honeypot.template = '<label>{label}</label><input type="text" name="{name}" value=""/>'





//app/Controllers/Home.php
<?php namespace App\Controllers;

use CodeIgniter\Controller;
use App\Models\UserModel;

class Home extends BaseController
{
	public function index()
	{
		$userModel=new UserModel($db);
		$user=$userModel->find('1');
		var_dump($user);
		$estructura=view('estructura/header').view('estructura/body',$user);
		return $estructura;
	}

	//--------------------------------------------------------------------

}




//app/Models/UserModel.php
<?php namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
        protected $table      = 'users';
        protected $primaryKey = 'id';

        protected $returnType = 'array';
        protected $useSoftDeletes = true;

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

        protected $useTimestamps = false;
        protected $createdField  = 'created_at';
        protected $updatedField  = 'updated_at';

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





//app/Views/estructura/body.php
<body>
    Hola  <?php echo $email; ?>
</body>
</html>


Guia de codeigniter 4: https://codeigniter4.github.io/userguide/models/model.html

Codeigniter 4? [09.- model]

#Codeigniter4 #php7 #backend #Codeigniter #php .
? Esta lista de reproducción: https://www.youtube.com/playlist?list=PLCTD_CpMeEKTFN5TDeOP-wP_hU0_9VoWg

Codigos en gdrive: https://drive.google.com/file/d/1awbG6jI40IO0N68fgjLUwNFpsTC3wIHj/view?usp=sharing .
Gracias por apoyar este canal: https://www.patreon.com/programadornovato?fan_landing=true .
? Facebook: https://facebook.com/ProgramadorNovatoOficial
? Twitter: https://twitter.com/programadornova
? Linkedin: https://www.linkedin.com/in/programadornovato/
? Instagram: https://www.instagram.com/programadornovato/

.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Información básica sobre protección de datos Ver más

  • Responsable: Eugenio Chaparro.
  • Finalidad:  Moderar los comentarios.
  • Legitimación:  Por consentimiento del interesado.
  • Destinatarios y encargados de tratamiento:  No se ceden o comunican datos a terceros para prestar este servicio. El Titular ha contratado los servicios de alojamiento web a digitalocean.com que actúa como encargado de tratamiento.
  • Derechos: Acceder, rectificar y suprimir los datos.
  • Información Adicional: Puede consultar la información detallada en la Política de Privacidad.

Esta web utiliza cookies propias y de terceros para su correcto funcionamiento y para fines analíticos y para mostrarte publicidad relacionada con sus preferencias en base a un perfil elaborado a partir de tus hábitos de navegación. Contiene enlaces a sitios web de terceros con políticas de privacidad ajenas que podrás aceptar o no cuando accedas a ellos. Al hacer clic en el botón Aceptar, acepta el uso de estas tecnologías y el procesamiento de tus datos para estos propósitos. Más información
Privacidad