Skip to content

Commit

Permalink
added session support, tailwind css
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryoalli committed Jun 10, 2023
1 parent 9d92e46 commit e19a3f3
Show file tree
Hide file tree
Showing 20 changed files with 1,808 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
node_modules/
vendor/
public/css/build/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Install


```bash
composer install
```

```bash
npm install
```

## Tailwind CSS

For development use `--watch`
```bash
npx tailwindcss -i ./public/css/app.css -o ./public/css/build/app.css --watch
```
6 changes: 6 additions & 0 deletions app/Controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public function about()
return view('about', ['company' => $company]);
}

public function whoops()
{
$name = "Whats up";
return view('partials.whoops', ['name' => $name]);
}

/**
* Show the contact page.
*/
Expand Down
64 changes: 57 additions & 7 deletions app/Core/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* @param array $data
*/
if(!function_exists('view')) {
function view($name, $data = [])
function view($view, $data = [])
{
$viewname = str_replace('.', '/', $view);
extract($data);

return require __DIR__."/../../app/views/{$name}.view.php";
return require __DIR__."/../../app/views/{$viewname}.view.php";
}
}

Expand Down Expand Up @@ -56,17 +57,14 @@ function loadEnv($filePath)

// Eliminar las comillas del valor si existen
$value = trim($value);
$value = trim($value,"'");
$value = trim($value, "'");
if (str_starts_with($value, '"') && str_ends_with($value, '"')) {
$value = substr($value, 1, -1);
}

// Agregar la variable al entorno
putenv("$name=$value");

// También puedes usar $_ENV o $_SERVER si lo prefieres
// $_ENV[$name] = $value;
// $_SERVER[$name] = $value;
}
// Uso:
//loadEnv(__DIR__ . '/.env');
Expand All @@ -76,10 +74,62 @@ function loadEnv($filePath)

}
}

if(!function_exists('env')) {
function env($key, $default='')
{
$result = empty(getenv($key))?$default:getenv($key);
$result = empty(getenv($key)) ? $default : getenv($key);
return $result;
}
}


if(!function_exists('session')) {
function session($key = null, $value = null)
{
// Iniciar la sesión si aún no ha sido iniciada
if (session_status() == PHP_SESSION_NONE) {
session_start();
}

// Si no se proporcionó un valor, obtener el valor de la sesión
if ($value === null) {
if ($key === null) {
// Si tampoco se proporcionó una clave, devolver todos los datos de la sesión
return $_SESSION;
} else {
// Si se proporcionó una clave, devolver el valor correspondiente de la sesión
return $_SESSION[$key] ?? null;
}
} else {
// Si se proporcionó un valor, establecer el valor en la sesión
$_SESSION[$key] = $value;
}
}
}


/**
* Clear session.
*
* Establecer un valor en la sesión
* session('key', 'value');
* Limpiar la sesión
* clearSession();
* Intentar obtener un valor de la sesión
* $value = session('key'); // Devuelve null
*/
if(!function_exists('clearSession')) {
function clearSession()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
}

// Liberar todas las variables de sesión
session_unset();

// Destruir la sesión
session_destroy();
}
}
3 changes: 2 additions & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$router->get('', 'PagesController@home');
$router->get('about', 'PagesController@about');
$router->get('contact', 'PagesController@contact');
$router->get('whoops', 'PagesController@whoops');

$router->get('users', 'UsersController@index');
$router->post('users', 'UsersController@store');
$router->post('users', 'UsersController@store');
4 changes: 2 additions & 2 deletions app/views/about-culture.view.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php require('partials/head.php'); ?>
<?php require('partials/head.view.php'); ?>

<h1>Our Culture at <?= $name; ?></h1>

<?php require('partials/footer.php'); ?>
<?php require('partials/footer.view.php'); ?>
4 changes: 2 additions & 2 deletions app/views/about.view.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php require('partials/head.php'); ?>
<?php require('partials/head.view.php'); ?>

<h1>About <?= $company; ?></h1>

<?php require('partials/footer.php'); ?>
<?php require('partials/footer.view.php'); ?>
8 changes: 5 additions & 3 deletions app/views/contact.view.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php require('partials/head.php'); ?>
<?php require('partials/head.view.php'); ?>

<h1>Contact Us</h1>
<main class="max-w-screen-lg mx-auto mt-12">
<h1 class="text-lg">Contact Us</h1>
</main>

<?php require('partials/footer.php'); ?>
<?php require('partials/footer.view.php'); ?>
4 changes: 2 additions & 2 deletions app/views/index.view.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php require('partials/head.php'); ?>
<?php require('partials/head.view.php'); ?>

<h1>Home Page</h1>

<?php require('partials/footer.php'); ?>
<?php require('partials/footer.view.php'); ?>
File renamed without changes.
8 changes: 0 additions & 8 deletions app/views/partials/head.php

This file was deleted.

10 changes: 10 additions & 0 deletions app/views/partials/head.view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en" class="h-screen">
<head>
<meta charset="UTF-8">
<title><?php echo env('APP_NAME','Mini PHP Framework'); ?></title>
<link href="/css/build/app.css" rel="stylesheet">
</head>
<body class="h-screen bg-gray-50">

<?php require('nav.view.php'); ?>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<nav>
<ul>
<nav class="max-w-screen-lg mx-auto bg-white px-4 py-2">
<ul class="flex justify-between">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/users">Manage Users</a></li>
<li><a href="/whoops">Whoops</a></li>
</ul>
</nav>
</nav>
1 change: 1 addition & 0 deletions app/views/partials/whoops.view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Whoops</h1>
4 changes: 2 additions & 2 deletions app/views/users.view.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php require('partials/head.php'); ?>
<?php require('partials/head.view.php'); ?>

<h1>All Users</h1>

Expand All @@ -13,4 +13,4 @@
<button type="submit">Submit</button>
</form>

<?php require('partials/footer.php'); ?>
<?php require('partials/footer.view.php'); ?>
Loading

0 comments on commit e19a3f3

Please sign in to comment.