I have next variables:
$type_model = ProductTypeModel::model()->findByPk($id);
$prod = $type_model->product;
Now in $prod:
array
(
0 => ProductModel#1
(
[CActiveRecord:_new] => false
[CActiveRecord:_attributes] => array
(
'product_id' => '6'
'product_type_id' => '5'
)
...
)
1 => ProductModel#2
(
'product_id' => '8'
'product_type_id' => '5'
)
...
How i can display my products in CGridView?
Thx.
I Suppose you are using CarrayDataProvider. So in your controller
$dataProvider = new CArrayDataProvider($prod);
Here $product could be any array you want to display in CgridView. Now
In you view write this.
$gridColumns = array(
array(
'header' => 'First Name',
'value' => 'ProductTypeModel::model()->findByPk($data->product_id)->key',
'htmlOptions' => array('style' => 'text-align:center;')
),
$this->widget('zii.widgets.grid.CGridView',array('dataProvider' => $dataProvider,));
As in CarrayDataprovider array is obtained so we cant use relations in it. Thats why u have to write 'ProductTypeModel::model()->findByPk($data->product_id)->key'
Here you can display anything attribute of ProductTypeModel so u can replace above mentioned key with your desired attribute
Try this ...
it automatic convert to array data provider.
$dataProvider=new CArrayDataProvider($type_model->product);
Thanks all. By means of answers "naveen goyal" and "jailed abroad" i did like this:
$dataProvider=new CArrayDataProvider($type_model->product);
$dataProvider->keyField = 'product_id';
$this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'header' => 'Title',
'value' => 'CHtml::encode($data["product_title"])',
),
)));
Nice work for me.
Related
I go through this documentation "https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/journalentry"
And tried to add journal entry with line having customer as shown in the below code:
$journal_entry_create['TxnDate'] = date('Y-m-d');
$journal_entry_line = array(
'Amount' => $amount,
'DetailType' => 'JournalEntryLineDetail',
'JournalEntryLineDetail' => array(
'PostingType' => Credit,
'Entity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'type' => 'Customer',
'value' => "2",
'name' => 'Abc'
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
);
$journal_entry_lines[] = $journal_entry_line;
$journal_entry_create['Line'] = $journal_entry_lines;
$journal_entry_receipt_create = QBJournalEntry::create($journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
Without EntityRef its working fine but when I add EntityRef its giving me error "Message: Passed array has no key for 'Value' when contructing an ReferenceType"
Only just came across this problem myself. They did fix this issue but didn't seem to document it at all or tell anyone. Found the fix in the source code. You need to use "JournalEntryEntity" instead of "Entity" under "JournalEntryLineDetail", like so:
'JournalEntryLineDetail' => array(
'PostingType' => "Credit",
'JournalEntryEntity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'value' => "2"
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
Also I used the FacadeHelper from the V3 of the PHP SDK (I'm not sure if it'll work with the method you were using):
use QuickBooksOnline\API\Facades\FacadeHelper;
...
$journal_entry_receipt_create = FacadeHelper::reflectArrayToObject('JournalEntry', $journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
I know this is probably too late for you OP but hopefully it helps someone else!
I have a form with 3 pages and each page have different fields
in my controller i am able to make data in json format which is as
controller code
$input = $request->all();
unset($input['_token']);
unset($input['submit']);
$form_attributes = json_encode($input);
dd($form_attributes);
Output is as
"{"name":"test","student":"yes","email":"test.student#gmail.com","format":"auto",
"lists":["1,2"],"class_lists":["2,5"],"status":"1"}"
I not show full form so that it will easy to understand with small data
I want to make above out put as
its array should save as one main array Student then page1 array page2 array and then page3 array
it should be as
"Student":[{"arraypage1":[{"name":"test","student":"yes","email":"student#gmail.com"}],
"arraypage2":[{"format":"auto","lists":["1,2"]}],
"arraypage3":[{"class_lists":["2,5"],"status":"1"}]]"
Please help me to encode this data in above format
Thanks
You can easily build up an associative array in your desired format, then json_encode() it:
$formattedOutput = Array(
'student' => Array(
'arraypage1' => Array(
'name' => $input['name'],
'student' => $input['student'],
'email' => $input['email']
),
'arraypage2' => Array(
'format' => $input['format'],
'lists' => $input['lists']
),
'arraypage3' => Array(
'class_lists' => $input['class_lists'],
'status' => $input['status']
)
)
);
$form_attributes = json_encode($formattedOutput);
The exact key names may differ, but you should get the idea.
UPDATE:
To get the square brackets, you can wrap with additional Array():
$formattedOutput = Array(
'student' => Array(
Array('arraypage1' =>
Array(
Array(
'name' => $input['name'],
'student' => $input['student'],
'email' => $input['email']
)
)
),
Array('arraypage2' =>
Array(
Array(
'format' => $input['format'],
'lists' => $input['lists']
)
)
),
Array('arraypage3' =>
Array(
Array(
'class_lists' => $input['class_lists'],
'status' => $input['status']
)
)
)
)
);
see this post for more details: no square bracket json array
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 Yii EDataTables Extension : http://www.yiiframework.com/extension/edatatables/
I have Widget of EDataTables as follow
$this->createWidget(
'ext.EDataTables.EDataTables', array(
'id' => 'items',
'dataProvider' => $dataProvider,
'ajaxUrl' => '/ajax-update',
'columns' => array(array(
'user_id',
'email',
'name',
'created_at:date:Updated',
'updated_at:date:Updated',
)
),
'options' => array(
'bStateSave' => false,
'bPaginate' => true,
),
)
);
I want to pass custom ( value,array or object to the widget so i can use it in the row value )
I have looked around many places but i couldn't find way to do it.
Could you please advice how to do that ?
Assuming you have custom column Value for name for example :
$nameExp = '$this->grid->options["nameArray"][$data->user_id]';
And Array like this
$namesInArray = array(
'1'=>'FirstName LastName 1',
'2'=>'FirstName LastName 2',
'3'=>'FirstName LastName 3',
'4'=>'FirstName LastName 4',
);
The possible way to pass extra data not from data provide is to send it with options or htmloptions array ( because all other params for the widget has to have an attribute in the class referring to )
So You can pass the object or the array in the options array and use it as below
$nameExp = '$this->grid->options["nameArray"][$data->user_id]';
$namesInArray = array(
'1'=>'FirstName LastName 1',
'2'=>'FirstName LastName 2',
'3'=>'FirstName LastName 3',
'4'=>'FirstName LastName 4',
);
$this->createWidget(
'ext.EDataTables.EDataTables', array(
'id' => 'items',
'dataProvider' => $dataProvider,
'ajaxUrl' => '/ajax-update',
'columns' => array(array(
'user_id',
'email',
'name',
array('class' => 'CDataColumn', 'name' => 'Name from array options', 'sortable' => false, 'value' => $nameExp, 'type' => 'raw'),
'created_at:date:Updated',
'updated_at:date:Updated',
)
),
'options' => array(
'bStateSave' => false,
'bPaginate' => true,
'nameArray' => $namesInArray
),
)
);
You will be able to use/access the Array, value or the object with that row value expression and do the logic you need there !
I have been looking how to do this and am a bit stumped.
My array is as follows:
$returndata->setup_array = array(
'General' => array(
'Main Details' => 'setup/maindets',
'Directories' => 'directories',
'Extension Allocation' => 'xtnallo',
'List Holidays' => 'setup/holidays',
'List Group VM' => 'groupvm',
'Conference Rooms' => 'confroom'
),
'Offices' => array(
'List Offices' => 'iptoffices'
),
'Users' => array(
'List Users' => 'iptusers'
),
'Phones' => array(
'List Phones' => 'iptphones'
),
);
However I have 1 item that on a certain condition(triggered by the users session) that needs to be added to the listin the general array. The section being 'View Details => setup/viewdetails'. I have tried array push (probably incorrectly) but this adds the item as another array at the end under the main array.
I want/need it to work like this:
$returndata->setup_array = array(
'General' => array(
$viewdets
'Main Details' => 'setup/maindets',
'Directories' => 'directories',
'Extension Allocation' => 'xtnallo',
'List Holidays' => 'setup/holidays',
'List Group VM' => 'groupvm',
'Conference Rooms' => 'confroom'
),
'Offices' => array(
'List Offices' => 'iptoffices'
),
'Users' => array(
'List Users' => 'iptusers'
),
'Phones' => array(
'List Phones' => 'iptphones'
),
);
$viewdets = "'View Details' => 'setup/viewdetails'";
and still be interpreted as a functioning array for use as a menu.
$returndata->setup_array['General']['View Details'] = 'setup/viewdetails'
Cheers Rick!
You can use ArrayObject to have the array as a reference:
$a = new ArrayObject();
$b = array(
"a" => $a
);
$a[] = "foo";
print_r($b);
What did you try calling array_push() on? Have you tried
array_push($returndata->setup_array['General'], $viewdets);
You would need to add the variable to the specific depth of the array you wanted it to be present. check out array_push here, there's also a short language syntax that avoids the function call:
$returndata->setup_array['General'][] = $viewdets;