Backendless PHP Call to a member function on a non-object - php

I have been trying to retrieve data from backendless database using PHP but i get this error.
I followed the documentation but there is no much details written.
I have been trying to retrieve data from backendless database using PHP but i get this error.
I followed the documentation but there is no much details written.
Below is my code
<?php
require_once('Plant.php');
use backendless\Backendless;
include "vendor/backendless/autoload.php";
Backendless::initApp('API-KEY', 'API-KEY', 'v1');
$first_contact = Backendless::$Persistence->of('Plant')->findFirst();
$first_contact->getName();
<?php
class Plant {
private $userId;
private $tempLimit;
private $name;
private $lightLimit;
private $lastWatered;
private $humidityLimit;
private $currentTemp;
private $currentHumidity;
private $currentLight;
public function __construct() {
}
public function getName() {
return $thsi->name;
}
public function setName( $name ) {
$this->name = $name;
}
public function getUserId() {
return $thsi->userId;
}
public function setUserId( $userId ) {
$this->userId = $userId;
}
public function gettempLimit() {
return $thsi->tempLimit;
}
public function setTempLimit( $tempLimit ) {
$this->tempLimit = $tempLimit;
}
public function getLightLimit() {
return $thsi->lightLimit;
}
public function setLightLimit( $lightLimit ) {
$this->lightLimit = $lightLimit;
}
public function getLastWatered() {
return $thsi->lastWatered;
}
public function setLastWatered( $lastWatered ) {
$this->lastWatered = $lastWatered;
}
public function getHumidityLimit() {
return $thsi->humidityLimit;
}
public function setHumidityLimit( $humidityLimit ) {
$this->humidityLimit = $humidityLimit;
}
public function getCurrentTemp() {
return $thsi->currentTemp;
}
public function setCurrentTemp( $currentTemp ) {
$this->currentTemp = $currentTemp;
}
}

Related

Where to include the private key in the ds_config.ini file (PHP)

I'm new to the docusign API.
I already did the quick start: "Quick start: request a signature via your application (integrated signature)".
Now I'm blocked for the PHP construction part: "JSON Web Token (JWT) Grant".
I created the JWT token, and now I don't understand where I should include the rsa private key in the ds_config.ini file
private $config;
private static $instance;
private static function getInstance() {
if(is_null(self::$instance)){
self::$instance = new DSConfig();
}
return self::$instance;
}
public function __construct() {
date_default_timezone_set('UTC');
$clientId = getenv("DS_CLIENT_ID");
if (!is_null($clientId) and !empty($clientId)) {
$this->config["DS_CLIENT_ID"] = $clientId;
$this->config["DS_AUTH_SERVER"] = getenv("DS_AUTH_SERVER");
$this->config["DS_IMPERSONATED_USER_GUID"] = getenv("DS_IMPERSONATED_USER_GUID");
$this->config["DS_TARGET_ACCOUNT_ID"] = getenv("DS_TARGET_ACCOUNT_ID");
$this->config["SIGNER_EMAIL"] = getenv("SIGNER_EMAIL");
$this->config["SIGNER_NAME"] = getenv("SIGNER_NAME");
$this->config["CC_EMAIL"] = getenv("CC_EMAIL");
$this->config["CC_NAME"] = getenv("CC_NAME");
$this->config["DS_PRIVATE_KEY"] = getenv("DS_PRIVATE_KEY");
} else {
$this->config = parse_ini_file('ds_config.ini', true);
}
}
private function _auth_server() {
return $this->config["DS_AUTH_SERVER"];
}
public static function auth_server() {
return self::getInstance()->_auth_server();
}
private function _client_id() {
return $this->config["DS_CLIENT_ID"];
}
public static function client_id() {
return self::getInstance()->_client_id();
}
private function _impersonated_user_guid() {
return $this->config["DS_IMPERSONATED_USER_GUID"];
}
public static function impersonated_user_guid() {
return self::getInstance()->_impersonated_user_guid();
}
private function _target_account_id() {
return $this->config["DS_TARGET_ACCOUNT_ID"];
}
public static function target_account_id(){
return self::getInstance()->_target_account_id();
}
private function _signer_email() {
return $this->config["SIGNER_EMAIL"];
}
public static function signer_email(){
return self::getInstance()->_signer_email();
}
private function _signer_name(){
return $this->config["SIGNER_NAME"];
}
public static function signer_name(){
return self::getInstance()->_signer_name();
}
private function _cc_email() {
return $this->config["CC_EMAIL"];
}
public static function cc_email(){
return self::getInstance()->_cc_email();
}
private function _cc_name(){
return $this->config["CC_NAME"];
}
public static function cc_name(){
return self::getInstance()->_cc_name();
}
private function _private_key() {
return $this->config["DS_PRIVATE_KEY"];
}
public static function private_key(){
return self::getInstance()->_private_key();
}
public static function aud() {
$auth_server = self::getInstance()->_auth_server();
if (strpos($auth_server, 'https://') !== false) {
$aud = substr($auth_server, 8);
} else { # assuming http://blah
$aud = substr($auth_server, 7);
}
return $aud;
}
public static function api() {
return "restapi/v2";
}
public static function jwt_scope() {
return "signature";
}
Thanks for your help
Store the private key in the ds_config.ini file. In the ds_config.ini file, add the private key, including the BEGIN / END lines with a pair of quotation marks. Example:
DS_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAkbz3bi31zrH2ry4p8S4ncPoMdkUyu+MG46m9BalOKzWNNAvW
1LVs5ftlXxzA6V0m6nx895w8S761/qZ8xtAAl99DezRn/3CueeBUyw+tvlmEBu1C
....
UC1WqwKBgQCY/6aZxlWX9XYgsQsnUjhj2aTwr7pCiQuYceIzLTQzy+nz8M4PfCE1
rjRsm6YTpoxh7nuW2qnFfMA58UPs9tonN/z1pr9mKfwmamtPXeMSJeEZUVmh7mNx
PEHgznlGh/vUboCuA4tQOcKytxFfKG4F+jM/g4GH9z46KZOow3Hb6g==
-----END RSA PRIVATE KEY-----"
You can find more details with an example here

