GithubHelp home page GithubHelp logo

ewa's Introduction

Meet EWA

EWA is website application for building small or medium size websites and web apps. It stems from the code I created for my own projects. Recently I decided to share it so that others can use it too or want to contribute to develop further together.

Getting started

Easy installation to get started building with EWA.

  1. upload the files on your server
  2. setup your webserver and point your document root to the httpdocs folder.
  3. open the 'basic.conf.php' file in the app/lib/config folder
  4. change the settings matching your information. Do not touch the 'app settings', this might break EWA.
  5. Go to the browser type in the url and enjoy!
  6. Time to write your app/website code on the core of EWA, amaze her.

Website class view method

Pages and templates are loaded dynamically. Make a new file in de index folder (For Example: /app/index/contact.php). The goal is to keep the logic in the index files and build up the view from the view folder. With the already loaded website class you can request to load the view.

In the new file in the index folder call the following function to load the view:

$app->loadView($view, $data = '');

The system will search for a file with the given name as the first param. You can pass data to the view. This can be a single string, boolean, array, object and methods. For example:

$myArray = array('title'=>'Hello World!');
$app->loadView('contact', $myArray);

In the view the data is available by simply calling:

return $data or echo $data

With the data we passed an echo will generate an error. So we can print hello world by the following code:

echo $data['title'];

It is recommended only to pass data to build up the view, and leave all the logic in the index files.

Database class

The database class is made to supply basic ready to go methods to select, insert, update and delete data from a database.

$db = new Database();

In the examples below 'users' is a table in the database. The 'name', 'mail' and 'id' are the rows.

Selecting data from a database is easy and does not need a lot of code:

$db->limit(5)->orderby('name', 'DESC')->get('users', array('name','mail'));

$db->where('id', 1)->get('users', array('name','mail'));

If you want every item from the table, just leave the second param empty.

$db->get('users');

Example to handle the results:

$db = new Database();

$query = $db->get('users');

if($query->results) {
	
	echo '<h1>Users</h1>';
	echo '<p>You have fetched '.$query->count.' user(s).</p>';
	echo '<table>';
	
	foreach($query->results as $user) {
	
		echo '<tr>';
		echo '<td>'.$user->id.'</td>';
		echo '<td>'.$user->username.'</td>';
		echo '<td>'.$user->mail.'</td>';
		echo '</tr>';
	
	}
	
	echo '</table>';
	
} else {

	echo $query->message;
	
}

Insert data in the database:

$db->add('users', array('name'=>'Jan', 'mail'=>'[email protected]'));

Update data in the database:

$db->where('id', 11)->update('user', array('name'=>'Mikey', 'mail'=>'[email protected]'));

Delete data from the database.

$db->where('id', 11)->remove('users');

Mail class

How to send an e-mail:

$mail = new Mail();

// Full name of the recipient. 
$toName = '';

// E-mail address of the recipient.
$toMail = '';

// E-mail subject
$subject = '';

// This is the mail template name that needs to be loaded
$template = '';

/**
 * This array hold values to replace placeholders in the e-mail template.
 * The keys are written as follows: {name}
 */
$replaceArray = array (
	'name' => 'Firtname Lastname',
	'username' => 'user9',
);

// This will return a boolean
$mail->sendMail($toName, $toMail, $subject, $template, $replaceArray);

The e-mail can look like this:

Hello {name}
<br/><br/>
This is a confirmation about your registration.
You're username is: {username}
<br/><br/>
Kind Regards,
<br/><br/>
Webteam

Save a template per language like this: welcome.en.mail.php and for a Dutch version: welcome.nl.mail.php

Password Generation

Password validation check and generation is included in the core code:

// The password given by the user (for example via a $_POST var)
$password = '';

/** 
 * Set the minimum length for the password. This field can be left empty.
 * When this field is left out, EWA will use the constant: PASSWORD_LENGTH
 */
$length = 8;

/**
 * By default strict is false.
 * strict: uppercase and lowercase letters, numbers, special characters.
 */
$strict = true;

try {
	
	// Check if the password comply
	Validator::isValidPassword($password, $length, $strict);
	
	// Generate a hash from the password
	$hash = Helper::generatePasswordHash($password);
	
	// For example save it in the DB with the username
	$db = new Database();
	
	$query = $db->add('users', array('username'=>'Jan', 'password'=>$hash));
	
	if($query->results) {
		echo 'New user successfully saved!';
	}
	
	
} catch (Exception $e) {

	echo $e->errorDisplay();
	
}

ewa's People

Contributors

jasmaine avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.