Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,454 members, 7,843,387 topics. Date: Wednesday, 29 May 2024 at 01:21 AM

PHP MVC Model Is Complete Garbage - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / PHP MVC Model Is Complete Garbage (1079 Views)

Which Php Mvc Framework Is Most Similar To Django? / How To Implement Chart In ASP.NET MVC Project Using Amchart / ASP.NET MVC [C#] Php Laravel - Training From Scratch-apply now (2) (3) (4)

(1) (Reply) (Go Down)

PHP MVC Model Is Complete Garbage by dometome: 9:54pm On Apr 22, 2020
You will never go through a PHp tutorial without the presenter parroting the MVC system. But when you actually try it, it completely falls flat on it's face. It is impossible to move the variables, from one file to the other, how can session work in one file and when you pass that it to another file, be it via include, require or require once, the session simply throws away the variables and returns empty handed? The stupid array returns empty. And there is simply NO solution. But when I do everything in one page, the whole thing works flawlessly. It is all complete garabage. I wonder what type of hickory pockery those YouTubers do to make it work on their computers, I have tried everything, spent the whole day on stackoverflow. Edited the PHP. ini file, Nothing. I am sick and tired of that rubbish.
Re: PHP MVC Model Is Complete Garbage by stanliwise(m): 10:24pm On Apr 22, 2020
dometome:
You will never go through a PHp tutorial without the presenter parroting the MVC system. But when you actually try it, it completely falls flat on it's face. It is impossible to move the variables, from one file to the other, how can session work in one file and when you pass that it to another file, be it via include, require or require once, the session simply throws away the variables and returns empty handed? The stupid array returns empty. And there is simply NO solution. But when I do everything in one page, the whole thing works flawlessly. It is all complete garabage. I wonder what type of hickory pockery those YouTubers do to make it work on their computers, I have tried everything, spent the whole day on stackoverflow. Edited the PHP. ini file, Nothing. I am sick and tired of that rubbish.
Dont hate what you don’t understand.

You were saying you’re trying to pass session from one page to another.

Wait let me ask you did you start every page with

session_start()

?

3 Likes

Re: PHP MVC Model Is Complete Garbage by Nobody: 11:29pm On Apr 22, 2020
.
Re: PHP MVC Model Is Complete Garbage by Ayemileto(m): 12:51am On Apr 23, 2020
dometome:
You will never go through a PHp tutorial without the presenter parroting the MVC system. But when you actually try it, it completely falls flat on it's face. It is impossible to move the variables, from one file to the other, how can session work in one file and when you pass that it to another file, be it via include, require or require once, the session simply throws away the variables and returns empty handed? The stupid array returns empty. And there is simply NO solution. But when I do everything in one page, the whole thing works flawlessly. It is all complete garabage. I wonder what type of hickory pockery those YouTubers do to make it work on their computers, I have tried everything, spent the whole day on stackoverflow. Edited the PHP. ini file, Nothing. I am sick and tired of that rubbish.


Just say you don't know it, and let people help you. grin

5 Likes

Re: PHP MVC Model Is Complete Garbage by dometome: 10:56am On Apr 23, 2020
stanliwise:
Dont hate what you don’t understand.

You were saying you’re trying to pass session from one page to another.

Wait let me ask you did you start every page with

session_start()

?
yes I did

here is the code

<?php
session_start();

require_once 'config/db.php'; //this the config file

$errors = array();
$username = '';
$email = '';
$password = '';

//this code runs when user clicks sign up button
if(isset($_POST['signup-btn'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConf = $_POST['passwordConf'];


//validation code
if(empty($username)){
$errors['username'] = "Username Required";
}

if(empty($email)){
$errors['email'] = "Email Required";
}

if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errors['email'] = 'Email address is invalid';
}

if(empty($password)){
$errors['password'] = "Password Required";
}

if($password !== $passwordConf){
$errors['password'] = 'The passwords do not match';
}
//this code checks if the email has already been taken
$emailQuery = "SELECT * FROM users WHERE email=? LIMIT 1";
$stmt = $conn->prepare($emailQuery);
$stmt -> bind_param('s',$email);
$stmt ->execute();
$result = $stmt->get_result();
$userCount = $result->num_rows;
$stmt-> close();

if ($userCount > 0){
$errors ['email'] = "Email already exists";
}

//tip: Try to implement this for username
//We do not want two usernmes, do we?

//this code runs checks that there are no errors
if(count($errors)===0){
//encrypt the password to avoid damn hackers
$password = password_hash($password,PASSWORD_DEFAULT);
//generate a token for security
$token = bin2hex(random_bytes(50));
//verified is false until user clicks verify in the email
$verified = false;


//now query the database
$sql = "INSERT INTO users(username,email,verified,token,password)VALUES(?,?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmt -> bind_param('ssbss',$username,$email,$verified,$token,$password);

if($stmt->execute()){
//login user
$user_id =$conn->insert_id;
$_SESSION["id"] = $user_id;
$_SESSION["username"] = $username;
$_SESSION['email'] = $email;
$_SESSION['verified'] = $verified;
//set flash message
$_SESSION["alert-class"] = 'alert-success';
$_SESSION["message"] = 'You are now logged in!';

header('location: index.php');
session_write_close();
}else{
$errors['db_error']="Database error: Failed to register";
}

}
}




this is the code of the inex.php




<?php
session_start();
require 'config/db.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Home</title>
<link rel="stylesheet" href="style/bootstrap.css">
<style>

body{
font-family:helvetica,sans-serif;
}
.alert li{
font-weight: 800;
list-style: none;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-md-4 offset-md-4 blah">

<div class="alert <?php echo $_SESSION['alert-class'];?>">
<?php echo $_SESSION['message']; ?>
</div>
<h3>You are Welcome, user</h3>

<a href="#" class="logout mt-4">Logout</a>

<div class="alert alert-warning mt-2">
You need to verify your account.
Go to your email account and click on the verification link
we just emailed you.
<strong>user@email.com</strong>
</div>
<button class="btn btn-block btn-lg btn-primary">I am verified</button>
</div>
</div>
</div>
</body>
</html>


Note: when I print_r session, it returns an empty array
Re: PHP MVC Model Is Complete Garbage by stanliwise(m): 12:13pm On Apr 23, 2020
dometome:
yes I did

here is the code

<?php
session_start();

require_once 'config/db.php'; //this the config file

$errors = array();
$username = '';
$email = '';
$password = '';

//this code runs when user clicks sign up button
if(isset($_POST['signup-btn'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConf = $_POST['passwordConf'];


//validation code
if(empty($username)){
$errors['username'] = "Username Required";
}

if(empty($email)){
$errors['email'] = "Email Required";
}

if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errors['email'] = 'Email address is invalid';
}

if(empty($password)){
$errors['password'] = "Password Required";
}

if($password !== $passwordConf){
$errors['password'] = 'The passwords do not match';
}
//this code checks if the email has already been taken
$emailQuery = "SELECT * FROM users WHERE email=? LIMIT 1";
$stmt = $conn->prepare($emailQuery);
$stmt -> bind_param('s',$email);
$stmt ->execute();
$result = $stmt->get_result();
$userCount = $result->num_rows;
$stmt-> close();

if ($userCount > 0){
$errors ['email'] = "Email already exists";
}

//tip: Try to implement this for username
//We do not want two usernmes, do we?

//this code runs checks that there are no errors
if(count($errors)===0){
//encrypt the password to avoid damn hackers
$password = password_hash($password,PASSWORD_DEFAULT);
//generate a token for security
$token = bin2hex(random_bytes(50));
//verified is false until user clicks verify in the email
$verified = false;


//now query the database
$sql = "INSERT INTO users(username,email,verified,token,password)VALUES(?,?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmt -> bind_param('ssbss',$username,$email,$verified,$token,$password);

if($stmt->execute()){
//login user
$user_id =$conn->insert_id;
$_SESSION["id"] = $user_id;
$_SESSION["username"] = $username;
$_SESSION['email'] = $email;
$_SESSION['verified'] = $verified;
//set flash message
$_SESSION["alert-class"] = 'alert-success';
$_SESSION["message"] = 'You are now logged in!';

header('location: index.php');
session_write_close();
}else{
$errors['db_error']="Database error: Failed to register";
}

}
}




this is the code of the inex.php




<?php
session_start();
require 'config/db.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Home</title>
<link rel="stylesheet" href="style/bootstrap.css">
<style>

body{
font-family:helvetica,sans-serif;
}
.alert li{
font-weight: 800;
list-style: none;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-md-4 offset-md-4 blah">

<div class="alert <?php echo $_SESSION['alert-class'];?>">
<?php echo $_SESSION['message']; ?>
</div>
<h3>You are Welcome, user</h3>

<a href="#" class="logout mt-4">Logout</a>

<div class="alert alert-warning mt-2">
You need to verify your account.
Go to your email account and click on the verification link
we just emailed you.
<strong>user@email.com</strong>
</div>
<button class="btn btn-block btn-lg btn-primary">I am verified</button>
</div>
</div>
</div>
</body>
</html>


Note: when I print_r session, it returns an empty array

If you’re experiencing this then I suggest you insert static data into the $_SESSION variable e.g
$_SESSION[‘username’] = ‘Stanliwise’;

after this then try print it in the other page, if it works then it means your bind_param() didn’t bind anything to those variables or your form submitted empty $_POST variables.

Also I wonder how you called bind_param() method on already existing variables, do you understand how $stmt works?
Re: PHP MVC Model Is Complete Garbage by ToyinDipo(m): 12:41pm On Apr 23, 2020
It's a crap language anyway, just saying embarassed
Re: PHP MVC Model Is Complete Garbage by ubsky(m): 6:45pm On Apr 23, 2020
You have just created an avenue for those that aren't interested in the language to bash it, brother if you don't understand it ask questions not bashing,If I was acting the same way u re currently acting I would have left dotnet since...... Learn to search properly with the right keywords on Google relating to ur issues on the errors,u might likely get a good solution from stack overflow or better still seek help from people u know.....
Re: PHP MVC Model Is Complete Garbage by silento(m): 11:56pm On Apr 23, 2020
I have been coding with php for 5years now but learning mvc concept just few days have made me believe how stupid I was for not giving mvc concept a trial since

Mvc is the best thing that can happen to any php developer who want to make money and enjoy building website

Mvc is the future

At first everything will be like magic but once u understand the concept bro u will enjoy it die


Neat syntax , reusable function , easy call to database , in fact mvc made it more easy to expose ur variables from models to views

Easy reusable template and fast coming up with website design

Mvc is the way and future

If u can't do mvc just know that web programming is not for u in coming years

Mvc that made php easy as python u are here bashing , na people like u that pointer in c language will frustrate and u will call the language rubbish forgetting that it is the mother of all most higher languages

Beat your self and learn mvc concept you will thank yourself in near future when u complete full functional website in a day
Re: PHP MVC Model Is Complete Garbage by silento(m): 11:59pm On Apr 23, 2020
lovely cakephp
Re: PHP MVC Model Is Complete Garbage by Nobody: 12:04am On Apr 24, 2020
silento:


My sweet lovely cakephp easy on him
Lol you can now edit your quote. I've edited mine.
Re: PHP MVC Model Is Complete Garbage by afonja112: 5:05am On Apr 24, 2020
We dont write codes like this again this days, when you are talking of MVC, please go to cakephp, laravel and you wont even have to write something like session_start() ever again.
This whole code is procedural pattern, this is 2020, we write in OOP these days.

Just take a glance at this - https://laravel.com/docs/7.x/session - to give you an idea of what a little bit of OOP looks like, and what a self-respecting MVC system should be able to do.
Re: PHP MVC Model Is Complete Garbage by Karleb(m): 8:20am On Apr 24, 2020
afonja112:
We dont write codes like this again this days, when you are talking of MVC, please go to cakephp, laravel and you wont even have to write something like session_start() ever again.
This whole code is procedural pattern, this is 2020, we write in OOP these days.

Just take a glance at this - https://laravel.com/docs/7.x/session - to give you an idea of what a little bit of OOP looks like, and what a self-respecting MVC system should be able to do.

Everything shouldn't be framework framework framework! angry

Abeg! PHP is still PHP! Framework or not.

2 Likes

Re: PHP MVC Model Is Complete Garbage by chim14(m): 4:38pm On Apr 24, 2020
Oga, go and learn Laravel jor. 2020 you are still stuck in vanilla php. It's because you don't know how to code in MVC, this was how I was then, b4 I forced myself to learn Codeigniter cuz all the job adverts was Framework, framework. When I got a job, guess what, it was Codeigniter they were using.

Fast forward, Laravel was trending, Codeigniter was becoming obsolete. I learnt Laravel by myself on the job, guess what? The company employed a senior developer to head the development area, and what he uses is Laravel so we were able to speak the same language.

Stop complaining & upgrade

3 Likes

Re: PHP MVC Model Is Complete Garbage by WebMind: 4:57pm On Apr 24, 2020
So which is good?
Maybe OP is still learning it and needs better grasp.
Re: PHP MVC Model Is Complete Garbage by ugwum007(m): 5:25pm On Apr 24, 2020
dometome:
yes I did

here is the code

<?php
session_start();

require_once 'config/db.php'; //this the config file

$errors = array();
$username = '';
$email = '';
$password = '';

//this code runs when user clicks sign up button
if(isset($_POST['signup-btn'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConf = $_POST['passwordConf'];


//validation code
if(empty($username)){
$errors['username'] = "Username Required";
}

if(empty($email)){
$errors['email'] = "Email Required";
}

if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errors['email'] = 'Email address is invalid';
}

if(empty($password)){
$errors['password'] = "Password Required";
}

if($password !== $passwordConf){
$errors['password'] = 'The passwords do not match';
}
//this code checks if the email has already been taken
$emailQuery = "SELECT * FROM users WHERE email=? LIMIT 1";
$stmt = $conn->prepare($emailQuery);
$stmt -> bind_param('s',$email);
$stmt ->execute();
$result = $stmt->get_result();
$userCount = $result->num_rows;
$stmt-> close();

if ($userCount > 0){
$errors ['email'] = "Email already exists";
}

//tip: Try to implement this for username
//We do not want two usernmes, do we?

//this code runs checks that there are no errors
if(count($errors)===0){
//encrypt the password to avoid damn hackers
$password = password_hash($password,PASSWORD_DEFAULT);
//generate a token for security
$token = bin2hex(random_bytes(50));
//verified is false until user clicks verify in the email
$verified = false;


//now query the database
$sql = "INSERT INTO users(username,email,verified,token,password)VALUES(?,?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmt -> bind_param('ssbss',$username,$email,$verified,$token,$password);

if($stmt->execute()){
//login user
$user_id =$conn->insert_id;
$_SESSION["id"] = $user_id;
$_SESSION["username"] = $username;
$_SESSION['email'] = $email;
$_SESSION['verified'] = $verified;
//set flash message
$_SESSION["alert-class"] = 'alert-success';
$_SESSION["message"] = 'You are now logged in!';

header('location: index.php');
session_write_close();
}else{
$errors['db_error']="Database error: Failed to register";
}

}
}




this is the code of the inex.php




<?php
session_start();
require 'config/db.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Home</title>
<link rel="stylesheet" href="style/bootstrap.css">
<style>

body{
font-family:helvetica,sans-serif;
}
.alert li{
font-weight: 800;
list-style: none;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-md-4 offset-md-4 blah">

<div class="alert <?php echo $_SESSION['alert-class'];?>">
<?php echo $_SESSION['message']; ?>
</div>
<h3>You are Welcome, user</h3>

<a href="#" class="logout mt-4">Logout</a>

<div class="alert alert-warning mt-2">
You need to verify your account.
Go to your email account and click on the verification link
we just emailed you.
<strong>user@email.com</strong>
</div>
<button class="btn btn-block btn-lg btn-primary">I am verified</button>
</div>
</div>
</div>
</body>
</html>


Note: when I print_r session, it returns an empty array

Can't you put this in a gist?. The cord attaching my eyes to my brain is now paining after attempting to read this.

2 Likes

Re: PHP MVC Model Is Complete Garbage by CodeTemplar: 6:25pm On Apr 25, 2020
Most times people gather to criticize something, it is because they never really examine the purpose of that thing.
Python for example was created to be fast in computation and to achieve that they traded of security.
Java was created to be a verbose and robust programming language with good web support, mobile support, embedded support and even security.
I am sure this framework was created to solve an existing challenge or set of challenges. Just find out those things and know when best to engage the framework. Those other frameworks like laravel and codeigniter are very good too but have weaknesses also.

(1) (Reply)

Microsoft Technologies And The Path To Glory / [Help Request] Help In Robotics / Please Share Your Experiences With Redis (using Python Preferably)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 62
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.