ajaxlink shows blank # Yii - yii

my ajaxlink shows # instead of the link. I tried using chtml::link, and that displayed it correctly.
<?php
echo CHtml::ajaxLink("<img alt=".$data->text."
src=".Yii::app()->assetManager->publish(Yii::app()->basePath."/images/".$data->img)."
title=".$data->text." height=100px width=100px/>",
Yii::app()->createUrl('controller/action',array('id'=>$data->id)),
array(
"type" => "post",
"data" => "js:{ids:$.fn.yiiGridView.getSelection('chck-id')}",
"update" => "#grid"));
?>

Look at the ajaxLink function
public static function ajaxLink($text,$url,$ajaxOptions=array(),$htmlOptions=array())
{
if(!isset($htmlOptions['href']))
$htmlOptions['href']='#';
$ajaxOptions['url']=$url;
$htmlOptions['ajax']=$ajaxOptions;
self::clientChange('click',$htmlOptions);
return self::tag('a',$htmlOptions,$text);
}
As you see href comes from htmlOptions. The right code will be:
CHtml::ajaxLink("<img alt='".$data->text."'
src='".Yii::app()->assetManager->publish(Yii::app()->basePath."/images/".$data->img)."'
title='".$data->text."' height=100px width=100px/>",
'',
array(
"type" => "post",
"data" => "js:{ids:$.fn.yiiGridView.getSelection('chck-id')}",
"update" => "#grid"
),array(
'href'=>Yii::app()->createUrl('controller/action',array('id'=>$data->id))
));

Hope your other approach worked! But you could try repeating the link for both url and href like this.
echo CHtml::ajaxLink("<img alt='" . $data->text . "'
src='" . Yii::app()->assetManager->publish(Yii::app()->basePath . "/images/" . $data->img) . "'
title='" . $data->text . "' height=100px width=100px/>",
Yii::app()->createUrl('controller/action', array('id' => $data->id)),
array(
"type" => "post",
"data" => "js:{ids:$.fn.yiiGridView.getSelection('chck-id')}",
"update" => "#grid"
), array(
'href' => Yii::app()->createUrl('controller/action', array('id' => $data->id))
)
);

Related

shopware 6 upload multiple product variation images

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.

How to pass a variable set in Controller to Select Helper "value"?

I have something like this in my Controller:
$this->view->userTagsComma = ($skills[0] == 'No Skills Set')?'':'"' . implode('", "', $skills) . '"';
And this generates something like "Cooking", "Swimming" when I echo this in View.
And in my View I have:
<?php echo Phalcon\Tag::select(array('user-skills-input',
TagsStandard::find("status = 1"),
"using" => array("name", "name"),
"class" => "select-chosen",
"type" => "text",
"data-role" => "tagsinput",
"value" => [],
"multiple" => "multiple"
)); ?>
I want to pass $userTagsComma into [] in my select helper so how can I do it? I tried doing "view" => [$userTagsComma] in the select helper but it does not work.
Update: I tried putting in "value" => ["Cooking", "Swimming"], and this works. So not sure why passing in a variable with everything looking the same wouldn't work.
Try this!
$this->view->userTagsComma = $skills[0] == 'No Skills Set' ? array() : $skills;
Phalcon\Tag::select(array('user-skills-input',
TagsStandard::find("status = 1"),
"using" => array("name", "name"),
"class" => "select-chosen",
"type" => "text",
"data-role" => "tagsinput",
"value" => $userTagsComma,
"multiple" => "multiple"
));
Use this within Controller $this->view->userTagsComma = ($skills[0] == "No Skills Set") ? [] : $skills; instead of imploding as it is already an array.

Get images by custom field

