douzhuan4406 2015-06-21 09:44
浏览 16

cakephp出错

This is a small code of paypal controller i cakephp

its working fine in my localhost but its give me error in live

if you need more information then write in comment

undefine index username

Notice (8): Undefined index: username [APP/Controller/PaymentsController.php]
public function _initPaypal() {
    $config = $this->User->findByUsername('admin');
    $config = $config['Username'];
    App::import('Vendor', 'Paypal/paypal');
    $this->paypal = new Paypal($config['paypal_api_username'],        $config['paypal_api_password'], $config['paypal_signature']);
}

its give me error like

notice(8) undefine index user name in localhost its working fine

thanks

  • 写回答

1条回答 默认 最新

  • dsdt66064367 2015-06-21 10:28
    关注

    CakePHP's magic findBy methods return in the same format as find('first') so your $config result will be indexed by the model's alias, not the field you've searched with. Therefore, $config['Username'] should be $config['User']. So your controller action should look like:-

    public function _initPaypal() {
        $user = $this->User->findByUsername('admin');
        $config = $user['User'];
        App::import('Vendor', 'Paypal/paypal');
        $this->paypal = new Paypal($config['paypal_api_username'], $config['paypal_api_password'], $config['paypal_signature']);
    }
    

    I've modified your variable names a little to make the difference between the query result ($user) and $config (at first read this confused me).

    I don't see why your example code would have worked anywhere without the correct alias index.

    If this doesn't fix your problem check what $this->User->findByUsername('admin') is returning using either debug() or print_r() and make sure it is generating the expected SQL query (and that that works on your server).

    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装