📜 ⬆️ ⬇️

Create an application on Doophp 1.5

I was very upset that I did not find a similar theoretical article in Habré. And so there is DooPHP version 1.5 which was released on October 6, 2013. The official website translated such graphics performance

image

Also on Habré there is an article about the performance link .
')
Development of a simple form of logging under the cat.

So, we have OpenServer:

image

With this configuration:

image

Also on the DooPHP off site , the links to the framework files were not working, with Google I found version 1.5 here .

Let's start:

In the root directory of the site (I have this C: \ web \ OpenServer \ domains \ doophp), we unpack all the contents from the archive in the “app” folder, also the “dooframework” folder. We have the following structure:

image

We understand in more detail what's what:

“Dooframework” - all files of the framework itself.
“Global” is the storage of site files (css, js, img, swf).
“Protected” - php files of your application (configuration files, controller, model, maps, additional modules).
"Tools" - add. utilities and tools.

Customize our application:

Edit the settings file (C: \ web \ OpenServer \ domains \ doophp \ protected \ config \ common.conf.php)
set the paths to the folder with the framework files and our application:
$config['SITE_PATH'] = '/'; $config['BASE_PATH'] = '/dooframework/'; 


in $config['SITE_PATH'] = '/'; you need to specify the full path and end it with a '/' symbol (C: \\ web \ .... /).

We can also configure which errors to display and the time zone:
 error_reporting(E_ALL | E_STRICT); date_default_timezone_set('Asia/Kuala_Lumpur'); 

Go to our web browser go to our address and see:

image

A welcome page for the framework.

Database Setup:

Create a table (User) with fields:

id
username
password
name

 CREATE TABLE `test`.`User` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `username` VARCHAR( 20 ) NOT NULL , `password` CHAR( 32 ) NOT NULL , `name` VARCHAR( 40 ) NOT NULL ); 


Now we need to connect the database to the framework; we do this in the file C: \ web \ OpenServer \ domains \ doophp \ protected \ config \ db.conf.php

uncomment and customize the line:
 $dbconfig['dev'] = array('localhost', 'database', 'root', '1234', 'mysql', true); 


you also need to configure the routing to do this in the root uncommenting .htaccess and in the file

C: \ web \ OpenServer \ domains \ doophp \ protected \ config \ routes.conf.php

Add:

 $route['*']['/login'] = array('LoginController', 'index'); 


Controller:

In the folder C: \ web \ OpenServer \ domains \ doophp \ protected \ controller we create a new file LoginController.php

We write in it:

 <?php class LoginController extends DooController {//  LoginController  DooController protected $data = array(); /* This function is called by DooPHP before we run an action */ public function beforeRun($resouce, $action) { // Get the sites base url ie http://localhost/ (includes the / at the end) $this->data['app_url'] = Doo::conf()->APP_URL; } public function index() { $this->data['pagetitle'] = 'login'; $this->view()->render('login',$this->data);//  } } ?> 


Display:

In the folder C: \ web \ OpenServer \ domains \ doophp \ protected \ view create a file login.html with the contents:

 <html> <head> <title>To Doo List Manager :: {{pagetitle}}</title> </head> <body> <h1>To Doo List Manager :: {{pagetitle}}</h1> <p>Please Login</p> <form method="post"> <label for="txt_username">Username</label> <input type="text" name="txt_username" /><br /> <label for="txt_password">Password</label> <input type="password" name="txt_password" /><br /> <p class="error">Error: {{errorMsg}}</p> <input type="submit" value="Login" /> </form> </body> </html> 


PS when rendering, I got an error saying that such a file was not found in the viewc folder, as I understand it is the cache, but instead of the login.php file in this same folder, the login.php folder was created, I think it is either from the PHP version since I it is 5.3. *, and is required by documentation 5.1. *. I created an empty login.php file missing.

Model

In the folder C: \ web \ OpenServer \ domains \ doophp \ protected \ model create a file and fill it

 Doo::loadCore('db/DooModel'); class User extends DooModel { public $id; public $username; public $password; public $name; public $_table = 'user'; public $_primarykey = 'id'; public $_fields = array('id', 'username', 'password', 'name'); public function get_user(){ if(!$this->username or !$this->password){ return array('errorMsg'=>"At least one field was empty"); }else{ $a=Doo::db()->find( $this, array('limit'=>1)); if($a){ return true; }else return array('errorMsg'=>"no user or wrong pass"); } } function __construct(){ parent::$className = __CLASS__; } } 


After that we add an entry to the routing so that the POST request goes to the method we need in the routes.conf.php file

add row

 $route['post']['/login'] = array('LoginController', 'login'); 


Add a welcome file to the display for the user who has logged in.
in the package "view" create a file success.html write it

 <html> <body> <h1>Success!</h1> </body> </html> 


Add a check function to the controller:
  public function login() { $this->data['pagetitle'] = 'login'; Doo::loadModel('User'); $u = new User; $u->username=$_POST['txt_username']; $u->password=md5($_POST['txt_password']); $ab=$u->get_user(); if(isset($ab['errorMsg'])){ $this->data['errorMsg']=$ab['errorMsg']; $this->view()->render('login',$this->data); }else{ $this->view()->render('success'); } } 


We check the performance:

Enter the empty fields see the error.

image

Entering the wrong password, we see an error.

image

Enter the correct username and password see the welcome form.

image

findings

When developing this mini task, it was not difficult to find documentation and examples, but with more difficult tasks the community will be sorely missed. Also, many things in more popular frameworks are implemented automatically. You can develop something on this product or choose more popular frameworks with more complete documentation and community.

Project on Github: https://github.com/izac1/DoophpSimpleApp.git

Source: https://habr.com/ru/post/216251/


All Articles