sagar parmar
sagar parmar

Reputation: 11

Error in 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

Upvotes: 1

Views: 58

Answers (1)

drmonkeyninja
drmonkeyninja

Reputation: 8540

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).

Upvotes: 2

Related Questions