Skip to content

Instantly share code, notes, and snippets.

View vihugarcia's full-sized avatar

Victor Hugo Garcia vihugarcia

View GitHub Profile
@vihugarcia
vihugarcia / ClientController.php
Last active July 29, 2023 16:29
Chapter 7 ClientController class
<?php
namespace controllers;
use core\Controller as Controller;
use models\Client as Client;
use core\View as View;
use widgets\DataTable as DataTable;
use core\db as db;
class ClientController extends Controller {
@vihugarcia
vihugarcia / form.php
Created July 31, 2022 22:15
Form to test the File Uploader class
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
require_once "FileUploader.php";
$uploader = new FileUploader("file", $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "uploads");
try {
$uploader->uploadFile();
echo "File uploaded succesfully";
} catch (Exception $e) {
@vihugarcia
vihugarcia / FileUploader.php
Created July 31, 2022 22:14
File Uploader class for the book PHP MVC
<?php
class FileUploader {
private $fileName;
private $targetDir;
private $targetFile;
private $errors;
public function __construct($fileName, $targetDir = '')
{
$this->fileName = $fileName;
@vihugarcia
vihugarcia / db.php
Last active September 6, 2022 12:59
Chapter 03 of PHP MVC: db class
<?php
namespace core;
class db {
private $_connection;
public function __construct(array $CONFIG)
{
try {
$this->_connection = new \PDO(
@vihugarcia
vihugarcia / user-add.component.html
Last active September 24, 2022 21:17
Chapter 4: User add view
<div class="container" style="margin-top: 40px;">
<form [formGroup]="userForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" formControlName="first_name" class="form-control">
<div *ngIf="submitted && userForm.controls['first_name'].errors" class="error">
<div *ngIf="userForm.controls['first_name'].errors['required']">
Your first name is required
</div>
@vihugarcia
vihugarcia / user-detail.component.html
Created April 4, 2021 14:19
Chapter 4: User detail view
<div *ngIf="user" class="container" style="margin-top: 40px;">
<div class="card" style="width: 100%;">
<div class="card-body">
<div class="row">
<div class="col-4" style="text-align: center;">
<img *ngIf="user.avatar" [src]="user.avatar" class="card-img-top img-thumb" [alt]="user.first_name">
<h5 class="card-title">{{user.first_name}}</h5>
<div class="form-inline">
<label for="user-name">Name: </label>
<input id="user-name" [(ngModel)]="user.first_name" placeholder="name" class="form-control">
@vihugarcia
vihugarcia / reqres.service.ts
Created April 3, 2021 19:41
Chapter 3: ReqresService
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from '../user';
@Injectable({
providedIn: 'root'
})
export class ReqresService {
private url = 'api/users';
@vihugarcia
vihugarcia / in-memory-data.service.ts
Last active April 18, 2021 12:54
Chapter 3: InMemoryDataService
import { Injectable } from '@angular/core';
import { InMemoryDbService } from 'angular-in-memory-web-api';
import { User } from '../user';
@Injectable({
providedIn: 'root',
})
export class InMemoryDataService implements InMemoryDbService {
createDb() {
const users = [
@vihugarcia
vihugarcia / auth.service.ts
Created August 9, 2019 00:59
AuthService final version
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import * as auth0 from 'auth0-js';
@Injectable()
export class AuthService {
private _idToken: string;
private _accessToken: string;
private _expiresAt: number;
@vihugarcia
vihugarcia / auth.service.ts
Created August 9, 2019 00:57
AuthService second draft
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import * as auth0 from 'auth0-js';
@Injectable()
export class AuthService {
private _idToken: string;
private _accessToken: string;
private _expiresAt: number;