Skip to content

Commit 1ed8462

Browse files
authored
Merge pull request #28 from NisanurBulut/dev-mvcphp
Dev mvcphp is complated
2 parents fb6f348 + 3c88489 commit 1ed8462

File tree

14 files changed

+75
-51
lines changed

14 files changed

+75
-51
lines changed

SayHiPhpMvc/ReadMe.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
- Composer.json ve index.php aynı seviyede yer alması best practise değildir.
2-
- __ ile başlayan tüm yöntem isimleri PHP tarafından ayrılmıştır. Bu nedenle, PHP'nin davranışını geçersiz kılmadıkça bu tür yöntem adlarının kullanılması önerilmez.
1+
## Give a Star! :star:
2+
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
3+
<hr>
34

4-
Kurulumlar:
5-
* composer require vlucas/phpdotenv
5+
## SAY Hİ PHP MVC
6+
7+
Modern PHP is used in this work. This means no framework is used. PDO was used for database operations. Migration operations were carried out using filing structure and raw sql queries.
8+
The user's password is stored in the database in hash form. Bootstrap library is used as database, MYSQL design.In addition, a middleware mechanism has been developed for auth control. Users who are not logged in cannot access the homepage.
9+
* SOLID DRY and KISS software development principles are focused. OOP has been applied using abstraction and encapsulation structures.
10+
* The project is generally developed with the MVC design pattern.
11+
12+
The project topic is very simple: Users sign up for the application and see the list of other members on the main page.
13+
14+
![SayHiPhpMvc](https://github.com/NisanurBulut/SayHiCode/blob/master/Trailers/Trailer_SayHiPhpMvc.gif)
384 KB
Loading

SayHiPhpMvc/controllers/AuthController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AuthController extends Controller {
1313

1414
public function __construct()
1515
{
16-
$this->registerMiddleware(new AuthMiddleware(['profile']));
16+
$this->registerMiddleware(new AuthMiddleware(['home']));
1717
}
1818
public function login(Request $request, Response $response)
1919
{
@@ -23,7 +23,7 @@ public function login(Request $request, Response $response)
2323
if($request->isPost()){
2424
$loginForm->loadData($request->getBody());
2525
if($loginForm->validate() && $loginForm->login()){
26-
$response->redirect('/');
26+
$response->redirect('/home');
2727
return;
2828
}
2929
}
@@ -37,8 +37,8 @@ public function register(Request $request)
3737
$registerModel->loadData($request->getBody());
3838

3939
if($registerModel->validate() && $registerModel->save()){
40-
Application::$app->session->setFlash('success','Thanks for registering');
41-
Application::$app->response->redirect('/');
40+
Application::$app->session->setFlash('success','Thanks for registering. Please Login..');
41+
Application::$app->response->redirect('/login');
4242
}
4343
return $this->render('auth/register',[
4444
'model'=>$registerModel
@@ -50,6 +50,6 @@ public function register(Request $request)
5050
}
5151
public function logout(Request $request, Response $response){
5252
Application::$app->logout();
53-
$response->redirect('/');
53+
$response->redirect('/login');
5454
}
5555
}

SayHiPhpMvc/controllers/HomeController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
namespace app\controllers;
44

5+
use app\models\User;
56
use app\core\Request;
67
use app\core\Controller;
78
use app\core\Application;
9+
use app\core\middlewares\AuthMiddleware;
810

911
class HomeController extends Controller {
1012

11-
public function home()
13+
public function __constructor()
1214
{
13-
return $this->render('home');
15+
$this->registerMiddleware(new AuthMiddleware(['home']));
1416
}
15-
public function profile()
17+
public function home()
1618
{
17-
return $this->render('profile');
19+
$userEntity= new User();
20+
$users= $userEntity->select();
21+
return $this->render('home', ['users'=>$users]);
1822
}
1923
}

SayHiPhpMvc/core/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use app\models\User;
66
use app\core\Session;
77
use app\core\Controller;
8+
use app\core\db\Database;
89

910
class Application
1011
{

SayHiPhpMvc/core/UserModel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace app\core;
33

4+
use app\core\db\DbModel;
5+
46
abstract class UserModel extends DbModel{
57
abstract public function getDisplayName():string;
68
}

SayHiPhpMvc/core/db/Database.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace app\core;
3+
namespace app\core\db;
4+
5+
use app\core\Application;
46

57
class Database
68
{

SayHiPhpMvc/core/db/DbModel.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
namespace app\core;
3+
namespace app\core\db;
4+
5+
use PDO;
6+
use app\core\Model;
7+
use app\core\Application;
48

59
abstract class DbModel extends Model
610
{
@@ -22,22 +26,14 @@ public function save()
2226
}
2327
$statement->execute();
2428
return true;
25-
// echo '<pre>';
26-
// var_dump($statement, $params, $attributes);
27-
// '</pre>';
28-
// exit;
2929
}
3030
public function select()
3131
{
3232
$tableName = $this->tableName();
3333
$statement = self::prepare("SELECT * FROM $tableName");
3434
$statement->execute();
35-
$result = $statement->fetchAll();
35+
$result = $statement->fetchAll(PDO::FETCH_CLASS);
3636
return $result;
37-
// echo '<pre>';
38-
// var_dump($statement, $params, $attributes);
39-
// '</pre>';
40-
// exit;
4137
}
4238
public static function find($where, $tableName) { // [email=>nisanurrunasin@gmail.com, firstName=> Nisanur]
4339
$tableName = $tableName;

SayHiPhpMvc/core/form/BaseField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __toString()
1919
return sprintf('<div class="form-group">
2020
<label for="inputFor">%s</label>
2121
%s
22-
<small class="text-danger %s"> %s </small>
22+
<small class="text-danger"> %s </small>
2323
</div>',
2424
$this->model->getLabel($this->attribute),
2525
$this->renderInput(),

SayHiPhpMvc/models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function labels(): array
5050
'lastname'=>'Last Name',
5151
'email'=>'Email Address',
5252
'password'=>'Password',
53-
'confirmPassword'=>'Confirm Password'];
53+
'passwordConfirm'=>'Confirm Password'];
5454
}
5555
public function attributes(): array
5656
{

0 commit comments

Comments
 (0)