I have an array, Vehicles, "id" and "vehicle", like this database table:
Vehicles
1.Car
2.Truck
3.Bicycle
4.Motorcycle
I make a model of the table, and CRUD it, I am given this generated code in vehicle/index:
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return Html::a(Html::encode($model->vehicle), ['view', 'id' => $model->id]);
},
]) ?>
I see now a list with all my vehicles as links:
Car,
Truck,
Bicycle,
Motorcycle
What I want, is the links to get me somewhere, like this:
Car - vehicles/car,
Truck - vehicles/truck
...etc
I will have to hard-code the paths, I guess.
Is there a convenient way to do this, in the Html::a function given above?
Or should I use another type of function?
You can use the urlManager
return Html::a(Html::encode($model->vehicle),
['/your-controller/your-action', 'id' => $model->id]);
assuming your controller is name vehicle and in $model->name you have car, or Trukck ...
return Html::a(Html::encode($model->vehicle),
['/vehicle/'. $model->name, 'id' => $model->id]);
Related
I would like to display categories in posts and in post excepts, however I would alo like to use categories that help organise the display of posts around the site but are not visible.
For example a 'featured' category that may be applied to a range of posts in unconnected categories, but that are the most valuable posts to show in a particular area. I don't want the category 'featured' to show to the user.
you're looking at custom taxonomies. Custom taxonomies can be applied to multiple posts. You can control their behaviour by using arguments.
CTs looks somewhat like that and are declared in your function.php file
<?php
/**
* Add CT to CPT
*/
add_action( 'init', 'custom_taxonomy_langues' );
function custom_taxonomy_langues() {
$taxonomy = '_related_CPT_goes_here';
$singular = '_CT_singular_name';
$plural = '_CT_plural_name';
$labels = array(
'name' => $plural,
'singular_name' => $singular,
);
$args = array(
'labels' => $labels,
'description' => '',
'hierarchical' => 1,
'public' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => array( 'slug' => strtolower( $plural ), 'hierarchical' => 1 ),
);
register_taxonomy( strtolower( $plural ), strtolower( $taxonomy ), $args );
}; ?>
As you can see you can control pretty every regarding the behaviour, can you query them, do they have an archive page, do you want them to show up in the admin ui, if so where ... etc
A bunch of article already exist, you can take a look at this one https://wordpress.stackexchange.com/questions/92430/can-multiple-custom-post-types-share-a-custom-taxonomy in regards to connecting multiple CPTs to a single CT.
Use a custom taxonomy instead.One can specify that they are not public, but still use them for querying and grouping. https://developer.wordpress.org/reference/functions/register_taxonomy/
I am trying to understand how to use the setSearchFilter function in the Priority Web SDK. I can run formStart() followed by form.getRows(1) to get the entire form, but I only need ~5 of the over 100 rows.
login(configuration)
.then(() => formStart('ORDERS', null, null, 'demo',1))
.then(form => form.setSearchFilter({
or: 0,
ignorecase: 1,
QueryValues: [{
field: 'TOTPRICE',
fromval: '100',
op: '>'
}]
}))
.then(filter => filter.getRows(1))
.then(rows => console.log(rows))
.catch(err => console.log(err));
If I comment out the then-setSearchFilter line, I get the entire form. With it in, I get filter undefined.
This is for a phone app so how much data I download seems important.
As you can see in the documentation setSearchFilter doesn't return a filter object. After defining the filter each call to getRows will return rows according to the filter. You should call it like this: form.getRows not filter.getRows.
In addition, when defining a Filter you must define all of its members.
I have read some articles about yii2 dynamic-form and javascript function. The solution given by InsaneSkull is perfect. But i have one question.
example :
i'm using dynamic-form from wbraganca and trying to call function onchange event (javascript). My code like this
<?= $form->field($detail, "[{$i}]qty")->widget(\yii\widgets\MaskedInput::className(),
[
'clientOptions' => [
'alias' => 'numeric',
'groupSeparator' => ',',
'digits' => 0,
'autoGroup' => true,
'removeMaskOnSubmit' => true,
'rightAlign' => false,
],
'options' => [
'class' => 'form-control',
'onchange' => 'Info($(this))',
]
]) ?>
First, i try to register Info function like below
<?php
$script = <<< JS
function Info(item){
var index = item.attr("id").replace(/[^0-9.]/g, "");
alert(index);
};
JS;
$this->registerJs($script);
?>
It gave error because Info function not defined yet.
Second, I registered in AppAsset and it worked.
My question : what is the differences? *(I think it was the scope).
How to define the function beside register in AppAsset ?
Where dou you register above script? If in view after use widget, default position at which JS is register is POS_READY public void registerJs ( $js, $position = self::POS_READY, $key = null ) Try to use position POS_BEGIN or POS_HEAD if you want to put the script after use widget. Otherwise You can override widget class and put this script into init method of the widget which is execute before run method rendered widget.
I'm Vue.js newbie and my task is:
make an ajax call (GET) to server, using RESTful API (Laravel on background)
retrieve a (JSON) list of Form CRUD items in array (like checkbox, input text, textarea...) with their properties (value, checked, custom classes...)
render CRUD form with these form items maybe using Vue's loop
I'm wondering if it could be rendered using components somehow. But I don't know the correct way.
Frankly, I exactly don't know how to solve this problem with Vue.js - rendering items from array and each item has it's own markup and properties (checkbox has it's own, textbox, select, textarea...).
I'm building a web application based on CRUD operations and I'm trying to write universal components. The easiest way is to do a special component with hard-written sub-components for each subpage, but I don't like this way if not needed.
Thank you!
EDIT: I don't have much code yet, but this is where I am...
<script>
// ./components/CrutList.vue
export default {
mounted() {},
data() {
return {
items: []
}
},
props: ['resource'],
methods: {
getItems() {
var resource = this.$resource('api/'+this.resource+'{/id}');
resource.get({}).then(function(items){
if(items.body.status == 'success'){
this.items = items.body.items;
}
}).bind(this);
},
deleteItem(item) {
// perform CRUD operation DELETE
alert('delete action');
}
}
}
</script>
My idea is using CrudList component to CRUD listing...
<crud-list resource="orders">
In laravel I do something like this:
return response()->json([
'status' => 'success',
'items' => [
[
'itemComponent' => 'checkbox',
'props' => [
'checked' => true,
'label' => "Checkbox č.1",
'name' => 'checkbox1'
]
],
[
'itemComponent' => 'checkbox',
'props' => [
'checked' => true,
'label' => "Checkbox č.2",
'name' => 'checkbox2'
]
],
[
'itemComponent' => 'checkbox',
'props' => [
'checked' => true,
'name' => 'checkbox3'
]
],
],
]);
...it's very simplified, but it's just example of what I'm doing.
Now the problem is:
take the 'itemComponent' part from the returned array item (this is in a loop),
if it's a checkbox, take (for example) Checkbox.vue component, fill it with properties ('props' part of the array item)
I read about slots, but it's not what I'm looking for. Is there something I can use for dynamic components?
Check out this jsFiddle working example for dynamic forms:
https://jsfiddle.net/mani04/kr8w4n73/1/
You can do it easily by using a lot of v-ifs for each and every form element type you might get from server. It is a bit cumbersome but I can't find any other way.
In the above example, I have the form structure as follows:
var formItems = [{
input_type: "text",
input_label: "Login",
values: {
value: "your_name#example.com"
}
},
{...},
{...}];
Once you have that data, then it is a matter of iterating through formItems, checking input_type and activating the relevant form control.
Here is how my dynamic form template looks like, for the above input:
<div v-for="formItem in formValues">
<div v-if="formItem.input_type == 'text'">
<input type="text" v-model="formItem.values.value">
</div>
<div v-if="formItem.input_type == 'password'">
<input type="password" v-model="formItem.values.value">
</div>
<div v-if="formItem.input_type == 'checkbox'">
<input type="checkbox" v-model="formItem.values.checked">
{{formItem.values.label}}
</div>
</div>
My jsFiddle example uses form-horizontal from bootstrap, and I am also able to display the labels well. If I put that in the example above, it will get cluttered and will not let you see how it works.
Hope it helps! You can change the formItems data structure to meet your needs, and modify the template accordingly.
I've had a look through the forum already, but can't seem to find an answer for my specific problem.
So, I've installed a third party 'store locator' plugin on my Magento store but I keep getting a js error message about MissingKeyMapError. I've already applied for an API key - but my problem is I'm not sure where in the code I should put this key.
API Key
I'm in Googlemap.php in the app folder for this particular plugin and I think it should go in here somewhere but not entirely sure.
This is what's contained in Googlemap.php:
class Clarion_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Googlemap extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$model = Mage::registry('storelocator_data');
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('form_General_Googlemap', array('legend'=>Mage::helper('clarion_storelocator')->__('Google Map')));
$radiusConfigValue = Mage::getStoreConfig('clarion_storelocator_general_setting/clarion_storelocator_display_setting/default_radius');
$fieldset->addField('radius', 'text', array(
'label' => Mage::helper('clarion_storelocator')->__('Radius'),
'note' => Mage::helper('clarion_storelocator')->__('Radius is in miles. If kept blank then default configured radius will be used (System > Configuration > Store Locator)'),
'name' => 'radius',
'value' => $radiusConfigValue,
));
$fieldset->addField('latitude', 'text', array(
'label' => Mage::helper('clarion_storelocator')->__('Latitude'),
'class' => 'validate-number',
'required' => true,
'name' => 'latitude',
));
$fieldset->addField('longitude', 'text', array(
'label' => Mage::helper('clarion_storelocator')->__('Longitude'),
'class' => 'validate-number',
'required' => true,
'name' => 'longitude',
));
$zoomLevelConfigValue = Mage::getStoreConfig('clarion_storelocator_general_setting/clarion_storelocator_display_setting/zoom_level');
$fieldset->addField('zoom_level', 'text', array(
'label' => Mage::helper('clarion_storelocator')->__('Zoom Level '),
'note' => Mage::helper('clarion_storelocator')->__('If kept blank then default configured zoom level will be used (System > Configuration > Store Locator)'),
'name' => 'zoom_level',
'value' => $zoomLevelConfigValue,
));
$data = $model->getData();
if(!empty($data)) {
$form->setValues($data);
}
return parent::_prepareForm();
}
}**
Any help/suggestions would be much appreciated!
Thanks in advance,
Letitia
I also had same issue with this extension just find the xml file under your theme layout mainly named with clarion_storelocator.xml in this find google api path under script tag in line no #32 replace with src="//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=YOUR_API_KEY" async="" defer="defer" type="text/javascript"> under script tag
Remember to put your api key.
Enjoy Coding :)