Task framework

About the framework



The task framework is based on the MVC paradigm with ease of use and a minimum of functionality for solving simple tasks.



Unlike standard solutions, instead of a controller, a task is used here



A link to a framework that also uses task.



jsock-framework-tutorial.blogspot.com

java-framework-jsocket.blogspot.com

github.com/nnpa/jsock



Installing the task framework



1. Download the archive with the framework



2. Unpack it into the task folder into the directory where you store your sites.



3. Download the framework for the application



4. Unpack it into the site folder in the directory where you store your sites.



5. Create a database in mysql.



6. Download the users table and export to the created database.



You should get such a directory tree



/webroot/task

/webroot/site


7. Configure the web server so that the root folder / webroot / site is bound to a specific host using the web server you are using.



8. Go to the config folder and open config.php and edit the database connection array with your connection values ​​and host variable.



MVC paradigm



The Task framework uses the MVC paradigm to better separate the logic of view templates, models, and controller.



Instead of a controller, the Task framework uses Task tasks - tasks are located in the tasks folder and are designed to execute application logic.



Models are stored in the models folder and are designed to work with database logic.



Views are stored in the views folder and are designed to work with presentation logic.



Task



Task (or Controller) are located in the tasks folder.



Tasks are created by the variable in the url of the site request:



If the variable request = test, then an instance of the Task class will be created, which is stored in the tasks folder in the test.php file and is called test.



index.php?request=test


An example of the test.php class:



include_once('WebTask.php');

class Test extends WebTask{

	public function run(){

          // 

        }

}


The task must be inherited from WebTask and the run () method must be created in it



Models



Models are located in the models folder and are responsible for the logic of working with the database.



The most common way to create models is in tasks.



The model must be created in the models folder and be inherited from Model, the $ table_name field must also be written.



An example class models / users.php:



class Users extends Model{

    public $table_name = 'users';

}


In the Model class, a set of methods for working with the database is pre-implemented.



findBySql



$users = new Users();

 $users->findBySql("SELECT * FROM `users`");

foreach($users as $user) {

      echo $user['email'] . "<br>";

}


findByPk



$users = new Users();

 $users->findByPk(3);

 echo $users->email;


find



$users = new Users();

 $users->find("email <> ''");

foreach($users as $user) {

     echo $user['email'] . "<br>";

}


update



$users = new Users();

 $users->findByPk(3);

$users->email = "yandex@mail.ru";

$users->update();


save



$users = new Users();

$users->email = "yandex@mail.ru";

$users->id    = NULL;

$users->save()


delete



$users = new Users();

$users->delete("id = 6");


exec



$users = new Users();

$users->exec("free sql string"); //mysqli_result


DB



App::$DB->exec("free sql string");//mysqli_result


view



View templates are stored in the / view / folder and are responsible for the view logic.



The view is called at the end of the run method of the task class using the render method.



Variables are passed to the view that will be used in the view logic.



Example site task:



include_once('WebTask.php');

class Site extends WebTask{

	public function run(){

              $users = new Users();

               $users->find("email <> ''");

	       $this->render('site',[

			'users' => $users,

		]);

	}

}


In the run method, the model with users is passed to the view / site.php template, where the search results are processed and html is generated:



<?php

foreach($users as $user) {

    echo $user['email'] . "<br>";

}

?>


Also in the view / layout folder is the main template main.php which is the main template where our views are loaded into the {content} variable.



User authorization



The framework has already implemented registration and authorization using the login and register links.



The application method that allows you to check if the user is authorized. App :: isGuest ()



At the end of the

task-framework blog, the



framework will continue to develop and test on applications developed on it.



Thanks.



All Articles