I'm newbie in CakePHP and I have a few questions.
I'm trying to set up my first CakePHP website, and I want to display menu with links in my layout. I've created model called MenuItem, then I've created controller "MenuItemsController" and then a function show. When I access /menuitems/show/ all my links are displayed. So here's the problem. I want do call this controller in my layout so links will be visible on every subpage. First question is how to call this controller, and second how will output look like ? Do I have to create view for this cotroller if I don't want to use /menuitems/show/ or it's okay to set controller to output just array of data ?
Thank you!
First question is how to call this controller, and second how will output look like ?
Use requestAction() to request the data from the view OR better, set it based on the page you're on in your AppController::beforeFfilter() method.
In your layout simply use an element $this->element('menu'); and use the set data in it or, if you go for requestAction() do this call inside the element, you can even cache the element.
Read the links to the CakePHP book in the text, the book contains example code as well.
Related
I have some data that I need to pass to every website views in Odoo. The problem is that I don't know the proper way to do that. I have thought about manually add them to every render method, but it doesn't feel right for me. And it violated DRY, of course.
I am using Odoo 12. Thank for your help!!
every page of odoo call website.layout template (for header & footer) so you can place your data in layout template and it will available in every page
I am creating a dnn module. The content depends on the param in the url.
I want to be able to edit this content in the 'edit content' mode. However when i go to edit content the param in the url is no longer accessible because it is the parent document. How do i go about passing this value from the view.ascx to the edit.ascx?
Try storing the param in cookies or localstorage. Then you should be able to access it. Of course the user will be able to modify it but you can do a check that the user has not modified it by storing a server side encryption or somthing like that.
A workaround is to have a field where the user enters this parameter. But i know this isn't a very good solution. I am guessing that you will have to override the dotnetnuke core to do this (yes i know it sucks).
I hope I am understanding the question properly.
To pass parameters from your View to Edit controls, you should first make sure they are registered properly in the module definition. You default View should have an empty controlkey and your Edit should be registered with a control key, for example "addedit".
When creating a link between your view control and edit control, use the EditUrl() method of PortalModuleBase. When passing a parameter, for example an id of the item you want to load into your edit control, you can pass them as arguments in the EditUr method.
Example (in my view.ascx.cs):
lnkEdit.NavigateUrl = EditUrl("id", "16", "addedit");
This will assign a module view link to the edit.ascx (assuming the controlkey in the definition is addedit) passing in a url parameter "id" with value 16.
See my DNN Module Views tutorial for a complete lesson on how to do DNN module views and navigation.
http://www.dnnhero.com/Premium/Tutorial/tabid/259/ArticleID/204/Introduction-and-Module-Definition-basics-in-DNN-Part-1-6.aspx
I am using MVC 4 with some Kendo UI and I am new to both.
What I need is for my Kendo grid to redirect to another page when a row is clicked.
My initial thought was to create a function within the script section of the view that the grid is on and that function would call the other view that I need. However, I am not sure if this is possible because I believe the view is supposed to be separate from the controller.
I think that I need to somehow make all of this be able to work from within the controller but I am not sure how to get started.
Use #Ajax.ActionLink to call controller and receive partialView
If you are doing a post action you can use RedirectToAction() in your controller. If you need to change the window in JavaScript see below.
window.location.href = "#Url.Action("(Action)","(Controller)",new {id= (params)})";
I am confused when I should use a custom widget or renderPartial in my view files. Sometimes I use widget and sometimes I use renderPartial.
Widget
You use widget when your application logic is defined in a separate CLASS file and the logic is somehow separated and standalone.
Widget's are chosen when the functionality is repeatedly used elsewhere, on lot of pages.
renderPartial
You use renderPartial for VIEW files that you want to embed into something bigger, or when you want to print something without using the application layouts.
renderPartial is chosen when all the variables it need to access are already prepared in the current action.
Widget
You can use widget when your site has some common part like header and footer or sometime some kind filter which require on every page of site.
renderPartial
Take example of search form of yii crude which is called by using renderPartial because that serach form is changing according to requirement of pages.
Sorry for english.
I have a filter that is used to populate a grid view and the url will conain: /example/grid?value1=1&value2=2
It will then have a link to page 2, which allows them to edit something.
I then want them to click a link that will send them back to the gridview under the same parameters of: /example/grid?value1=1&value2=2
Is this possible? How do I hold on and fill in the URL values so it knows how to refill the grid view accordingly??
Thank you!!
Well since you're using MVC, you should add parameters to your Grid controller that allow you to pass in parameters, then the url would look like this:
/example/grid/1/2
Then in your code you just need to read the parameters while you're filling the grid and apply the appropriate logic.