0

Hello I am having trouble running more than one model in my controller.

The first model is encryption then the second model is insertion.

public function addStore()
{
    $name = $_POST['name'];
    $address = $_POST['address'];
    $gpsAddress = $_POST['gps_address'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $status = 1;

    $this->load->model('EncryptionModel');
    $password = $this->EncryptionModel->encryptPassword($password);

    $this->load->model('StoresModel');
    $this->StoresModel->addStore($name, $address, $gpsAddress, $phone, $email, $password, $status);
}

The following is the error

Fatal error: Call to a member function addStore() on a non-object in \application\controllers\stores.php

This does not occur when the encryption model call is taken out.

Encryption Model as requested

class EncryptionModel extends CI_Controller {

public function encryptPassword($password)
{
    $options = ['cost' => 12];
    $password = password_hash($password, PASSWORD_BCRYPT, $options)."\n";
    return $password;
}
}
4
  • Something is wrong with your EncryptionModel. Post the code for EncryptionModel Commented Oct 26, 2014 at 17:41
  • Added for you to see Commented Oct 26, 2014 at 17:44
  • 2
    Why is your model extending CI_Controller? Commented Oct 26, 2014 at 17:55
  • Thanks Tim all is good now much appreciated Commented Oct 26, 2014 at 18:05

2 Answers 2

3

Should be...

class EncryptionModel extends CI_Model {

Note CI_Model in place of where you had CI_Controller.


Also see the CodeIgniter class naming recommendations regarding upper and lower case best practices...

"Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names."

 

INCORRECT:
class superclass
class SuperClass

CORRECT:
class Super_class

class Super_class {
    function __construct()
    {

    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Encryption Model was extending CI_Controller where it should be extending CI_Model

Thanks everyone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.