I have beginner skills only for php,
I need to get several persons information name and surname, currentlt i get only one.
Problem described below, that's more accurate:
current php code fragment:
myRegister($server,'info',array(
'in' => array('id_code' => 'xsd:int'),
'out' => array(
'name' => 'xsd:string',
'surname'=>'xsd:string', )));
current result:
<Response>
<name>Name</name>
<surname>Surname</surname>
</Response>
what I need:
<Response>
<person>
<name>Name</name>
<surname>Surname</surname>
</person>
</Response>
How to write php a multiple arrays? with php ? as I see in this case i can recieve several persons
Can you try this ?
myRegister($server,'info',array(
'in' => array('id_code' => 'xsd:int'),
'out' => array('person' => array(
'name' => 'xsd:string',
'surname'=>'xsd:string', ))));
i'm not an expert, maybe this can be helped
array( 'person' =>
array(
array( 'name' => 'john', 'surname' => 'smith' ),
array( 'name' => 'jack', 'surname' => 'black' ),
...
)
);
In php non associative arrays can not have named nodes as in xml so every element of 'person' array myst be translated in to a node. As far as I am aware (and please correct me if i am wrong) this can only be done via custom function.
Related
I'm creating a form using Zend2 framework, and can't figure out why a simple Textarea is not showing up on the view (below you can see my code). I've tried the type Text and it shows a standard single lined text field, but got luck with Textarea. I've also tried a non existing type, and zend throws an exception, so it seems Textarea type actually exists, and I must be missing a mandatory param or something like that. Could anyone point me in the right direction?
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
)
));
SOLVED
My bad, it looks there was an intermediate layer in the project ignoring all the Textarea fields.
I just check you code and found 2 things missing first
use Zend\Form\Element;
use Zend\Form\Form;
Which I think you have used in you file.
Another mistake was you were missing comma in the code. use this below code.
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
),
));
Good luck
Try changing your 'rows' and 'cols' value from a string to integer (remove single quotes).
'attributes' = > array(
'rows' => 10,
'cols' => 75,
);
Right, so my data returns in the following way,
(int) 0 => array(
'MODEL-XX' => array(
//DATA HERE
'xxs_id' => '11',
'aas_id' => '44',
'vvs_id' => '2'
),
'xxs' => array(
'id' => '11',
'customername' => 'XX name here'
),
'aas' => array(
'id' => '44',
'clientname' => 'aa name here',
'xxs_id' => '11'
),
'vvs' => array(
'id' => '2',
'start' => '1405296000',
'end' => '1405814400',
'users_id' => '1'
)
This works fine, but I want to know how to link my users table to this model. So the details of each user for my VV model would become apart of the data. My MODEL-XX does not have any links with my users table so the place I need to call in the users details are held with my VV model.
I have been looking into this but have not been able to find a simple easy method for doing this?
I was thinking that this would be doable with my model, so I opened my my XX model and added the following within my '$belongsTo' section,
'Users' => array(
'className' => 'Users',
'foreignKey' => 'vvs.users_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
So is there a easy method for linking data like this?
Please give me time, if I have not explained myself right or not enough data, please tell me and let me fix or explain better.
Thanks,
Either set your recusive higher:
$this->MODEL-XX->recursive = 1; //or 2
Or and this should be your prefered way to go, start using the containable behaviour:
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html
In your appModel:
public $actsAs = array('Containable');
Then try this find:
$this->MODEL-XX->recursive = -1;
$data = $this-MODEL-XX>find(
'all', array(
'conditions' => $conditions,
'contain' => array('xxs', 'aas', 'vvs', 'user')
)
);
I might be 'vvs.user' but I forgot what is used for deeper models
I am using Cakephp 2.2.4 and I need to retrive a list of Lead that belongs to the user (id = 106).
The result of the query is:
array(
(int) 0 => array(
'Lead' => array(
'id' => '6',
'user_id' => '106',
'date' => '2012-12-31 22:15:23',
'ip' => '127.0.0.1',
'service_id' => '1',
'location' => 'Rome',
'message' => 'Message Message',
'telephone' => null,
'active' => null
),
'User' => array(
'id' => '106',
'email' => 'daje#daje.it',
'pwd' => '0433c024cb08be13000d59a347e640482843f46f177e95749dc6599c259617fd3491dcb940b47693cbbc7f65a2cc5ef62deca2e600c1be133ad54170f7d1fbd1',
'role_id' => '3',
'active' => '1'
),
'Service' => array(
'id' => '1',
'name' => 'Primo servizio'
),
'Estimate' => array(
(int) 0 => array(
'id' => '1',
'lead_id' => '6',
'user_id' => '106'
)
)
)
)
It looks good but I need to count the Estimates (Estimate array), I would like to retrive the number of the estimates, and not the array with all the fields (of estimates table).
How can i do it?
I need :
Lead array as it shown
User array as it shown
Service array as it shown
Estimate (only the total number of the estimates... in this case 1)
The find is very simple:
$options = array('conditions' => array('User.id' => 106));
debug($this->Lead->find('all', $options));
Try something like this, not 100% sure it'll work but worth a go if not I'd advise trawling the cakephp docs for retrieving your data:
$options = array(
'fields' => array('Lead.*', 'User.*', 'Service.*', 'count(Estimate.id)'),
'conditions' => array('User.id' => 106)
);
Without diving too far into the internals of the Cake ORM, assuming you don't need to do this immediately at query time, couldn't you just get the count of the estimate array programmatically after the fetch?
http://php.net/manual/en/function.count.php
$leads = $this->Lead->find('all',$options);
foreach($leads as $lead){
//get the number of estimates for every lead result
$lead_num = count($lead['Estimate']);
}
Alternatively, you could manually write a join query for this one fetch and execute it using the Cake Model class's query method. Without knowing the specifics of your table schema and model relations its hard to give specifics about how to structure the query, but this shouldn't be too difficult by just look at your table spec and extracting a sql COUNT statement for every Estimate with given id.
we are using SAOP clients for a while now without a problem. But now we are facing the following challenge and I can't find the answer. We need to send the following XML structure:
<Cards>
<CardDetails>
<Name>string</Name>
<Address>string</String>
</CardDetails>
<CardDetails>
<Name>string</Name>
<Address>string</String>
</CardDetails>
</Cards>
As you van see we need two instances of 'CardDetails'. Creating a PHP array will only allow me to send 1.
$data = array(
'Cards' => array(
'CardDetails' => array(
'Name' => 'test name',
'Address' => 'test address'
),
'CardDetails' => array(
'Name' => 'second test name',
'Address' => 'second test address'
)
)
));
Of course, only the second address will be used. But what would be the solution to make this work?
Thanks a lot!
Use php dom to create xml from an array , here is a good example of it http://www.ibm.com/developerworks/library/os-xmldomphp/
And what function/class are you using to turn array to xml?
Try this structure:
$data = array(
'Cards' => array(
'CardDetails' => array(
array(
'Name' => 'test name',
'Address' => 'test address'
),
array(
'Name' => 'second test name',
'Address' => 'second test address'
)
)
)
);
If this doesn't work and you can modify serializing function, just check if current key is numerical. If it is, use parent key name for tag.
I've created a custom node type in Drupal 7, using the hook_node_info method in the install file:
// declare the new node type
function foo_node_info ( ) {
return array(
'foo' => array(
'name' => t('Foo entry'),
'base' => 'node_content',
'description' => t('For use to store foo entries.'),
));
} // END function foo_node_info
and I'm trying to save that type in the module file using the following code:
// INSERT the stuff
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'Title, blah blah blah',
'url' => 'url here, just pretend',
'body' => '<p>test</p>',
)));
My issue, is that the url, and body fields aren't saving. Any idea what I'm doing wrong?
So, after a ton of digging, it turns out that the way I was entering the custom fields in the node_save was wrong. The node_save needs to look like the following:
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'the title',
'url' => array(
'und' => array(array(
'summary' => '',
'value' => 'url value',
'format' => 2,
))),
'body' => array(
'und' => array(array(
'summary' => '',
'value' => 'the body goes here',
'format' => 2,
))),
)));
Notice that for the custom fields, the array structure has to match what was previously going on with CCK (pretty much exactly). The first key in the array describing the field value is the language for the content.
I've used 'und' here only because that's what I saw going into the database when entering the data through a form.