I'm trying to display all images that have a certain custom field from the types plugin set to true. It would also work to filter them by post_content or post_excerpt but none of my attempts have worked so far.
<?
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_content' => 'foo',
'numberposts' => -1
);
?>
<? print_r(get_posts($args)); ?>
This get's all images allthough only one has the post_content foo. My attempt to use WP_Query failed miserably as well.
Any help is appreciated!
WP_Query method :
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'meta_query' => array(
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'LIKE',
),
),
);
$query = new WP_Query( $args );
I am presuming that the reason why you failed with WP_Query is due to the following condition.
Codex states : The default WP_Query sets 'post_status'=>'publish', but attachments default to 'post_status'=>'inherit' so you'll need to explicitly set post_status to 'inherit' or 'any' as well.
http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
get_posts method :
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'meta_key' => 'custom-field',
'meta_value' => 'custom value',
'numberposts' => -1
);
print_r(get_posts($args));
The only draw back with this method is that the meta_value needs to exactly match what was entered in the custom field. If you still like to use get_posts then use the meta_query as shown in WP_Query example above.

Dependent dropdownlist with chosen jquery plugin. Dynamic update

I'm new to yii so dont be strict.
I have dependent dropdown list with countries/states from model. It works perfect until comes Chosen jquery plugin.
I use http://harvesthq.github.com/chosen/.
So the problem is in howto trigger liszt:updated, so 2nd select can obtain data from standart select.
This is view code which makes that lists.
if ($field->varname=='country') {
echo $form->dropDownList($profile, $field->varname,CHtml::listData(Countries::model()->findAll(),'short','title'), array(
'class'=>"chzn-select",
'empty'=>"Select country",
'ajax' => array(
'type' => 'POST',
'url'=>$this->createUrl('registration/state'),
'update' => '#Profile_state',
'data'=>array('country'=>'js:this.value',),
)));
}
elseif($field->varname=='state') {
echo $form->dropDownList($profile, $field->varname,array(), array(
'empty'=>"Select state",
'class'=>"chzn-select",
));
Ok. I found the solution. Writing it here(maybe someone will find it usefull).
In our view file
echo $form->dropDownList($profile, $field->varname,CHtml::listData(Countries::model()->findAll(),'short','title'), array(
'class'=>"chzn-select",
'empty'=>"Select country",
'ajax' => array(
'type' => 'POST',
'url'=>$this->createUrl('registration/state'),
'update' => '#Profile_state',
'data'=>array('country'=>'js:this.value',),
'success'=> 'function(data) {
$("#Profile_state").empty();
$("#Profile_state").append(data);
$("#Profile_state").trigger("liszt:updated");
} ',
)));
Then in 2nd dropdownlist leve data empty:
echo $form->dropDownlist($profile, $field->varname, array(),array(
'class'=>"chzn-select",
'empty'=>"Select state",
));
Works perfect for me but gave me hours of research work.

ZF2 form element description

in ZF1 form and form elements had a setDescription method that was outputted as <p>description here</p> in view ....
ZF2 seems that doesn't have this method
so my question is how can i add description to form elements ?
this is my view :
<div>
<?
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
foreach ($form->getElements() as $el) {
?>
<div class="form_element">
<?=$this->formRow($el);?>
</div>
<?
}
echo $this->partial('system/form/buttons_form_part.phtml', array('form' => $form));
echo $this->form()->closeTag();
?>
</div>
Using ZF 2.1.5, one solution might be setOptions().
In the form definiton:
$file = new Element\File('file');
$file->setLabel('Photo (.jpg, .gif, .png)');
$file->setOptions(array('description' => 'test description'));
…
When rendering the form element:
$element = $form->get(…);
var_dump($element->getOptions());
Will give you access to:
array(1) { ["description"]=> string(16) "test description" }
If you mean a label for an Element you can use the setLabel method when you create the form (in Controller).
$name = new Element('name');
$name->setLabel('Your name');
Or if you use an array to create your form elements use this:
array(
'spec' => array(
'name' => 'name',
'options' => array(
'label' => 'Your name',
),
'attributes' => array(
'type' => 'text'
),
)
),
Here is a link:
enter link description here