I have using cakephp for my website. And i use sql server 2012 with it.
I have confused that when i use:
$this->set('types',$this->Manager->query('select * from product_types'));
to get the array of all my product types
the return array is:
Array
(
[0] => Array
(
[0] => Array
(
[id] => 1
[name] => hoa my pham
)
)
[1] => Array
(
[0] => Array
(
[id] => 2
[name] => hoa my
)
)
)
Why has the [0] instead of [product_types]????
Please follow the documentation and tutorials available.
Then you will be able to just use
$this->set('managers', $this->Manager->find('all'));
for the very same thing - using a clean approach with wrapper functions and a sql server datasource.
For SqlServer there should be a datasource available, for example:
https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/Database/Sqlsrv.php
This is from the CakePHP documentation:
To use the model name as the array key, and get a result consistent with that returned by the Find methods, the query can be rewritten:
$this->Picture->query("SELECT * FROM pictures AS Picture LIMIT 2;");
which returns:
Array
(
[0] => Array
(
[Picture] => Array
(
[id] => 1304
[user_id] => 759
)
)
[1] => Array
(
[Picture] => Array
(
[id] => 1305
[user_id] => 759
)
)
)
So you need:
$this->set('types',$this->Manager->query('select * from product_types as Product_Types'));
Source: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
P.S.:
This syntax and the corresponding array structure is valid for MySQL
only. Cake does not provide any data abstraction when running queries
manually, so exact results will vary between databases.
Related
First, I'm using sugarcrm pro 6.5 and accessing via rest v4, so I have this array that's being returned from printing $results that is working fine:
stdClass Object
(
[result_count] => 2000
[total_count] => 3390
[next_offset] => 2000
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 77da301b-83dd-4fe6-e38f-53ba151fb084
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 77da301b-83dd-4fe6-e38f-53ba151fb084
)
[name] => stdClass Object
(
[name] => name
[value] => Jim Beam
)
[status] => stdClass Object
(
[name] => status
[value] => Dead
)
[website] => stdClass Object
(
[name] => website
[value] => website.com
)
[phone_cr] => stdClass Object
(
[name] => phone_cr
[value] => 1-888-888-8888
)
)
)
[1] => stdClass Object
(
[id] => d0ecc069-d556-98f3-41f2-53ba1468327a
[module_name] => Leads
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => d0ecc069-d556-98f3-41f2-53ba1468327a
)
[name] => stdClass Object
(
[name] => name
[value] => John Doe
)
[status] => stdClass Object
(
[name] => status
[value] => New
)
[website] => stdClass Object
(
[name] => website
[value] => web.com
)
[phone_cr] => stdClass Object
(
[name] => phone_cr
[value] => 1-888-888-8888
)
)
)
I'm using a query from the api to filter the results for the user I'm targeting:
'query' => "leads.assigned_user_id='user_ID-here'",
'order_by' => "date_entered DESC",
This works fine. So I've ran a foreach () statement to retrieve only one field on a button click, which also works just fine. What I really need to accomplish is before this statement, a foreach() command (or something else?) to filter out and retrieve ONLY the "New" results in the status value, and from that group output an array showing only the website field. Seen in the "desired end result section of this question."
This is the code I'm filtering the field I'm targeting and having a new array created with if that helps bridge the gap:
$results = call('get_entry_list', $params, $url);
$eresult = array();
foreach ($results->entry_list as $index=>$value_list) {
$listed = $value_list->name_value_list->website->value;
$eresult[] = $listed;}
So the desired end result based on this data should be:
Array
(
[1] => web.com
)
I'm unsure what I need to do to filter the "Status" field to only then be ran with the $eresult array I created to achieve this. To be clear, everything is working as it should, and my print from $eresult is outputting exactly as it should by returning all results in the website value area, I just need some help to get it sorted before going to that step by sorting it by the "new" status first without all the extra 'stuff,' then sorting out the array in my desired format with the foreach() statement above. I tried to cut out all the other code, as it's a pretty long project, so this should be all the relevant information for the particular goal I need to accomplish in this segment. Any help is greatly appreciated! Thank you!
I've decided to create a second script for this as a temp solution by adding:
'query' => "(leads.assigned_user_id='user_ID-here') AND (status='New')"
So I guess that works, I was trying to avoid calling another script for just one separate function, but it is working fine.
The array I am looking at is this:
Array
(
[0] => Array
(
[0] => Bigcommerce\Api\Resources\ProductCustomField Object
(
[ignoreOnCreate:protected] => Array
(
[0] => id
[1] => product_id
)
[ignoreOnUpdate:protected] => Array
(
[0] => id
[1] => product_id
)
[fields:protected] => stdClass Object
(
[id] => 17
[product_id] => 3232
[name] => Artist
[text] => Test
)
[id:protected] => 17
[ignoreIfZero:protected] => Array
(
)
)
)
)
I want to check to see if 'Artist' exists in a php conditional statement. But I don't know how to turn 'Artist' into a string.
UPDATED:
I did not find understand how to extract that value into a string, but I got what I was looking for using the method related to the bigcommerce api:
$customs = Bigcommerce::getProductCustomFields($product->id);
foreach($customs as $custom) {
if($custom->name == 'Artist'): // do something
endif;
}
Ok, looking at the source, it seems you should be able to use the magic __get method. Try
$array[0][0]->name == 'Artist'
The value of the custom field would be stored in the "text" resource for that custom field.
See the following link where you can see the 4 properties of a custom field.
https://developer.bigcommerce.com/api/stores/v2/products/custom_fields
I don't know what is going on (maybe it because it is the 12th consecutive hour working).
I always used this notation but now it just doesn't work (I already checked several time that the data is passed to this template I'm talking about).
Data is not iterated and the result is empty.
Mustache code:
{{#ad}}
setInput("{{key}}", "{{value}}");
{{/ad}}
I tried also:
{{#ad}}
setInput("{{key}}", "{{value}}");
{{/ad}}
The data passed is the following:
Array
(
[ad] => Array
(
[0] => Array
(
[key] => id
[value] => 1
)
[1] => Array
(
[key] => created_on
[value] => 1371464401
)
[2] => Array
(
[key] => updated_on
[value] =>
)
[3] => Array
(
[key] => dealer_id
[value] => 1
)
)
)
Solved: be careful to not pass hashes instead of "plain" arrays!! Even if it seemed to be a common array because of the indexing (0 => "a", 1 => "b") it was actually an hash! So just return the malicious data within an array_values($data) to fix it!
I moved a website (cakephp 2.1) from a test server ( PHP verson 5.3.10 ) to the live server (PHP verson 5.3.17).
In the new situate all my code started to complaine about undefined
indexes. When debugging an array I see that the array indexes became
numbers instead of the Model names!? What can be the problem of that I
use the exact same installation of cakephp?
Below the 2 examples of arrays.
this is how the array should be.
Array
(
[0] => Array
(
[Post] => Array
(
[id] => 152
[menu_item_id] => 1
)
)
This is the array on the live server
Array
(
[0] => Array
(
[0] => Array
(
[id] => 152
[menu_item_id] => 1
)
)
can't figure out what is the right syntax to add an additional attributes to a LDAP entry. When authenticating i get this array:
Array
(
[0] => Array
(
[cn] => Array
(
[0] => Vit Kos
)
[shortname] => Array
(
[0] => vit.kos
)
[uid] => Array
(
[0] => vit.kos
)
[mail] => Array
(
[0] => vit.kos#email.com
)
[objectclass] => Array
(
[0] => top
[1] => person
[2] => organizationalPerson
[3] => inetOrgPerson
[4] => dominoPerson
)
[givenname] => Array
(
[0] => Vit
)
[userpassword] => Array
(
[0] => password here
)
[sn] => Array
(
[0] => Kos
)
[localadmin] => Array
(
[0] => CN=#SysHQAdmin
)
[mailaddress] => Array
(
[0] => Vit.Kos#email.com
)
[maildomain] => Array
(
[0] => EMAIL
)
[dn] => CN=Vit Kos,OU=###,O=EMAIL
)
)
need to get an additional attribute member to be like
Array (
[uid] => Array
(
[0] => vit.kos
)
[mail] => Array
(
[0] => vit.kos#email.com
)
[member] => Array
(
[0] => MEMBER HERE
)
)
Never worked with LDAP before so it's quite confusing for me. Thanks for the answers.
To assign data to the directory item that you retrieved above, you will perform a "modify" operation with ldap_modify(). This is assuming that the schema of your database allows an attribute called member on this object - which it may not, you cannot simply add attributes to any object as and when you feel like it.
Firstly, you will need to create the entry or entries that will belong to the member attribute, and store them in an array:
$member = array (
0 => "This is some data",
1 => "This is some more data"
);
In order to tell the directory which object we want to modify, we will need it's DN. We can get this from the result of your previous search/list/read operation - the array that you show you have retrieved already (I assume this is stored in a variable called $array):
$dn = $array[0]['dn'];
Now we have all the information we need to perform the modify operation (I assume your connected/bound LDAP resource is held in a variable called $ds):
$result = ldap_modify($ds, $dn, array('member'=>$member));
After this, $result will be a boolean indicating whether the operation was successful or not. If it was unsuccessful, you can get an error message explaining why by calling:
$error = ldap_error($ds);