I am trying to access the $this->agent object in CodeIgniter 2, but all values (variables) are NULLed since the model where I'm accessing $this->agent is passed through the CURL request.
I have a test controller OUTBOUND from which the CURL request is made to another controller named INBOUND for example.
Once the schema is validated and all checkings are passed with success, the INBOUND calls the following function inbound():
public function inbound()
{
// Load dependencies
$this->load->library('user_agent');
var_dump($this->agent);
die;
}
and it returns me the following dump:
object(CI_User_agent)[28]
public 'agent' => null
public 'is_browser' => boolean false
public 'is_robot' => boolean false
public 'is_mobile' => boolean false
public 'languages' =>
array (size=0)
empty
public 'charsets' =>
array (size=0)
empty
public 'platforms' =>
array (size=0)
empty
public 'browsers' =>
array (size=0)
empty
public 'mobiles' =>
array (size=0)
empty
public 'robots' =>
array (size=0)
empty
public 'platform' => string '' (length=0)
public 'browser' => string '' (length=0)
public 'version' => string '' (length=0)
public 'mobile' => string '' (length=0)
public 'robot' => string '' (length=0)
Is there any proper way to not loose these information after the CURL request is made, I'm mean in INBOUND controller?
**** UPDATED ****
Is it possible to solve this problem without need to tell the 3rd party to include these informations into their CURL request ?
Related
its my first Google MyBusiness API encounter.
Im trying to retrieve account locations but ive got nothing.
I dont have direct access for account, my client gave me access to API by json file.
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/plus.business.manage');
$service = new Google_Service_MyBusiness($client);
$accounts = $service->accounts->listAccounts();
and i don't have any error, just Google_Service_MyBusiness_ListAccountsResponse object, then giving foreach on that object and I can get account informations:
object(Google_Service_MyBusiness_Account)[94]
protected 'internal_gapi_mappings' =>
array (size=0)
empty
public 'accountName' => null
public 'accountNumber' => null
public 'name' => string 'accounts/XXXXXXXXXXXXXXXXXXXXX' (length=30)
protected 'organizationInfoType' => string 'Google_Service_MyBusiness_OrganizationInfo' (length=42)
protected 'organizationInfoDataType' => string '' (length=0)
public 'permissionLevel' => null
public 'profilePhotoUrl' => string '.../photo.jpg' (length=94)
public 'role' => null
protected 'stateType' => string 'Google_Service_MyBusiness_AccountState' (length=38)
protected 'stateDataType' => string '' (length=0)
public 'type' => string 'PERSONAL' (length=8)
protected 'modelData' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
public 'state' =>
object(Google_Service_MyBusiness_AccountState)[84]
protected 'internal_gapi_mappings' =>
array (size=0)
empty
public 'status' => string 'UNVERIFIED' (length=10)
protected 'modelData' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
Now when i try:
$name = $account->getName(); //accounts/XXXXXXXXXXXXXXXXXXXXX
$service->accounts_locations->listAccountsLocations($name);
i get almost empty Google_Service_MyBusiness_ListLocationsResponse object:
object(Google_Service_MyBusiness_ListLocationsResponse)[88]
protected 'collection_key' => string 'locations' (length=9)
protected 'internal_gapi_mappings' =>
array (size=0)
empty
protected 'locationsType' => string 'Google_Service_MyBusiness_Location' (length=34)
protected 'locationsDataType' => string 'array' (length=5)
public 'nextPageToken' => null
public 'totalSize' => null
protected 'modelData' =>
array (size=0)
empty
protected 'processed' =>
array (size=0)
empty
What is wrong? Am I doing something wrong, or i have wrong credentials(?). How can I check/ask client that he gave me correct access. Can he check Account name in his panel or something?
You appear to be trying to use a service account. As per the doucmentation Basic setup you need to create an Oauth2 client and use that to login to an account that has access to the my business account.
Service accounts do not appear to be supported by Google MyBusiness API as per the documentation.
Why are new entities instantiated with null for all values except the data in the json, why is the entity constructor not setting defaults - putting a die() in the constructor never gets executed.
Update:
Ok so digging into the code, when no managed entity is found, JMSS will use the doctrine instantiator class to create the entity - its sole job, to create entities without calling the constructor. Is there a reason for this? this is inside JMS\Serializer\Construction\UnserializeObjectConstructor
I've configured the object constructor to use the doctrine object constructor written by JMS, but the same issue happens with and without this.
jms_serializer.object_constructor:
alias: jms_serializer.doctrine_object_constructor
public: false
Existing entities are updated without trouble, however new entities are missing all constructor set defaults.
Under 'fields' element 0 is existing, element 1 is new.
array (size=3)
'id' => int 2
'name' => string 'Categories' (length=10)
'fields' =>
array (size=2)
0 =>
array (size=7)
'id' => int 49
'displayName' => string 'Car Branded' (length=11)
'type' => string 'checkboxlist' (length=12)
'required' => boolean false
'disabled' => boolean false
'name' => string 'h49' (length=3)
1 =>
array (size=3)
'type' => string 'email' (length=5)
'name' => string 'field3491' (length=9)
'displayName' => string 'Email' (length=5)
The entity looks like this after deserializing:
object(stdClass)[2000]
public '__CLASS__' => string 'AppBundle\Entity\FormElement' (length=28)
public 'id' => null
public 'label' => string 'Email' (length=5)
public 'type' => string 'email' (length=5)
public 'defaultValue' => null
public 'required' => null
public 'mappedField' => null
public 'garbageCollection' => null
public 'sortOrder' => null
public 'disabled' => null
public 'uuid' => null
public 'form' => null
public 'multiOptions' => null
public 'filters' => null
public 'submissions' => null
The entity constructor:
public function __construct()
{
$this->required = false;
$this->disabled = false;
$this->garbageCollection = false;
$this->sortOrder = 0;
$this->type = 'text';
}
And finally this is how im deserializing:
$serializer = $this->get('jms_serializer');
$entryForm = $serializer->deserialize($json_data, 'AppBundle\Entity\EntryForm', 'json');
The issue is the default ObjectConstructor uses Doctrine's Instantiator, which does not call the class' constructor. To solve this, you can create your own ObjectConstructor that just returns a new instance of the class.
Example:
<?php
namespace AppBundle\Serializer;
use JMS\Serializer\Construction\ObjectConstructorInterface;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\VisitorInterface;
class ObjectConstructor implements ObjectConstructorInterface
{
/**
* {#inheritdoc}
*/
public function construct(
VisitorInterface $visitor,
ClassMetadata $metadata,
$data,
array $type,
DeserializationContext $context
) {
$className = $metadata->name;
return new $className();
}
}
If you're using the bundle, just set jms_serializer.unserialize_object_constructor.class parameter to that new class. Otherwise in your builder, use the class as your object constructor.
What worked for me was simply adding this to the jms_serializer config:
jms_serializer:
object_constructors:
doctrine:
fallback_strategy: "fallback"
I have a problem with accessing one of the properties in stdClass returned from Twitter api, I'm trying to get property named extended_entities however PHP constantly returns error complaining that the property doesn't exist. I can clearly see it thoug in var_dump. See output:
object(stdClass)[597]
public 'created_at' => string 'Mon Mar 23 16:39:25 +0000 2015' (length=30)
public 'id' => int 580046201061580800
public 'id_str' => string '580046201061580800' (length=18)
...
public 'user' =>
object(stdClass)[600]
...
...
public 'notifications' => boolean false
public 'geo' => null
...
public 'entities' =>
object(stdClass)[581]
public 'hashtags' =>
array (size=0)
empty
public 'symbols' =>
array (size=0)
empty
public 'user_mentions' =>
array (size=0)
empty
public 'urls' =>
array (size=0)
empty
public 'media' =>
array (size=1)
0 =>
object(stdClass)[593]
...
public 'extended_entities' =>
object(stdClass)[573]
public 'media' =>
array (size=2)
0 =>
object(stdClass)[556]
...
1 =>
object(stdClass)[595]
...
public 'favorited' => boolean false
public 'retweeted' => boolean false
public 'possibly_sensitive' => boolean false
public 'possibly_sensitive_appealable' => boolean false
public 'lang' => string 'en' (length=2)
I have no problem getting property for example retweeted, created_at etc. in the following way:
$response->retweeted //this returns false
$response->user //returns stdClass
however
$response->extended_entities
or
$response->extended_entities->media
returns
Notice: Undefined property: stdClass::$extended_entities
I expect to have object or array respectively. I don't understand why I can access some of the properties and this one not?
This is a really simple task, that has me absolutely stumped! I'm pulling back some JSON via CURL and PHP, and attempting to access the data from the below structure:
object(stdClass)[1]
public 'maxResults' => int 43
public 'resultList' =>
array (size=43)
0 =>
object(stdClass)[2]
public '#class' => string '' (length=64)
public 'id' => int
public 'version' => int 0
public 'dateCreated' => string '2014-02-11T18:37:55.835+0000' (length=28)
public 'dateModified' => null
public 'locationId' => int
public 'departmentId' => int
public 'ownerCompanyId' => int
public 'active' => boolean true
public 'userId' => int
public 'userName' => string '' (length=24)
public 'externalCode' => null
public 'employeeDetails' =>
object(stdClass)[3]
...
public 'chargeBandAllocationsIds' =>
array (size=7)
...
public 'personalRateChargeBandId' =>
object(stdClass)[13]
...
public 'employeeGroupIds' =>
array (size=0)
...
public 'isResource' => boolean false
(I've removed some of the values, for privacy reasons)
Now I'm trying to var_dump using var_dump(json_decode($result, false));, however when I try and get into the 'resultList' array using var_dump(json_decode($result['resultList'], false)); I get an illegal string offset error.
$result is the JSON string, your cannot do $result['resultList'] on a string. It only becomes a structure after you json_decode it. However, you're decoding it as object, not array, so this wouldn't work either way.
$data = json_decode($result);
var_dump($data->resultList);
var_dump($data->resultList[0]);
var_dump($data->resultList[0]->id);
foreach ($data->resultList as $employee) {
var_dump($employee->id);
}
Answer
*$this->db->set('page_routes','pageid', $newid);*
Should have been
$this->db->update('page_routes', array('pageid' => $newid));
I am trying to create a page where, you can submit a form and it update values based on what you select, I cannot see what I am doing wrong but at some point, I think I am erring with regards to the MySQL command.
The idea is you select a page(friendly name) on the top option-select, and on the bottom you set the ID to the value of another pageID.
The effect it should be achieving is that the user can change change what content is displayed on a particular page.
Question: According to the query return, the update runs, but nothing is changed in my page_routes table
My View, the values are pulled from the database, they populate correctly.
<form class="form-horizontal" action="<?php echo site_url('/view/updatepageid'); ?>" method="post">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- Select Basic -->
<div class="control-group">
<label class="control-label" for="friendly_name">Page</label>
<div class="controls">
<select id="friendlyname" name="friendlyname" class="input-xlarge">
<?php foreach($pageroutes as $key): ?>
<option value="<?php echo $key['friendly_name']; ?>"><?php echo $key['friendly_name']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Select Basic -->
<div class="control-group">
<label class="control-label" for="selectbasic">Change to:</label>
<div class="controls">
<select onchange="this.form.submit();" id="newid" name="newid">
<?php foreach($page_data as $key): ?>
<option value="<?php echo $key['id']; ?>"><?php echo $key['pagetitle']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</fieldset>
</form>
Which submits to here
function updatepageid(){
$this->load->model('view_model');
$friendlyname = $this->input->post('friendlyname');
$newid = $this->input->post('newid');
$query = $this->view_model->setpageid($friendlyname, $newid);
if($query == TRUE){
echo 'updated';
}else { echo 'failed'; }
var_dump($query);
}
and my Model view_model setpageid function
function setpageid($friendlyname, $newid){
$this->db->where('friendly_name', $friendlyname);
$query = $this->db->set('page_routes','pageid', $newid);
return $query;
}
If I var_dump($query) it returns
Object(CI_DB_mysql_driver)[14]
public 'dbdriver' => string 'mysql' (length=5)
public '_escape_char' => string '`' (length=1)
public '_like_escape_str' => string '' (length=0)
public '_like_escape_chr' => string '' (length=0)
public 'delete_hack' => boolean true
public '_count_string' => string 'SELECT COUNT(*) AS ' (length=19)
public '_random_keyword' => string ' RAND()' (length=7)
public 'use_set_names' => boolean false
public 'ar_select' =>
array (size=0)
empty
public 'ar_distinct' => boolean false
public 'ar_from' =>
array (size=0)
empty
public 'ar_join' =>
array (size=0)
empty
public 'ar_where' =>
array (size=1)
0 => string '`friendly_name` = 'aboutus'' (length=28)
public 'ar_like' =>
array (size=0)
empty
public 'ar_groupby' =>
array (size=0)
empty
public 'ar_having' =>
array (size=0)
empty
public 'ar_keys' =>
array (size=0)
empty
public 'ar_limit' => boolean false
public 'ar_offset' => boolean false
public 'ar_order' => boolean false
public 'ar_orderby' =>
array (size=0)
empty
public 'ar_set' =>
array (size=1)
'`page_routes`' => string ''pageid'' (length=8)
public 'ar_wherein' =>
array (size=0)
empty
public 'ar_aliased_tables' =>
array (size=0)
empty
public 'ar_store_array' =>
array (size=0)
empty
public 'ar_caching' => boolean false
public 'ar_cache_exists' =>
array (size=0)
empty
public 'ar_cache_select' =>
array (size=0)
empty
public 'ar_cache_from' =>
array (size=0)
empty
public 'ar_cache_join' =>
array (size=0)
empty
public 'ar_cache_where' =>
array (size=0)
empty
public 'ar_cache_like' =>
array (size=0)
empty
public 'ar_cache_groupby' =>
array (size=0)
empty
public 'ar_cache_having' =>
array (size=0)
empty
public 'ar_cache_orderby' =>
array (size=0)
empty
public 'ar_cache_set' =>
array (size=0)
empty
public 'ar_no_escape' =>
array (size=0)
empty
public 'ar_cache_no_escape' =>
array (size=0)
empty
public 'username' => string 'root' (length=4)
public 'password' => string '' (length=0)
public 'hostname' => string 'localhost' (length=9)
public 'database' => string 'cms' (length=3)
public 'dbprefix' => string '' (length=0)
public 'char_set' => string 'utf8' (length=4)
public 'dbcollat' => string 'utf8_general_ci' (length=15)
public 'autoinit' => boolean true
public 'swap_pre' => string '' (length=0)
public 'port' => string '' (length=0)
public 'pconnect' => boolean true
public 'conn_id' => resource(50, mysql link persistent)
public 'result_id' => resource(57, mysql result)
public 'db_debug' => boolean true
public 'benchmark' => float 0.00099992752075195
public 'query_count' => int 1
public 'bind_marker' => string '?' (length=1)
public 'save_queries' => boolean true
public 'queries' =>
array (size=1)
0 => string 'SELECT *
FROM (`sessions`)
WHERE `session_id` = '93072e3813e9ac20216c8cf6affc1d1b'
AND `user_agent` = 'Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0'' (length=171)
public 'query_times' =>
array (size=1)
0 => float 0.00099992752075195
public 'data_cache' =>
array (size=0)
empty
public 'trans_enabled' => boolean true
public 'trans_strict' => boolean true
public '_trans_depth' => int 0
public '_trans_status' => boolean true
public 'cache_on' => boolean false
public 'cachedir' => string '' (length=0)
public 'cache_autodel' => boolean false
public 'CACHE' => null
public '_protect_identifiers' => boolean true
public '_reserved_identifiers' =>
array (size=1)
0 => string '*' (length=1)
public 'stmt_id' => null
public 'curs_id' => null
public 'limit_used' => null
public 'stricton' => boolean false
If I have missed anything relevant to helping trouble shoot, please let me know, Thank you for your time, I believe it something simple I am missing, as I am self taught and my understanding isn't thorough as I'd like it to be.
Change your function to this:
function setpageid($friendlyname, $newid)
{
$this->db->where('friendly_name', $friendlyname);
$this->db->update('page_routes', array('pageid' => $newid));
return $this->db->affected_rows()>0 ? TRUE : FALSE;
}
This will update the page_routes table, specifically the pageid column, with the value of $newid where friendly_name = $friendlyname.
It will then return either boolean true or false, whether any rows were affected.
I hope this is what you mean?