I am using the Yii2 Menu widget. This is my menu
echo Menu::widget([
'items' => [
'label' => 'Products',
'url' => '/products' // Not working.
'items' => [
[
'label' => 'New Products',
'url' => '/new-products'
]
]
]
]);
But the URL /products doesn't work when the user click Products, then the menu must be open (it works) and also open the URL /products (it doesn't work).
When specifying the URLs for the menu items you have to specify them
in the form of controller/action not just as /controller even if
the default action is used.
This is written on the top as a Note in the class reference yii-widgets-menu in the very first example code under comments.
So change your url for the Products item to
'url' => '/products/index'
and also for the new-products
'url' => '/products/new-products'
Hope it helps.
Note: when you specify URLs like /controller/action it will add it to the baseUrl or domain name removing everything after that.
Like if you have a domain http://example.com and you are on the page http://example.com/contact-us.
It will replace everything after the domain name and add your specified http://example.com/controller/action and if the menu item URL is provided like controller/action then clicking it will append it to the existing URL http://example.com/contact-us/controller/action.
You can't really expect that clicking "product" item will open submenu and redirect to /products page at the same. It does not make any sense, since you will be redirected to different page before you will have a chance to click something in submenu. That's why clicking on "products" only shows submenu dropdown. But this link actually works - try use middle mouse button or disable javascript in your browser.
In your case you should probably define your menu as:
echo Menu::widget([
'items' => [
'label' => 'Products',
'url' => '/products'
'items' => [
[
'label' => 'All Products',
'url' => '/products'
],
[
'label' => 'New Products',
'url' => '/new-products'
],
]
]
]);
All navigation links should be in submenu.
Related
'm working on a global site search ( autocomplete ), right now it have almost all entries ( that have uri defined ) for results, it uses js fetch and Craft element api in a json file that filter results based on a query string. Works great!
I was wondering if it's possible to add to the query categories too, i don't know if this is possible buy maybe it's a way to merge them, here is my json api code, thanks!
'search.json' => function() {
$qParam = Craft::$app->request->getParam('q');
return [
'elementType' => Entry::class,
'paginate' => false,
'criteria' => [
'uri'=> ':notempty:',
'search' => $qParam,
'orderBy' => 'score',
'limit' => 20,
],
'cache' => false,
'transformer' => function(Entry $item) {
return [
'title' => $item->title,
'url' => $item->url,
];
},
];
}
I have bodytext and image so like this type of list where can I found? Can I get page list in select box?
$GLOBALS['TCA']['tt_content']['types']['text_image_left'] = [
'showitem' => '
--palette--;palette.general;general,
header, subheader, header_layout,menu,
bodytext;bodytext_formlabel,
--div--;tabs.images,
image,
--div--;tabs.appearance,
--palette--;palette.frames;frames,
--div--;tabs.access,
hidden;field.default.hidden,
--div--;tabs.extended
',
'columnsOverrides' => ['bodytext' => ['config' => ['enableRichtext' => true]]]
];
Hm, not sure if I get your question right. You asked
1. for a list of TCA types
2. how to get a list of pages in a select field (?)
You can find the complete TCA Documentation here:
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/
Interesting part for you is the [column][*][config] part:
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Index.html
In order to create a select with a page list, you need following kind of configuration.
I would suggest to use "group" type for field.
'page' => [
'exclude' => true,
'label' => 'List of Pages',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'pages',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
]
]
I use an ActiveForm in yii2. After click on submit button I have a following GET request. How can I add the custom attributes to 'ProjectSearch' array before submition?
$_GET = [
'r' => 'project/index',
'ProjectSearch' => [
'description_' => '',
'categories' => '',
'moneyrange' => '5,50',
],
'sort' => '-price',
];
You should look into yii.activeform.js in order to know more about the events which can help you to do the above mentioned task. Like here you can use before submit:
$('#contact-form').on('beforeSubmit', function (e) {
//Add your part of code!
}
return true;
});
I create small site with Yii2 basic, and I have problem, I search every times and not resolved this, I try rewrite with .htaccess file but not success.
My site have more category get from database example: house-building, car, job, computer, travel.....
I would like user click on category example: http://example.com/house-building => it access category/index?category=house-building
Current, my config/web.php as bellow.
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
#'suffix'=>'.html',
'rules' => array(
''=>'site/index',
'/login.html'=>'/users/login',
'/register.html'=>'/users/create',
### End custom url
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
Can you help me resolved this issues.
Thanks you.
Use this rule:
'<category:\w+>' => 'category/index'
I developing magneto module, In this module i want to make a ajax request in admin panel.I don't understand were to add script and controllers.please help me.
My requirement:
When change the select box(On change) i want add some field in the form.
Mycode:
/app/code/local/<Namespace>/<Module>/Block/Adminhtml/<Module>/Edit/Tab/Form.php
$fieldset->addField('type', 'select', array(
'label' => Mage::helper('<Module>')->__('Article Type'),
'name' => 'status',
'values' => array(
array(
'value' => '',
'label' => Mage::helper('<Module>')->__('Choose'),
),
array(
'value' => 1,
'label' => Mage::helper('<Module>')->__('Normal'),
),
array(
'value' => 2,
'label' => Mage::helper('<Module>')->__('video'),
),
),
'required' => true
));
I am creating fields using this.
How can i add another field on change.
Where should i add script
Where should i add controller
I created this module using this instructions
Let this field always be on the form. But make it invisible and show when you need it.
In the same template where the form is.
Place controller in your module. On stackoverflow you can find many questions about creating your own magento module and controller.