Closed jackttcoms closed 6 years ago
I have updated the repository with a fix for the "no records" bug when using the Model->select() method. Now it will return FALSE when no records are returned which you can then check for in your Controller.
You can update your local /core/Model select() method as shown below.
if(empty($data)) {
return false; // return FALSE b/c there are no records.
} elseif (count($data) > 1) {
return $data; // return full index of records.
} else {
return $data[0]; // return single record.
}
then in your Controller, you check for false like so
if($data === flase) { // do something here }
Thanks ever so much for your quick support!
Just a quick one, how would this bit of code work?
if($data === false) { echo'no exist'; die(); }
I think it should only be two '==' and also when i tested it i get an error with '===' as i think its not 100% identical so equal seems to work better.
public function profile($user_id)
{
// Get the user by id. (much cleaner)
$data = $this->user->getUserByUserId($user_id);
if($data == false) { echo'user no exist'; die(); }
// Load the View passing to it the Users information as $data.
$this->view('user/profile', $data);
}
And before i close this ticket...
In the core/controller or somewhere like that, is it possible to do a global function so that if you go to https://domain.com/user/profile/ and not https://domain.com/user/profile/admin it automatically takes you back to the homepage?
Right now my only way of doing it is like this so is there a way to do a global bit?
public function profile($user_id = '')
{
if($user_id == ''){
redirect('docs');
}
Thanks again and when i have done my login system, i will send you it so you can use it as a demo/sample for anyone else that wants to use this MVC Framework maybe...
Also one final thing would you agree with me in placing the session_start();
in the init.php file?
Thanks again
Hi,
I have created my login system which works fine until you enter an email which does not exist and then i get the error below... Notice: Undefined offset: 0 in /customers/a/d/5/domain.com/httpd.www/app/core/Model.php on line 124
I also get this error for my profile bit where if the username does not exist i get this error... Notice: Undefined offset: 0 in /customers/a/d/5/domain.com/httpd.www/app/core/Model.php on line 124 user no exist
This is the bit of code that causes the error:
is there any way where i can add another else so it says no records found and dies.
because right now this is my code for the profile but it does nothing to stop the error
Thanks again!