this is my config/main.php :
'components' => array(
'messages' => array(
'class' => 'CDbMessageSource',
),
and when i execute the command :
-Yiic messages c:/my...files/protected/messages/config.php
return array(
'sourcePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'../..',
'messagePath'=>dirname(__FILE__),
'languages'=>array('fr','en'),
'fileTypes'=>array('php'),
'overwrite'=>true,
'exclude'=>array(
'.git',
'/assets',
'/protected/migrations',
'/protected/messages',
'/protected/runtime',
'/protected/extentions/gii',
'/files',
),
);
the system save don't use de database but the files like if i use CMessageSource...
any idea ?
Many thanks
You did not specify de in your array:
'languages'=>array('fr','en','de'),
Related
Can we upload multiple image to the variation using API. Single image upload can be possible using below code, but not sure about multiple image upload.
$mediaId ='random string';
$url = $images['url'];
$mediaData = array(
array(
'id' => $mediaId,
'mediaFolderId' => $mediaFolderID,
),
);
$mediaDataArr = array(
'payload' => array(
"action" => "upsert",
"entity" => "media",
'payload' => $mediaData,
),
);
$createMedia = $shopware6HelperObj->post('_action/sync', $mediaDataArr);
$urlArr = array(
'url' => $url,
);
$parts = pathinfo($url);
$params = array(
'extension' => $parts['extension'],
'fileName' => $parts['filename'] . '__' . md5(time()),
);
$uploadImage = $shopware6HelperObj->post('_action/media/' . $mediaId . '/upload', $urlArr, $params);
Please suggest if any idea.
I always recommend to try doing that via the Admin Panel and check the Browser's Dev Tools / Network Tab which requests are made. This can give you a good hint on how do to it programmatically.
I have this SQL query that I need to convert to CakePHP. I used this website [http://dogmatic69.com/sql-to-cakephp-find-converter][1] that converts the code but I doesn't work in the way that I want. There is no results.
I think it is because it creates an empty array
here is the SQL code :
SELECT shops.phone1 FROM galleries , albums , shops
WHERE galleries.album_id = albums.id and albums.shop_id = shops.id and galleries.id = 210
and this is the result the website gives me :
$options = array(
'fields' => array(
'shops.phone1',
),
'joins' => array(
array(
),
),
'conditions' => array(
'Gallery.album_id = albums.id',
'albums.shop_id = shops.id',
'Gallery.id' => '210',
),
);
$data = $this->find('all', $options);
but the code doesn't work.
Any Ideas what could be wrong ?
Thanks
There are many ways to achieve this.
If you have defined your associations correctly then you can do this:
$data = $this->Shops->find('all')
->contain(['Galleries','Albums'])
->fields(['Shops.phone1'])
->where(['Galleries.id' => 210]);
Otherwise you can use custom join to generate your query:
$data = $this->Shops->find('all')
->join([
'albums' => [
'table' => 'albums',
'type' => 'INNER', // define your join type here
'conditions' => 'albums.shop_id = Shops.id',
],
'galleries' => [
'table' => 'galleries',
'type' => 'INNER', // define your join type here
'conditions' => 'galleries.album_id=albums.id',
]
])
->select(['Shops.phone1'])
->where(['galleries.id' => 210]);
Further Reading: Cakephp -> Query Builder -> Adding Joins
I have tried to implement the sorting using BootGridView but it does not seem to work. Here is the line of code.
<?php $this->widget('bootstrap.widgets.BootGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'user_id',
array('name'=>'user_type',
'value'=>'User::getType($data->user_type)'),
'username',
array('header'=>'Name',
'type'=>'raw',
'value'=> 'CHtml::link($data->firstname." ".$data->lastname, array("view", "id"=>$data->id))'
),
array('name' => 'status',
'type' => 'raw',
'value' => '$data->status == 1 ? "Active" : CHtml::link("In Active", "javascript:void(0);", array("id" => "active_" . $data->id, "onClick"=>"js:activate($data->id)"))'
),
/*
'email',
'dob',
'profession',
'hobby',
'height',
'weight',
'weight_taken_on',
'login_attempt',
'registration_date',
*/
array(
'class'=>'bootstrap.widgets.BootButtonColumn',
),
),
)); ?>
The code does not seem to sort the table as expected. What could be the possible problem in this. ?
Sorting is configured in the data provider, not in the grid view. So you should look into the search() method of your model. You need something like this:
return new CActiveDataProvider('User',array(
// ...
'sort' => array(
'attributes' => array(
'name',
'email',
// ...
Have a look at CSort and especially the attributes property there to learn more about sort options you can use here.
I am unable to set the value of the column day in the cgrid view :
I am able to see the dropdownlist but all have the same day Monday set irrespective of the value of the day as represented by $data->day
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'type'=>'raw',
'name'=>'day',
'value'=> ' CHtml::dropDownList(\'someName\'.$row,\'$data->day\',array(
\'Mo\'=>\'Monday\',
\'Tu\'=>\'Tuesday\',
\'We\'=>\'Wednesday\',
\'Th\'=>\'Thursday\',
\'Fr\'=>\'Friday\',
\'Sa\'=>\'Saturday\',
\'Su\'=>\'Sunday\',))',
),
'ts_id'
)
));
If you can accept a minor break in MVC then things will get much easier to read if you put a little getter method into your model:
public function getDayDropDown()
{
$days = array('Mo'=>'Monday', ...);
return CHtml::dropDownList('someName', $this->day, $days);
}
Now in your gridview you can use it as a column like
array(
'name' => 'Day',
'type' => 'raw',
'value' => '$data->dayDropDown',
),
Just a minor issue resolved the whole episode.
I had put quotes around $data->day in the original post. which was not needed.
array( 'type'=>'raw',
'name'=>'day',
'value'=> ' CHtml::dropDownList(\'someName\'.$row,$data->day,
array(\'Mo\'=>\'Monday\',
\'Tu\'=>\'Tuesday\',
\'We\'=>\'Wednesday\',
\'Th\'=>\'Thursday\',
\'Fr\'=>\'Friday\',
\'Sa\'=>\'Saturday\',
\'Su\'=>\'Sunday\',)
)',
),
This is an example of dropdown value and update onchange:
$this->widget('bootstrap.widgets.TbGridView', array(
'id'=>'session-grid',
'type'=>'striped bordered condensed',
'dataProvider'=>$PSDataProvider,
'filter'=>$PSModel,
'emptyText'=>'No hay sesiones abiertas.',
'columns'=>array(
array('name'=>'username', 'header'=>'Nombre de Usuario', 'filter'=>CHtml::activeTextField($PSModel, 'username',
array('placeholder'=>'Buscar por usuario...'))),
array('name'=>'product', 'header'=>'Producto', 'filter'=>CHtml::activeTextField($PSModel, 'product',
array('placeholder'=>'Buscar por producto...'))),
array('name'=>'expire', 'value'=>'date("d-m-y H:i:s", $data->expire)','header'=>'Hora de Expiracion', 'filter'=>CHtml::activeTextField($PSModel, 'expire',
array('placeholder'=>'Buscar por expiracion...'))),
array(
'header'=>CHtml::dropDownList('pageSize',$pageSize,array(5=>5,10=>10,20=>20,50=>50),array(
'onchange'=>"$.fn.yiiGridView.update('session-grid',{ data:{pageSize: $(this).val() }})",
'class'=>'span1 custom-tb-dropdown-inline',
)),
'class'=>'bootstrap.widgets.TbButtonColumn',
'htmlOptions'=>array('style'=>'width: 50px'),
'template'=>'{delete}',
'buttons'=>array(
'delete' => array(
'label'=>'Terminar sesión',
),
),
'deleteConfirmation'=>'Está seguro que desea terminar la sesión seleccionada?',
'deleteButtonUrl'=>'$this->grid->owner->createUrl("productSession/delete", $data->primaryKey)'
),
),
));
I have the following model:
$values = $this->PtlUserdata->find('all', array(
'fields' => array(
'PtlUserdata.field',
'PtlUserdata.value',
'PtlUserdata.timestamp'
),
'conditions' => array(
'PtlUserdata.user_id' => $user->get('id'),
),
'order' => array('PtlUserdata.timestamp' => 'DESC'),
'group' => array('PtlUserdata.field')
));
I'm trying to order the results by timestamp and then group the results by field, so I can get the most recent record with that field name.
Does anybody know how to do this is cakephp?
Thanks in advance for any help, much appreciated :)
This is the default behavior for the database. You will have to come up with some sort of workaround to do it.
An idea: CakePHP: Group by ID and Order by date
Does this work:
$values = $this->PtlUserdata->find('all', array(
'fields' => array(
'PtlUserdata.field',
'PtlUserdata.value',
'max(PtlUserdata.timestamp)'
),
'conditions' => array(
'PtlUserdata.user_id' => $user->get('id'),
'PtlUserdata.timestamp' => 'max(PtlUserdata.timestamp)',
),
'group' => array(
'PtlUserdata.field',
'PtlUserdata.timestamp'
)
));
I haven't had the chance to test this but you definitely need to be grouping by PtlUserdata.timestamp.