Not receiving an output oop php

I am not getting an output for the following piece of code. I cant seem to find the reason for this error.
Heres the code for the config.php
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS','somepwd');
define('DB_NAME','prac');
class Play
{
public $id;
public $username;
public $password;
public $first_name;
public $last_name;
private $connection;
function __construct()
{
$this->open_connection();
}
public function full_name() {
if(isset($this->first_name) && isset($this->last_name)) {
return $this->first_name . " " . $this->last_name;
} else {
return "";
}
}
public function open_connection()
{
$this->connection=mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
}
public static function find_all() {
return self::find_by_sql("SELECT * FROM users");
}
public static function find_by_sql($sql)
{
$result_set=mysql_query($sql,$this->connection);
$object_array=array();
while($row=mysql_fetch_array($result_set))
{
$object_array[]=self::instantiate($row);
}
return $object_array;
}
private static function instantiate($record)
{
$object=new self;
foreach ($record as $k => $value) {
if($object->has_attribte($k))
{
$object->$k=$value;
}
}
return object;
}
private function has_attribte($att)
{
$some=get_object_vars($this);
return array_key_exists($att, $some);
}
}
$play=new Play();
?>
Heres the code for the index.php
<?php
include('config.php');
$user=Play::find_all();
echo $user->username;
?>
So i am basically trying to instantiate an object to a query result but it is not working. I get no output. Please help.

call a method from a class in php

This is kind of embarrassing but I having problems calling a method from a class in PHP, this is how it goes: I have created a class persona with its respectives properties, the code is
<?php
class persona {
private $id;
private $nombre; //varchar(50)
private $correo; //varchar(50)
private $especialidad; //varchar(50)
private $nacionalidad; //varchar(50)
private $sueldo; //float
private $isss; //float
private $afp; //float
//getter
public function getId() {
return $this->id;
}
public function getNombre() {
return $this->nombre;
}
public function getCorreo() {
return $this->descripcion;
}
public function getEspecialidad(){
return $this->especialidad;
}
public function getNacionalidad(){
return $this->nacionalidad;
}
public function getSueldo(){
return $this->sueldo;
}
public function getIsss(){
return $this->isss;
}
public function getAfp(){
return $this->afp;
}
//setter
public function setNombre($nombre) {
$this->nombre = $nombre;
}
public function setCorreo($correo) {
$this->correo = $correo;
}
public function setEspecialidad($especialidad){
$this->especialidad=$especialidad;
}
public function setNacionalidad($nacionalidad){
$this->nacionalidad=$nacionalidad;
}
public function setSueldo($sueldo){
$this->sueldo=$sueldo;
}
public function setIsss($isss){
$this->isss=$isss;
}
public function setAfp($afp){
$this->afp=$afp;
}
public function __construct($nombre, $correo, $especialidad, $nacionalidad, $sueldo, $isss, $afp, $id=null) {
$this->nombre = $nombre;
$this->correo = $descipcion;
$this->especialidad = $especialidad;
$this->nacionalidad = $nacionalidad;
$this->sueldo = $sueldo;
$this ->isss = $isss;
$this->afp = $afp;
$this->id = $id;
}
public function mostrar(){
$mensaje="hola";
return $mensaje;
}
}
?>
as you can see at the end of the code I have created a function called mostrar, the only purpose of this is to show a message, now I want to call this method from a diferent class, my code is
<?php
require_once('persona.php');
class prueba{
private $person;
public function __construct(){
$person= new persona("el nombre","el correo", "la especialidad", "la nacionalidad", "el sueldo", "el isss", "el afp");
mostrando();
}
public function mostrando(){
$person->mostrar();
}
}
?>
but when I debug it doesn' show anything in the browser, I want to display the message from the class person.php, could you please tell me what is the problem in my code?
Variable scope:
$person !== $this->person
class prueba{
private $person;
public function __construct(){
$this->person= new persona("el nombre","el correo", "la especialidad", "la nacionalidad", "el sueldo", "el isss", "el afp");
$this->mostrando();
}
public function mostrando(){
echo $this->person->mostrar();
}
}
$this->person is an object property, accessible from all methods in the class.
$person is a local variable, accessible only from the method/function in which it is defined (unless passed as an argument to other methods/functions)

