duan3601 2014-10-26 17:23
浏览 80
已采纳

在控制器中调用多个模型

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)."
";
    return $password;
}
}
  • 写回答

2条回答 默认 最新

  • duangai1368 2014-10-26 17:57
    关注

    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()
        {
    
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