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
    • Controllers
      • welcome.php
    • Models
      • Hello.php
    • Views
      • template.php
      • content.php
  • Core
    • Classess
      • Base.php
      • Db.php
      • Request.php
      • Validator.php
      • View.php
    • config.php
    • helper.php
  • public
    • EPages
      • 404.html
    • css
      • style.css
    • img
      • logo-yesframework.png
    • index.php
.htaccess Files and index.html are omitted in this description.

The application must be built in the App. Controller default welcome.php is located in the Controllers.

Before starting work, you must correctly configure the file 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\Classess\Db):

Db::pdo_insert(string $query, array $var = [], bool $secure_input = true, bool $key=false) - add the record to the database. Returns the last ID after successful addition. The key argument is responsible for binding by key names instead of numbers.
Example:
Db::pdo_insert("INSERT table(column1, column2) VALUES(?,?)", array(' value1',' value2'),false, true);


Db::pdo_update(string $query, array $var = [], bool $execute_result = false, bool $secure_input = true, bool $key=false) - updating of that record. By default, if any record changes, it will return the number of changed records. If you just want to know if the method was done, change $ execute_result to true. Then, true or false is returned. The key argument is responsible for binding by key names instead of numbers.
Example
Db::pdo_update("UPDATE column1 FROM table SET column1=?", array('value1'),false,false,false);


Db::pdo_query(string $query) - classic functions to perform any query. Returns the "execute()" of a 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::pdo_query("SELECT * FROM table");


Db::pdo_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:
pdo_read("SELECT * FROM table WHERE column1=?", array('value'));


Db::pdo_read_no_numbers(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:
pdo_read_no_numbers("SELECT * FROM table WHERE column1=?",array('value'));


Db::pdo_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::pdo_delete("DELETE FROM table WHERE id=?", array('value'));


Db::pdo_transaction($query = array()) - function executes transactions.
Example:
$query = array(
array("INSERT table(column1) VALUES(?)", array(' 7'))
array("INSERT table(column2) VALUES(?)", array(' 8'))
);
Db::pdo_transaction(array $query);


View functions (use Core\Classess\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\Classess\Validator):

Validator::check_email(string $email) - check if a variable is an e-mail. If so - it does nothing if you do not - interrupt the script.

Validator::check_ip(string $ip) - checks whether a variable is the IP number. If so - it does nothing if you do not - interrupt the script.

Validator::check_integer(int $data, bool $param) - check if a variable is an integer. The variable $param allows you to set whether checked integer can be negative or not. $param = false - non-negative variable, $param = true variable may be negative. If so - it does nothing if you do not - interrupt the script.

Validator::rule_no_empty(array $array = [], array $param = []) - function checks whether the array $array does not include the blank keys, which are indicated in $param. If the validation fails, the script is interrupted. This function is useful eg. When checking the data fields in the form have been filled.
Example 1:
Validator::rule_no_empty($_POST,array('name','email'));
If name or email from $_POST will be empty, the function will abort the script.
Example 2:
Validator::rule_no_empty($_POST,array('ALL'));
In the example above, if any value of $ _POST array is empty, the function will abort the script.

Request functions (use Core\Classess\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.


Helpers function:

check_email(string $date) - check if a variable is an e-mail. Returns true or false.

check_ip(string $ip) - checks whether a variable is the IP number. Returns true or false.

check_integer(int $data, bool $param = false) - check if a variable is an integer. The variable $param allows you to set whether checked integer can be negative or not. $param = false - non-negative variable, $param = true variable may be negative. Returns true or false.

check_integer_in_array(bool $param = false, array $array = []) - checks whether the whole array contains integers. The variable $param allows you to set whether checked integer can be negative or not. $param = false - non-negative variable, $param = true variable may be negative. Returns true or false.

secure_input(string $date) - cleans array with special characters. Returns purified variable.

redirect(string $url, $redirect_301 = false) - redirects the user to the specified variable path.

getIP() - get IP address.

getServIP() - get server IP address.

genHoursOptionsList() - generates a list of hours as <option>.

genMinutesOptionsList() - generates a list minute as <option>.

getCSRF() - Gets the security code before the attack CSRF.

curl_get(string $url, int $time, bool $cert_verify = true) - makes a call CURL as GET, it returns the response was received from the specified URL. As the second parameter is the time TIMEOUT in seconds. The third parameter to control the SSL certificate (takes true or false)

curl_get_header(string $url, int $time, bool $cert_verify = true, array $headers) - makes a call CURL as GET with custom headers, it returns the response was received from the specified URL. As the second parameter is the time TIMEOUT in seconds. The third parameter to control the SSL certificate (takes true or false)

curl_post($url, $time, $cert_verify, $params=array()) - makes a call CURL as POST. Variable $time is TIMEOUT in seconds. The third parameter to control the SSL certificate (takes true or false). The variable $param should include variables to send.
Example:
$param = array(
'var1' =>'value1',
'var2' =>'value2',
);

echo curl_post('http://example.com',2,0,$param);
curl_post_header(string $url, int $time, bool $cert_verify = true, array $params = [], array $headers) - makes a call CURL as POST with custom headers. Variable $time is TIMEOUT in seconds. The third parameter to control the SSL certificate (takes true or false). The variable $param should include variables to send.

curl_json_post(string $url, int $time, bool $cert_verify = true, string $params) - makes a call CURL as POST with JSON data. Variable $time is TIMEOUT in seconds. The third parameter to control the SSL certificate (takes true or false). The variable $param should include variables to send.

rule_no_empty(array $array = [], array $param = []) - It works on the same principle as previously described function Validator::rule_no_empty(array $array = [], array $param = []). The difference is that if it is ok = returns true, and if it finds an empty element, returns false instead of aborting the script.

url_base64_encode(string $string) - function encodes data into base64 in the URL-friendly version.

url_base64_decode(string $string) - function decodes data from base64 from the URL-friendly version.

true_empty(mixed $data) - the function checks whether the data is actually empty.

secure_array(array $array) - the function builds a new filtered table.

check_json(string $json) - the function checks if the given string is compatible with the JSON format.

CORSHeaders() - this function solves the problem related to CORS.