PHP data collector engine Fatal Error

I am trying to write a small engine in PHP to handle data but i keep on getting this error:
Fatal error: Class 'Factory\dataHandler' not found in /Applications/MAMP/htdocs/Imperial/lp/php/dataPhraserController.php on line 12
Been now trying to find a way of solving the problem but not luck.....
My code:
DataFactory.php
<?php
namespace Factory;
class dataHandler{
protected $firstName;
protected $lastName;
protected $email;
protected $confirmEmail;
protected $phoneNumber;
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
public function setEmail($email)
{
$this->email = $email;
}
public function setConfirmEmail($confirmEmail)
{
$this->confirmEmail = $confirmEmail;
}
public function setPhoneNumber($phoneNumber)
{
$this->phoneNumber = $phoneNumber;
}
public function getFirstName()
{
var_dump($this->firstName);
}
public function getLastName()
{
return $this->lastName;
}
public function getEmail()
{
return $this->confirmEmail;
}
public function getPhoneNumber()
{
return $this->phoneNumber;
}
}
dataPharserController.php:
<?php
namespace PhraserController;
use Factory\dataHandler;
class DataPhraser
{
private $object;
public function __construct()
{
$this->object = new dataHandler;
}
public function pharseFirstName()
{
if(!isset($_POST['first_name']))
{
$this->object->setFirstName($firstName = null);
var_dump($_POST['first_name']);
}else{
$this->object->setFirstName($firstName = $_POST['first_name']);
}
}
}
$test = new DataPhraser();
$test->pharseFirstName();
The idea is to collect data from a submitted html form, can someone help me.. thx
Place this in one of your config files that are loaded before everything
DEFINE('LIB_DIR', '/path_to_library_dir_of_project/');
function AutoloadDefault($ClassName)
{
$File = LIB_DIR.'/' . $ClassName. '.php';
// echo 'Default:'.$File.'<br/>';
if (file_exists($File))
{
require_once($File);
}
}
spl_autoload_register('AutoloadDefault');
Then just point to right LIB_DIR folder. spl_autoload_register will load the class file

parent class method returns null in its daughter __construct()

I tried a code which I called a parent method in its daughter __construct and itreturns NULL,
I dont know why? I would be very happy if anyone could explain to me why.
Thanks in advance.
Here is my code
<?php
class me
{
public $arm;
public $leg;
public function __construct()
{
$this->arm = 'beautiful';
$this->leg = 'pretty';
}
public function setLeg($l)
{
$this->leg = $l;
}
public function getLeg()
{
return $this->leg;
}
}
class myBio extends me
{
public $bio;
public function __construc()
{
$this->bio = $this->setLeg();
}
public function newLeg()
{
var_dump($this->bio);
}
public function tryLeg()
{
$this->leg = $this->getLeg();
print $this->leg;
}
}
$mB = new myBio();
$mB->newLeg();
$mB->tryLeg();
?>
When I call:
$mB = new myBio();
$mB->newLeg();
, it returns
NULL,
BUT
$mB->tryLeg();
returns e string, 'pretty'.
You have a typo on this line:
$this->bio = $this->setLeg();
You're calling your setter, not your getter, and since the setter doesn't return a value you're getting null instead.
You've also misspelled construct:
public function __construc()
And you need to call the parent constructor.
<?php
class me
{
public $arm;
public $leg;
public function __construct()
{
$this->arm = 'beautiful';
$this->leg = 'pretty';
}
public function setLeg($l)
{
$this->leg = $l;
}
public function getLeg()
{
return $this->leg;
}
}
class myBio extends me
{
public $bio;
public function __construct()
{
parent::__construct();
$this->bio = $this->getLeg();
}
public function newLeg()
{
var_dump($this->bio);
}
public function tryLeg()
{
$this->leg = $this->getLeg();
print $this->leg;
}
}
$mB = new myBio();
$mB->newLeg();
$mB->tryLeg();

Categories