Documentation
Before you read the documentation, see the section How to start
here to know the principle of yesFramework.
yesFramework made up with the following files and directories.
src/yesFramework folder:
- App
- Core
- Classes
- Base.php
- Db.php
- Http.php
- Request.php
- Router.php
- Str.php
- Validator.php
- View.php
- Exceptions
- config.php
- public
.env, .htaccess files, and index.html are omitted in this description.
The application must be built in the
App directory. The default controller
WelcomeController.php is located in
Controllers.
Before starting work, you must configure the file
.env in root directory and
config.php, which is located in the
Core. Individual lines have been adequately described by comments.
Available functions
yesFramework has several built-in features.
Basic functions (use Core\Classess\Base):
Base::load_view(string $template, string $content, array $var = []) - loads view file
Example
Base::load_view('template.php','content.php',['value1','value2']);
Base::send_service_email(string $toemail, string $title, string $message_body) – send HTML e-mail in which the sender of the e-mail is set in config.php
Example:
Base::send_service_email('email_destination','example title','example content in html');
Base::send_email(string $fromemail, string $toemail, string $title, string $message_body) – send HTML email, with a fixed sender
Example:
Base::send_email('email_sender','email_destination','example title','example content in html');
Features for database (use Core\Classes\Db):
Note: The database instance is usually passed to your controllers via Dependency Injection as $this->db. These methods are no longer static.
$db->insert(string $query, array $var = [], bool $key = false) - a function adds to the base record.
Returns the last ID after successful addition. The key argument is responsible for binding by key names instead of numbers.
Example:
$db->insert("INSERT INTO table (column1, column2) VALUES (?,?)", array('value1', 'value2'));
$db->update(string $query, array $var = [], bool $key = false) - updating of that record. It will return the number of changed records. The key argument is responsible for binding by key names instead of numbers.
Example
$db->update("UPDATE table SET column1=? WHERE id=?", array('value1', 1));
$db->unsafeRawQuery(string $query) - classic functions to perform any query. I do not recommend using it for classic queries due to the lack of built-in protection against SQL Injection. Function only for advanced users.
Example:
$db->unsafeRawQuery("SELECT * FROM table");
$db->read(string $query, array $var = [], bool $key = false) - a function to read data from the database. Returns query results. The key argument is responsible for binding by key names instead of numbers.
Example:
$db->read("SELECT * FROM table WHERE column1=?", array('value'));
$db->readNoNumbers(string $query, array $var = [], bool $key = false) - a function to read data from the database without returning numbers in the array. Returns query results. The key argument is responsible for binding by key names instead of numbers.
Example:
$db->readNoNumbers("SELECT * FROM table WHERE column1=?",array('value'));
$db->delete(string $query, array $var = [], bool $key = false) - deletes the records. Returns the number of deleted records. The key argument is responsible for binding by key names instead of numbers.
Example
$db->delete("DELETE FROM table WHERE id=?", array('value'));
$db->transaction(array $query = [], bool $key = false) - function executes transactions.
Example:
$query = array(
array("INSERT INTO table(column1) VALUES(?)", array(' 7')),
array("INSERT INTO table(column2) VALUES(?)", array(' 8'))
);
$db->transaction($query);
View functions (use Core\Classes\View):
View::input(string $type, string $name, array $options = []) - creates INPUT tag in the HTML code of the specified parameters. An array of options: id, class, placeholder, value
Example:
Code:
echo View::input("text","my name", array("value"=>"my value", "size"=>"50", "myparam"=>"required"));
Result:
<input type="text" name="my name" value="my value" size="50" required />
View::option(string $value1, string $value2 = NULL) - creates OPTION tag in the HTML code of the specified parameters..
Example:
Code:
echo View::option("my value 1","my value 2");
Result:
<option value="my value 1">my value 2</option>
Validation functions (use Core\Classes\Validator):
Validator::isEmail(string $email) - check if a variable is an e-mail. Returns a boolean.
Validator::isIp(string $ip) - checks whether a variable is the IP number. Returns a boolean.
Validator::isInteger($data, bool $allowNegative = false) - check if a variable is an integer. The variable $allowNegative allows you to set whether checked integer can be negative or not. Returns a boolean.
Validator::isIntegerInArray(array $array, bool $allowNegative = false) - checks whether all items in array are integers. Returns a boolean.
Validator::noEmpty(array $array, array $keysToCheck = []) - function checks whether the array does not include the blank keys, which are indicated in $keysToCheck. Returns a boolean.
This function is useful eg. When checking the data fields in the form have been filled.
Example 1:
Validator::noEmpty($_POST,array('name','email'));
If name or email from $_POST is empty, it returns false.
Example 2:
Validator::noEmpty($_POST,array('ALL'));
In the example above, if any value of $_POST array is empty, it returns false.
Validator::isTrueEmpty($data) - the function checks whether the data is actually empty. Note that 0 is not considered empty.
Request functions (use Core\Classes\Request):
Request::get($value=NULL) - function handles $_GET.
Example 1:
Request::get(string $value)
Check whether there is a $ _GET, if so, the function returns the value of this array, if not, the function returns empty array;
Example 2:
Request::get('email')
Check whether there is a $ _GET['email'], if so, the function returns the value of this array, if not, the function returns empety array;
The following functions of the class Request operate on the same principle, only support other types of arrays:
Request::post(string $value) - function handles $_POST.
Request::session(string $value) - function handles $_SESSION.
Request::server(string $value) - function handles $_SERVER.
String functions (use Core\Classes\Str):
Str::secureInput(string $data) - cleans array with special characters. Returns purified variable.
Str::secureArray(array $array) - the function builds a new filtered table.
Str::urlBase64Encode(string $string) - function encodes data into base64 in the URL-friendly version.
Str::urlBase64Decode(string $string) - function decodes data from base64 from the URL-friendly version.
Str::isJson(string $json) - the function checks if the given string is compatible with the JSON format.
HTTP functions (use Core\Classes\Http):
Http::redirect(string $url, bool $redirect_301 = false) - redirects the user to the specified path.
Http::getIP() - get IP address.
Http::getServIP() - get server IP address.
Http::getReferer() - get HTTP Referer.
Http::getCSRF() - Gets the security code before the attack CSRF.
Http::jsonResult(string $status, string $message, string $message_type) - Return json result.
Http::setCORSHeaders() - this function solves the problem related to CORS.
Http::curlGet(string $url, int $time = 10, bool $cert_verify = true) - makes a call CURL as GET, it returns the response was received from the specified URL.
Http::curlGetHeader(string $url, int $time = 10, bool $cert_verify = true, array $headers = []) - makes a call CURL as GET with custom headers.
Http::curlPost(string $url, int $time = 10, bool $cert_verify = true, array $params = []) - makes a call CURL as POST.
Http::curlPostHeader(string $url, int $time = 10, bool $cert_verify = true, array $params = [], array $headers = []) - makes a call CURL as POST with custom headers.
Http::curlJsonPost(string $url, int $time = 10, bool $cert_verify = true, string $params = "") - makes a call CURL as POST with JSON data.