codeigniter custom library undefine property error - php

I created a codeigniter custom library(My_payment_gate_way_init) for my payment gateway.. but when i use my custom library function , controller(Billing) not passing parameters into the library it shows
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Billing::$My_payment_gate_way_init
Filename: controllers/Billing.php
Line Number: 576
that error occurs when i use
Controller
public function __construct()
{
parent::__construct();
$this->load->library('My_payment_gate_way_init');
}
function saveord(){
$ammount = $this->totlCost * 100;
$this->My_payment_gate_way_init->setTransactionAmountforPay($ammount);
}
library
class My_payment_gate_way_init
{
private $clientConfig;
private $initRequest;
private $transactionAmount;
private $redirect;
private $initResponse;
private $client;
private $CI;
function __construct()
{
$this->setTransactionAmountforPay();
}
function setTransactionAmountforPay($ammount=200){
// sets transaction-amounts details (all amounts are in cents)
$this->transactionAmount = new TransactionAmount();
$this->transactionAmount->setTotalAmount(0);
$this->transactionAmount->setServiceFeeAmount(0);
$this->transactionAmount->setPaymentAmount($ammount);
$this->transactionAmount->setCurrency("LKR");
$this->initRequest->setTransactionAmount($this->transactionAmount);
}
also it shows this error at bottom
Fatal error: Call to a member function setTransactionAmountforPay() on
null in
C:\xampp\htdocs\debug_online\application\controllers\Billing.php on
line 576

Make an object first before calling the function.
$this->My_payment_gate_way_init = new My_payment_gate_way_init();
$this->My_payment_gate_way_init->setTransactionAmountforPay($ammount);

Related

Using reflection class in PHP also unable to access private property

How to access private property values outside the class? I also tried using reflection in PHP.
<?php
namespace TDD;
class Receipt {
public $user_id = 1;
private $pending_amount = 45;
public function total(array $items = []){
$items[] = $this->pending_amount;
return array_sum($items);
}
public function tax($amount,$tax){
return $amount * $tax;
}
public function pending()
{
return $this->pending_amount = 45;
}
public function addTaxPending($tax){
return $this->pending_amount * $tax;
}
}
$class = new \ReflectionClass('TDD\Receipt');
$myProtectedProperty = $class->getProperty('pending_amount');
$myProtectedProperty->setAccessible(true);
$myInstance = new Receipt();
$myProtectedProperty->setValue($myInstance, 99);
echo $myInstance->pending_amount;
?>
Error:
`
$ php src/Receipt.php
PHP Fatal error: Uncaught Error: Cannot access private property TDD\Receipt::$pending_amount in C:\xampp\htdocs\all_scripts\PHPUnit_By_siddhu\src\Receipt.php:48
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\all_scripts\PHPUnit_By_siddhu\src\Receipt.php on line 48
Fatal error: Uncaught Error: Cannot access private property TDD\Receipt::$pending_amount in C:\xampp\htdocs\all_scripts\PHPUnit_By_siddhu\src\Receipt.php:48
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\all_scripts\PHPUnit_By_siddhu\src\Receipt.php on line 48
`
error screenshot
How can I solve it? Looking for your valuable solutions.
From the PHP manual for ReflectionProperty::setAccessible:
Enables access to a protected or private property via the ReflectionProperty::getValue() and ReflectionProperty::setValue() methods.
Calling setAccessible has no effect on access to the property via normal PHP syntax, only via that ReflectionProperty object.
So this line is still accessing a private property:
echo $myInstance->pending_amount;
You need to instead access it via your reflection object:
echo $myProtectedProperty->getValue($myInstance);

Bonfire - Authenticated_controller - Fatal error: Call to a member function is_ajax_request() on a non-object

I am trying to setup an area that is accessible only for the registered users, using Bonfire/CodeIgniter. Per Bonfire documentation, we can use the Authenticated_controller. When I try to extend my controller from Authenticated_controller, I get the error message:
Fatal error: Call to a member function is_ajax_request() on a non-object in D:\xampp\htdocs\bonfire\bonfire\libraries\template.php on line 264
The code that I have is for the controller boffice:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* boffice controller
*/
class Boffice extends Authenticated_Controller
{
public $ci;
//--------------------------------------------------------------------
/**
* Constructor
*
* #return void
*/
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
$this->load->library('form_validation');
$this->lang->load('boffice');
$this->load->model('pan/pan_model', null, true);
$this->load->model('activities/activity_model');
Assets::add_module_js('boffice', 'boffice.js');
Template::set_theme("jumbotron");
}
//--------------------------------------------------------------------
/**
* Displays a list of form data.
*
* #return void
*/
public function index()
{
Template::render();
}
//--------------------------------------------------------------------
}
Other Warnings that I get are listed below:
ERROR - 2014-08-15 13:10:19 --> Severity: Notice --> Trying to get property of non-object D:\xampp\htdocs\bonfire\bonfire\libraries\template.php 258
ERROR - 2014-08-15 13:10:19 --> Severity: Notice --> Trying to get property of non-object D:\xampp\htdocs\bonfire\bonfire\libraries\template.php 258
ERROR - 2014-08-15 13:10:19 --> Severity: Notice --> Trying to get property of non-object D:\xampp\htdocs\bonfire\bonfire\libraries\template.php 264
The code in template.php where the error occurs:
255 public static function render($layout=NULL)
256 {
257 $output = '';
258 $controller = self::$ci->router->class;
259
260 // We need to know which layout to render
261 $layout = empty($layout) ? self::$layout : $layout;
262
263 // Is it in an AJAX call? If so, override the layout
264 if (self::$ci->input->is_ajax_request())
265 {
267 $layout = self::$ci->config->item('template.ajax_layout');
268
269 $controller = NULL;
270 }
I have seen similar error messages and the problem has been not having an object initialized. This one "is_ajax_request()" type error is nowhere to be found and I am not sure how to fix this.
Any help is appreciated.

Magento Fatal Error

Its my first try with Magento.
I get this Error Message:
Fatal error: Call to a member function append() on a non-object in /var/customers/webs/magento/magento/app/code/core/Mage/Install/controllers/WizardController.php on line 77
Maybe someone have an Idee or can help me with my Problem?
Now the whole Code from Line 68 - 79:
protected function _prepareLayout()
{
$this->loadLayout('install_wizard');
$step = $this->_getWizard()->getStepByRequest($this->getRequest());
if ($step) {
$step->setActive(true);
}
$leftBlock = $this->getLayout()->createBlock('install/state', 'install.state');
$this->getLayout()->getBlock('left')->append($leftBlock);
return $this;
}
Its the orginal code i havenĀ“t edit anything
$this->getLayout()->getBlock('left')
should return a block class or NULL.
If it returned a block class then :
abstract class Mage_Core_Block_Abstract extends Varien_Object
has function
append($leftBlock);
This means that your $this->getLayout()->getBlock('left')
is not return a block instance.
Why not do a mage log of what $this->getLayout()->getBlock('left')
returns and confirm.

Message: Undefined property: classname::$navbardata, codeigniter

I have the following in my codeigniter constructor:
$navbar= new stdClass();
$navbar->user_email = $this->user_email;
$navbar->vp = $this->vp;
When I try to access this in my index function:
public function index() {
var_dump($this->navbar);
I get :
Message: Undefined property: classname::$navbar
How can I fix this?
Thanks in advance,
Bill
$navbardata needs to be made available to the Buyers object to be available to a method via $this
Ways that this can be accomplished.
Injection through the constructor
class Buyers {
protected $navbardata;
public function __construct($nbd){
$this->navbardata = $nbd;
}
}
Setter Injection
class Buyers{
protected $navbardata;
....
public function setNavBarData($nbd){
$this->navbardata = $nbd;
}
Or via a public property
class Buyers {
public $navbardata;
....
}
$b = new Buyers();
$b->navbardata = $navbardata

Codeigniter model Undefined property

i have following code in the controller file which check for post varible pdf and execute following code
if(isset($_POST['pdf']) && $_POST['pdf']=="pdf")
{
$this->load->model('voutput_model');
$final_view = $data['frmReport'];
$PDF_Name = "report.pdf";
$this->votput_model->pdf($PDF_Name,$final_view);
}
I have following code in model file
class Voutput_model extends CI_Model{
public function __construct()
{
parent::__construct();
$this->CI = get_instance();
}
public function pdf($file_name,$filecontents){
$this->pdf_path = $this->config->item('pdf_path');
$this->load->library('htmltopdf/Html2fpdf');
$file['Attach_path'] = $this->pdf_path.$file_name;
$this->html2fpdf->generate_pdf($file['Attach_path'],$filecontents,'Y');
}
}
while i am executing the code i am getting error as below:
Severity: Notice
Message: Undefined property: Voutput::$Voutput_model
Filename: controllers/voutput.php
Fatal error: Call to a member function pdf() on a non-object in
C:\xampp\htdocs\asset\application\controllers\voutput.php
You need to load model before use . Try this
$this->load->model('votput_model');
$this->votput_model->pdf($PDF_Name,$final_view);

Categories