how to set base_url in trntv filekit yii2 - file-upload

I am using trntv filekit in yii2, when I update profile the widget save profile image correctly in storage but save wrong base_url in database? var_dump result show following code :
C:\wamp64\www\realestate\frontend\modules\user\controllers\DefaultController.php:72:
array (size=6)
'path' => string '1/8fxqQhjo7lhtCkMnNDM6mdo2sODCUtVb.png' (length=38)
'name' => string 'Capture' (length=7)
'size' => string '33507' (length=5)
'type' => string 'image/png' (length=9)
'order' => string '' (length=0)
'base_url' => string '/source' (length=7
but I want to get following
base_url' => string 'http://localhost/realestate/storage/web/source' (length=45)
How can I change base_url?

'fileStorage'=>[
'class' => 'trntv\filekit\Storage',
'baseUrl' => '#web/image' // you should assign this way
'filesystem'=> ...
// OR
'filesystemComponent' => ...
],
https://github.com/trntv/yii2-file-kit#file-storage

Related

How to add an entity content programmatically in drupal

Good night: I used to create node programmatically with a code similar to:
use Drupal\node\Entity\Node;
$nodeObj = Node::create([
'type' => 'article',
'title' => 'Programatically created Article',
'body' => "CodeExpertz is contains best Blogs.",
'field_date' => '2017-10-24',
'field_category' => 'Study',
'uid' => 1,
]);
$nodeObj->save(); // Saving the Node object.
$nid = $nodeObj->id(); // Get Nid from the node object.
Print "Node Id is " . $nid;
Now I want to create entities content (no nodes) but I can't find something about this. I tried to adapt the next snippet:
$term = \Drupal\taxonomy\Entity\Term::create([
'vid' => 'test_vocabulary',
'name' => 'My tag',
]);
$term->save();
to this (vehicle is my entity):
$newvehicle = \Drupal\vehicle\Entity\Vehicle::create([
'title' => 'Ferrari'
]);
$newvehicle->save();
The result is the white page of death.
Thanks for your help.
I was able to do it with this code
use Drupal\customModule\Entity\entityCustom;
$entityCustom = entityCustom::create([
'type' => 'custom_entity',
'uid' => 1,
'status' => TRUE,
'promote' => 0,
'created' => time(),
'langcode' => 'en',
'name' => 'NAME',
]);
$entityCustom->save();

Prestashop: not saving field

I'm working in a Prestashop 1.6 module and I'm having problem with one field that seems not to be recognized. In the controller I'm using the renderForm() method to get the form and I define the field in the form like this:
array(
'type' => 'text',
'label' => $this->l('Message'),
'name' => 'message',
'required' => true,
'hint' => $this->l('Message to be shown when the customer exceeds the quota '),
),
And in the model class I define it like this:
'message' => array(
'type' => self::TYPE_STRING,
'validate' => 'isString',
'required' => true,
'size' => 4000,
'db_type' => 'varchar'
),
And then when I try to save the record I get this message: Property QuotaModel->message is empty
Am I missing a definition somewhere else? Can you see what I'm missing here?
Thanks for any help
Define the field as public property in your object model class.
class QuotaModel extends ObjectModel
{
...
public $message;
...
}

Symfony DQL - transform the array query result

I'm trying to transform the array of my query result.
First I did this query:
public function findAllTraduction()
{
return $this->createQueryBuilder('c')
->select('c.key, c.content, c.id, f.locale')
->leftJoin('c.TraductionFile', 'f')
->groupBy('c.key')
->getQuery()
->getArrayResult();
}
The result is like that:
array
0 =>
array
'key' => string 'FORMAT1'
'content' => string 'login'
'id' => int 507
'locale' => string 'en'
1 =>
array
'key' => string 'FORMAT1'
'content' => string 'connecter'
'id' => int 508
'locale' => string 'fr'
2 =>
array
'key' => string 'FORMAT2'
'content' => string 'password'
'id' => int 503
'locale' => string 'en'
3 =>
array
'key' => string 'FORMAT2'
'content' => string 'mot de passe'
'id' => int 504
'locale' => string 'fr'
What I would like to have is an array like that:
array
'FORMAT1' =>
array
'en' =>
array
'content' => string 'login'
'id' => int 507
'fr' =>
array
'content' => string 'connecter'
'id' => int 508
'FORMAT2' =>
array
'en' =>
array
'content' => string 'password'
'id' => int 503
'fr' =>
array
'content' => string 'mot de passe'
'id' => int 504
In fact, for each same 'key' (here 'FORMAT1' and 'FORMAT2', regroup by 'locale' (EN and FR)
Is it possible to do that in the query ?
I tried with GROUPBY and DISTINCT but nothing happened...
If not possible in query, may be redraw an array with loop....
thank you !
Doctrine provides a way to specify indexBy when creating the QueryBuilder in order to index the resulting array not in a sequential way but by a specific key :
createQueryBuilder($alias, $indexBy = null)
So you may want to try something like createQueryBuilder('c', 'c.key') to use c keys as array indexes
I found a solution with foreach for redraw the array ...
$catalogue = [];
foreach ($catalogues_array as $index => $val) {
$key = $val['key'];
$locale = $val['locale'];
unset($catalogues_array[$index]['key']);
unset($catalogues_array[$index]['locale']);
$catalogue[$key][$locale] = $catalogues_array[$index];
}
return $catalogue;
the result :
array (size=421)
'base_template.page_title' =>
array (size=2)
'en' =>
array (size=6)
'content' => string 'Audio Video Caption - Subtitling & Transcription of media.' (length=58)
'description' => null
'traductionControle' => boolean false
'id' => int 1
'domain' => string 'messages' (length=8)
'bundleName' => string 'app' (length=3)
'fr' =>
array (size=6)
'content' => string 'Audio Video Caption - Sous-Titrage & Transcription de médias.' (length=62)
'description' => null
'traductionControle' => boolean false
'id' => int 9
'domain' => string 'messages' (length=8)
'bundleName' => string 'app' (length=3)
'base_template.meta.keywords' =>
array (size=2)
'en' =>
array (size=6)
'content' => string 'closed captioning, subtitle, speech recognition, transcription, traduction, video, audio' (length=88)
'description' => null
'traductionControle' => boolean false
'id' => int 2
'domain' => string 'messages' (length=8)
'bundleName' => string 'app' (length=3)
'fr' =>
array (size=6)
'content' => string 'sous-titre, reconnaissance vocale, transcription, traduction, video, audio' (length=74)
'description' => null
'traductionControle' => boolean false
'id' => int 10
'domain' => string 'messages' (length=8)
'bundleName' => string 'app' (length=3)

cakephp save is not working 2.X

I am using CakePHP 2.3, I want to save data as follows follows:
$insertUser = array(
'Name' => $Name,
'LastName' => $lastName,
'password' => $password,
'email' => $email,
'TimeStamp' => $presentTime,
'RefererUserId' => $refererId // set the referer user id
);
$this->SystemUser->saveAll($insertUser) // save record in table.
The above code is not working. I tried another method like:
$this->SystemUser->query("INSERT INTO system_users(Name,LastName,password,email,TimeStamp,RefererUserId) VALUES ('{$Name}','{$lastName}','{$password}','{$email}','{$presentTime}','{$refererId}')");
How can I now get the last inserted id? I used getLastInsertId() to get last inserted id, as below:
$lastid = $this->SystemUser->getLastInsertId();
But it does not seem to work.
Please try the below code. SystemUser is assumed as your model name.
$this->user_data = array(
'SystemUser' => array(
'Name' => $Name,
'LastName' => $lastName,
'password' => $password,
'email' => $email,
'TimeStamp' => $presentTime,
'RefererUserId' => $refererId // set the referer user id
));
if ($this->SystemUser->save($this->user_data)) {
$lastid = $this->SystemUser->getLastInsertId();
} else {
// do something
}
Your $insertUser should be the following
$insertUser['SystemUser'] = array(
'Name' => $Name,
'LastName' => $lastName,
'password' => $password,
'email' => $email,
'TimeStamp' => $presentTime,
'RefererUserId' => $refererId // set the referer user id
);
Then you should be save data as like
if($this->SystemUser->save($insertUser)) {
$lastid = $this->SystemUser->getLastInsertId();
} else {
debug($this->SystemUser->validationErrors); die();
}
This will probably give you the info you need (assuming it's not saving because of invalid data, of course):
debug($this->SystemUser->validationErrors); die();
That's it.

Yii file CFormInputElement won't display unless explicitly marked "safe"

I'm trying to use Form Builder to build a simple file upload prompt. I want to specify the rule for the file to be similar to
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html'),
but something is wrong. The file upload element only appears if I explicitly mark the element as 'safe' (and remove the 'file' rule). What am I missing?
models/UploadForm.php
class UploadForm extends CFormModel
{
public $year;
public $formFile;
public function rules ()
{
return array(
array('year', 'required'),
array('year', 'date', 'format'=>'yyyy'),
// array('formFile', 'safe'),
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html'),
);
}
static public function getYearOptions () {...}
}
views/extranet/uploadForm.php
return array(
'title' => 'Select year',
'method' => 'post',
'enctype' => 'multipart/form-data',
'elements' => array(
'year' => array(
'type' => 'dropdownlist',
'items' => UploadForm::getYearOptions(),
),
'formFile' => array(
'type' => 'file',
'label' => 'form source file',
),
),
'buttons' => array(
'upload' => array(
'type' => 'submit',
'label' => 'upload',
),
),
);
controllers/ExtranetController.php
class ExtranetController extends CController
{
public function actionIndex ()
{
$form = new CForm('application.views.extranet.uploadForm', new UploadForm());
if ($form->submitted('upload') && $form->validate()) {...}
$this->render('index', array('form' => $form));
}
}
The reason for this is very simple.
The form builder only renders input elements which are considered safe (I.E. have a validation rule). What you have done is perfectly fine, except CFileValidator isn't "safe" by default, whereas other validators are safe.
The quickest way to solve this is the following:
// In your model::rules() function
return array(
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html', 'safe' => true),
);
Refer to these two links for more information: the CFileValidator#safe documentation, and the Github issue for a problem very similar to yours.