Implementing a menu's "selected" links in Yii - yii

I have two templates to integrate into yii - my front end website and my CMS.
My front end website has top menu that is generated by CMS (database)
CMS top menu which is static menu by me. ("Manage pages", "Manage users", "Manage products") although this menu is static I still want to assign a selected class to the appropriate top menu item.
Eg: If I'm managing some pages on the site the "Mange pages" link should be highlighted and selected. How would I go about this? Something I need to code myself or is there a existing function in yii that i need to refer to?
Thanks in advance
Yii newbie

What I do is have multiple "menu" functions in my Controller (AdminController extends Controller) class. Each one builds the array the CMenu needs, and I set the active one based on what I passed in to the function. For instance:
protected function getAdminMenu($activeTitle) {
return array(
array('label'=>'Manage pages', 'url'=>array('/user/purchase'),'active'=>($activeTitle=='Manage pages')?true:false),
array('label'=>'Manage users', 'url'=>array('/user/index'),'active'=>($activeTitle=='Manage users')?true:false),
);
}
You could do this where it looks like the Controller or Action or URL request and sets the appropriate menu item active as well. This is just an example.
Then in my view, if I want to render the menu with "Manage pages" active, I set my layout's Menu using the function in my Controller class:
$this->menu=$this->getAdminMenu('Manage pages');
(This assumes that you have public $menu=array(); declared in your Controller, and as well. Look at the Blog example to see how this works:
$this->widget('zii.widgets.CMenu', array(
'items'=>$this->menu,
));
)
I hope this gives you some direction!

Make a css class that changes the background of the object to highlight it.
In your views for the various pages just make the menu item have that particular class.

Related

Integrate search bar (like in product controller for packs) in custom module controller

I'm facing an issue when I'm try to integrate the same search bar as the one in product controller for product packs.
(this one)
I've been scrolling through the whole product controller but didn't find where the search bar is rendered.
I found few parts nearly related of the input in product.js, but nothing really interesting.
What I'm trying to do is implement the same search bar with product suggestions, I will find out later how to "save" it like in product controller when you create a pack.
Backoffice product page had been migrated in Symfony, form is built in a twig template inside:
src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/essentials.html.twig
src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
While JS handler is here :
admin/themes/new-theme/js/product-page/product-search-autocomplete.js

Prestashop 1.6: how to load a different template after an admin form submission?

I'm new to Prestashop and currently working on a custom admin module in 1.6.
My scenario is, users can load orders to this module/admin controller and from the list they can select which ever order they like using 'Select All' checkbox selector.
And then these selected order ids are submitted back to admin controller to be displayed on a different template with full information in a form.
And then again this form will be submitted to a third party API for further processing.
Now my problem is I can get the order listing to my admin controller and get them submitted back to the same controller. But I do not know how to switch to a different template to display in a form.
And also how to call a different method to process and export once second form substitution is done.
Any advice would be greatly appreciated.
Thanks in advance
Roshan
In your AdminController extend the method initContent with a condition that is you need to check if a certain button was pressed. Something like
public function initContent()
{
if (Tools::isSubmit('the_button')) {
'do what you want to do'
}
parent::initContent();
}
if you want to redirect to a different controller use Tools::redirectAdmin() and set the path of redirection like Context::getContext()->link->getAdminLink('your_another_controller', true), also you can send all necessary data with the third parameter of the method(array)
public function initContent()
{
if (Tools::isSubmit('the_button')) {
Tools::redirectAdmin(
Context::getContext()->link->getAdminLink('your_another_controller', true, $orders)
);
}
parent::initContent();
}
You can use as many conditions, inside the method, as you need so I hope it will help you in all your cases.

Calling Navigation Menu from Master class in the Default Page

I have my navigation menu declared in the master class. I want to use it in the Default page but for some reason is not picking it up! Just to note the menu items are declared in the SiteMap file!
Here is the Master class menu I am trying to call:
<asp:Menu ID="NavigationSiteMapMenu" runat="server" CssClass="menu"
Orientation="Horizontal" DataSourceID="SiteMapDataSource1">
Here is the code I am using it in Default Page (In the Page Load Method) :
Dim testMenu As Menu = CType(Master.FindControl("NavigationSiteMapMenu"), Menu)
And here I am testing if it returns list of items but it doesn't the count is 0.
Dim test = testMenu.Items
Do you guys have any idea why my above code is not working, the logic seems perfect to me but clearly not to VB.NET!
This is the correct syntax:
Dim testMenu As Menu = CType(Master.FindControl("NavigationSiteMapMenu"), Menu)
My problem was that on one of the aspx pages I wasn't referencing the Master page. So please make sure the Master Page is referenced in all the required pages.
All the best and Good Luck!

MVC4 Dynamic Menu Generation

I want to generate menu from database for that I have implemented my logic and its responding well, the issue is that I am unable to render menu from my controller method. I want to ask if its possible to return HTML from action controller method and render it on my view by using Html.Action("MenuGenerator","Menu") but I am unable to achieve this. Moreover I donot want to create partial view for menu since my method returns menu as html string and I just want to flush it out to the view.
Html.Action is a basic helper method. All it does is return a MVCHtmlString. You will have to create your own helper extension that returns your custom HTML to build your menu.

SharePoint: Programmatically moving pages and subsites on the current navigation menu

Does anyone know how to programmatically move/order the pages and subsites that appear in the Current Navigation when you have the Include subsites and include pages options ticked/enabled?
Background
I have written a class (in c#) which imports content into a new SharePoint site. The newly created subsites and pages all show on the Current Navigation menu as expected, but in the order they were created (I assume). I need to manually sort the pages on the menu so that they appear in the same order as the existing non-SharePoint site.
Issue
The PublishingWeb.Navigation.CurrentNavigationNodes collection does not contain any SPNavigationNode items for the pages and subsites that are automatically displayed on the Current Navigation menu, so I can't use this collection.
I know that to hide a particular page from the menu, you have to update a web property as follows:
web.AllProperties["__CurrentNavigationExcludes"] += page.UniqueId.ToString() + ";";
web.Update();
Is there something similar I can use to order the pages?
Set the Ordering to manual
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.orderingmethod.aspx
Check out the follow up article on this: http://www.thekickboard.com/archive/2010/09/01/programmatically-setting-navigation-order-in-a-moss-publishing-site.aspx
Is this sort of what you are looking for:
http://www.thekickboard.com/archive/2010/09/01/programmatically-setting-navigation-order-in-a-moss-publishing-site.aspx