duan33360 2013-11-05 10:27
浏览 39
已采纳

使用CakePHP的Auth组件登录时出错

I've integrated Cake's Auth component into my app. It mostly seems to work ok but I quite often get an error when logging in looking something like this:

Error: Call to undefined method Security::getDataSource()
File: C:\xampp\htdocs\ips-mvc\lib\Cake\Model\Datasource\DboSource.php
Line: 1063

Any idea what this means?

For the record, I do have a model in my app called Security. I wasn't aware of any reserved model names in Cake but is there a chance my Security mdoel is conflicting with a Cake component? This error can still occur when the Security model is not used although it is quite sporadic in its appearance - sometimes refreshing the page will make everything work fine.

Any ideas?

  • 写回答

1条回答 默认 最新

  • douyi1944 2013-11-05 11:50
    关注

    The error is caused by passing a component instance to a method expecting a model instance, and are easily avoidable by not creating model classes with the same name as a component in use.

    Models and Components cannot have the same name

    The problem is not related to duplicate class names as Models do not have a class name suffix, yet components do.

    However, for example, in a controller the following syntax:

    $this->{$alias}
    

    Is used to access both a component (class name {$alias}Component) or a model (class name $alias).

    As such, having a model with the same name as a component makes one or the other inaccessible.

    Cache Poisoning

    However the problem doesn't stop there. Objects are stored in the class registry using an alias as the key:

    For example, in Model:

     ClassRegistry::addObject($this->alias, $this);
    

    If the same alias is used (Security model, SecurityComponent) - the object occupying the key "Security" is simply the first one to get added to the registry - all subsequent requests for "Security" will return that object.

    Depending on cache expiration and whether the model and component are used in the same request - determines how often errors such as the one in the question appear and whether they are "random" or reproducible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大