mVC Architecture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dumlee
Forum Commoner
Posts: 33
Joined: Mon Jun 30, 2008 12:06 am

mVC Architecture

Post by dumlee »

In Our company We are using MVC Arch. I am a fresher with PHP.Just know abt Basics.

In the code given to me I have to design Registration page and that will be controlled by

another file init.php (Will Validate Data) and then One template folder is used to Provide Interface



My Problem is That alll other fields are getting updated in database Except username and Password and Iam not able to figure out the problem.


So pls First help me in understanding MVC and then in the coding part.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mVC Architecture

Post by Christopher »

What does "MVC Arch" mean? Are you using a framework or your own code?
(#10850)
dumlee
Forum Commoner
Posts: 33
Joined: Mon Jun 30, 2008 12:06 am

Re: mVC Architecture

Post by dumlee »

We are using a framework.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mVC Architecture

Post by Christopher »

Which one? Also, if you have code to show the problem, please post it.
(#10850)
dumlee
Forum Commoner
Posts: 33
Joined: Mon Jun 30, 2008 12:06 am

Re: mVC Architecture

Post by dumlee »

public function addUser($user) {
$this->logError("UserManager->addUser()");

$query = "INSERT INTO tblUsers SET
fldUsername = '" . add_slashes($user->getUserName()) . "',
fldAccountNumber = '" . add_slashes($user->getAccountNumber()) . "',
fldPassword = '" . add_slashes($user->getPassword()) . "',
fldUserType = '" . add_slashes($user->getUserType()) . "',
fldUserStatus = '" . add_slashes($user->getUserStatus()) . "',
fldNPI = '" . add_slashes($user->getNPI())."'";

require_once(DA_PATH . '/SystemDatabaseManager.inc.php');
$systemDatabaseManager = SystemDatabaseManager::getInstance();
$result = $systemDatabaseManager->executeUpdate($query, 'Save a new Grand Parent User');

if ($result) {
$this->isError = false;
$this->logError("Query: \"" . $query . "\" runs successfully");
$this->logError("Given GP User saved successfully.");
return $systemDatabaseManager->lastInsertId();
}
else {
$this->isError = true;
$this->logError("Query: \"" . $query . "\" failed");
$this->setErrorMessage("GP User cannot be saved. Please try again.");
return false;
}
}

/**
*
* Update the User table
*
* @param $user: Object of User having all the information to be saved
* @param $status: Updated status
*
*/

public function updateUserTable($user) {
$this->logError("UserManager->updateUserTable()");

$query = "UPDATE tblUsers SET
fldUsername = '" . $user->getUserName() . "',
fldPassword = '" . UtilityManager::generatePassword($user->getPassword()) . "'
WHERE fldUserId = '" . $user->getUserId() . "'";

require_once(DA_PATH . '/SystemDatabaseManager.inc.php');
$systemDatabaseManager = SystemDatabaseManager::getInstance();
$result = $systemDatabaseManager->executeUpdate($query, 'Modify the User status');

if ($result) {
$this->logError("Query: \"" . $query . "\" runs successfully");
$this->logError("Given User ids' status has been modified successfully.");
return true;
}
else {
$this->isError = true;
$this->logError("Query: \"" . $query . "\" failed");
$this->setErrorMessage("User ids' status cannot be modified. Please try again.");
return false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////


class User {
private $userid;
private $username;
private $accoutNumber;
private $password;
private $usertype;
private $leadUserId;
private $userLevel;
private $status;
private $NPI;
private $lastLogin;
private $blocked;
private $title;
private $MDspecialty;

//more added
private $firstName;
private $lastName;
private $email;
private $createdon;

public function __construct() {
$this->userid = "";
$this->username = "";
$this->accoutNumber = "";
$this->password = "";
$this->status = "";
$this->NPI = "";
$this->lastLogin = "";
$this->blocked = "";
$this->title="";
$this->MDspecialty="";
$this->email;
$this->createdon;
}

public function setUserId($userid) {
$this->userid = $userid;
}

public function getUserId() {
return $this->userid;
}


public function setUserName($username) {
$this->username = $username;
}

public function getUserName() {
return $this->username;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

public function getUserDetails(&$user) {

$this->logError("UserManager->getUserDetails()");

$query = "SELECT
*,
DATE_FORMAT(fldLastLogin,'".DATETIME_FORMAT_DB."') fldLastLogin
FROM
tblUsers
WHERE
fldUserId = '" . $user->getUserId() . "'";

require_once(DA_PATH . '/SystemDatabaseManager.inc.php');
$result = SystemDatabaseManager::runSingleQuery($query, 'Fetch the GP User details');

if (count($result) > 0) {
$this->logError("Query: \"" . $query . "\" runs successfully");
$this->logError("GP User id found.");

require_once(BL_PATH . '/User.inc.php');
$user = new User();

$user->setUserId($result[0]['fldUserId']);
$user->setUserName(strip_slashes($result[0]['fldUsername']));
$user->setPassword($result[0]['fldPassword']);
$user->setUserStatus($result[0]['fldUserStatus']);
$user->setUserBlocked($result[0]['fldBlocked']);

$user->setLeadUserId($result[0]['fldLeadUserId']);
$user->setUserLevel($result[0]['fldUserLevel']);
$user->setUserType($result[0]['fldUserType']);
$user->setNPI($result[0]['fldNPI']);
$user->setAccountNumber($result[0]['fldAccountNumber']);

$user->setLastLogin(strip_slashes($result[0]['fldLastLogin']));
return $user;
}
else {
$this->logError("Given GP User id does not exists in database");
$this->setErrorMessage("Given GP User id does not exists in database.");
$this->isError = true;
return;
}
}



I hope this code part will help u in figuring out the problem.I have separated the code as it is from different files.
Post Reply