I am looking for a way to get the PATH for a view and use it in a href.
For the rest of the links in my .tpl files i use something simillar to:
print url('node/36');
How can i mimic this behaviour for the views module? I want to be able to edit the path for the view from the admin interface without requiring to modify the theme.
Thank you.
Edit view path by php code:
$view = views_get_view($view_name, TRUE);
$view->display['page']->display_options['path'] = $new_path;
views_save_view($view);
Try this
function get_path() {
if (!empty($this->override_path)) {
return $this->override_path;
}
if (empty($this->display_handler)) {
if (!$this->set_display('default')) {
return FALSE;
}
}
return $this->display_handler->get_path();
}
Related
I am creating a module which will allow me to save HTML content in the settings section of the DNN module which will be stored on the Portal Settings.
How do I ensure my setting is unique only for the current container it is placed on? How can I get the ID of the current div the module is placed on?
Then I would be able to place the module in the exact same place. For example the Header and Footer section of the website.
So, if I can get ParentDivID and then append it at the end of the settings key.
For example: if (dictSettings.ContainsKey("GlobalHTML" + ParentDivID))
This is my current code for the DNN module Settings Codebehind
if (Page.IsPostBack == false)
{
//Updated to use Portal Settings instead of per page per tab settings
var dictSettings = m_PortalController.GetPortalSettings(PortalId);
if (dictSettings.ContainsKey("GlobalHTML"))
{
txtGlobalHTML.Text = dictSettings["GlobalHTML"];
}
}
You normally store store module settings in the ModuleSettings table of the ModuleController.
var modules = new ModuleController();
modules.UpdateTabModuleSetting(TabModuleId, "SettingKey", "SettingValue");
But for HTML I would create a custom table that stores the HTML with a Primary Key and a TabModuleId column.
I have figured out a way to add the same module to the page on a particular portal and have the content that is already saved in the settings to be linked with the use of an ID which I can set.
So if I want the same telephone number on multiple pages or footer content, then I can leave the HTML field in the settings section empty and just make the ID the same as the one I have initially configured with HTML content.
This is the code for when the module settings loads:
if (Page.IsPostBack == false)
{
per tab settings
var dictSettings = m_PortalController.GetPortalSettings(PortalId);
if (Settings.Contains("GlobalIDHTML"))
{
txtIDGlobalHTML.Text = Settings["GlobalIDHTML"].ToString();
LinkID = Settings["GlobalIDHTML"].ToString();
}
if (dictSettings.ContainsKey("GlobalHTML"+ LinkID))
{
txtGlobalHTML.Text = dictSettings["GlobalHTML"+ LinkID];
}
}
This is the code for Updating the settings:
public override void UpdateSettings()
{
try
{
var modules = new ModuleController();
modules.UpdateModuleSetting(ModuleId, "GlobalIDHTML", txtIDGlobalHTML.Text);
modules.UpdateTabModuleSetting(TabModuleId, "GlobalIDHTML", txtIDGlobalHTML.Text);
var globalstoragevalue = "GlobalHTML"+ txtIDGlobalHTML.Text;
if (txtGlobalHTML.Text != null && !string.IsNullOrWhiteSpace(txtGlobalHTML.Text))
{
PortalController.UpdatePortalSetting(PortalId, globalstoragevalue, txtGlobalHTML.Text);
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
My code when the page loads:
try
{
if (Settings["GlobalIDHTML"] != null && !string.IsNullOrWhiteSpace(Settings["GlobalIDHTML"].ToString()))
{
GlobalLinkID = Settings["GlobalIDHTML"].ToString();
}
GlobalContent = TryGetPortalSetting("GlobalHTML"+ GlobalLinkID);
if (GlobalContent != null)
{
GlobalPageContent = GlobalContent;
}
}
The module settings:
The result:
I would look at how the HTML module does this ...
Given my code:
oneFunctionInController() {
$state.go('newState')
anotherFunctionInController()
}
anotherFunctionInController() {
let url = $location.url()
//do something based on url
}
the problem is that when anotherFunctionInController() is executed, the url I get is still the old url, not "newState"
what is the reason? any solution? thanks
Try this,
oneFunctionInController() {
$state.go('newState').then(function(){
anotherFunctionInController();
});
}
I've read this post, but I don't like having browserHistory.push('/some/path') in one of my components while I have <Route path="/some/path" component={SomePage} /> in my router file since the path is duplicated. What if I want to change that path to /another/path? Now I need to remember to update it in the router file and also my component.
Is there a better way around this? I was thinking that I could have "/some/path" and all my other paths defined in some constants file that gets imported and referenced in my router and my component. Example:
paths.js
var Paths = {
myPath: "/some/path",
...
}
module.exports = Paths
router.jsx
var Paths = require('constants/paths');
...
<Route path={Paths.myPath} component={SomePage} />
component.jsx
var Paths = require('constants/paths');
...
browserhistory.push(Paths.myPath)
This seems like it could get a little messy when dealing with URL parameters like /some/path/:id, so I was hoping there might be a better way.
This is what I have done in the past for routing to make it simpler / more streamlined.
(as a side note i used lodash here so if you aren't you can use native functions to do basically the same thing. lodash just adds a bunch of nice features / functions that you dont need to go write yourself)
in my routes.jsx file you should create functions that convert any parameters into a url with a default path for this answer lets just make one for a profile route
export function pathToProfile(userName, params) {
return path(Paths.PROFILE, _.assign({userName}, params));
}
the path() function is just a simple helper utility function for generating a path.
path(url, params, urlMap) {
if(!url) {
console.error("URL is not defined for action: ", params);
}
if(!params)
return url;
params = _.merge({}, params);
if(urlMap) {
_.keys(urlMap).forEach((k) => {
params[urlMap[k]] = params[k];
delete params[k];
});
}
if(url.indexOf(":") !== -1) {
url.match(/:([0-9_a-z]+)/gi).forEach((match)=>{
var key = match.replace(":", "");
url = url.replace(match, params[key]);
params = _.omit(params, key);
});
}
if(_.keys(params).length > 0) {
url = url + "?" + this.paramsToString(params);
}
return url;
}
now looking at the constants file
Paths {
PROFILE: '/user/:username',
}
Finally usage.
I wouldn't recommend broswerHistory.push() when you can have an onClick handler. Yes it works and will redirect, but is it the best thing to use? react-router also has a Link that should be used wherever possible. you get some nice additional features one for example would be an active route for whatever page you're on.
browserHistory.push() is a good way to handle redirecting when you do things like an auth login redirect or if you are responding to data from a request and conditionally taking them to a page.
<Route path={Paths.PROFILE} component={Profile} />
<Link to={pathToProfile(this.props.user.username, {myParams: 'here'})></Link>
what that would be translated into if you wanted to see the url from that exact link it would be /user/someUsername?myParams=here
This document shows how to assign layout for error:
$this->layout = 'my_error';
http://book.cakephp.org/3.0/en/development/errors.html#exception-renderer
But i've 2 different layouts for frontend and backend. When NotFoundException is thrown, i want to assign different layout accordingly.
How can i do that? Please help me.
Just check appropriate criteria and set layout accordingly in your template. For e.g.
if ($this->request->param('prefix') === 'admin') {
$this->layout = 'admin';
} else {
$this->layout = 'default';
}
As #ADmad suggest.
Do check the request to identify frontend or backend inside error400.ctp file (you may have another error file, just is a example).
In my case use admin prefix, i did like this:
if (!empty($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin') {
$this->layout = 'Admin/default';
$app = [
'App.imageBaseUrl' => 'admin/img/',
'App.cssBaseUrl' => 'admin/css/',
'App.jsBaseUrl' => 'admin/js/'];
Configure::write($app);
} else {
$this->layout = 'Frontend/default';
}
If you want to re-set layout you have to re-render the action, a redirect would be the most easy solution here. You could also use an AppView.
$view = new AppView();
$view->set($variables);
$view->render();
http://book.cakephp.org/3.0/en/views.html#the-app-view
How can I get the parameter in the URL and save it to a varialble so I can save it to my database?
example: www.mydomain.com/item/products/3 <-
This is for my upload image, so I can specify what product ID will I use for that image.
function add() {
if ($this->request->is('post')) {
$this->Upload->create();
if(empty($this->data['Upload']['image']['name'])) {
unset($this->request->data['Upload']['image']);
}
if(!empty($this->data['Upload']['image']['name'])) {
$filename = $this->request->data['Upload']['image']['name'];
$new_filename = STring::uuid().'-'.$filename;
$file_tmp_name = $this->request->data['Upload']['image']['tmp_name'];
$dir = WWW_ROOT.'img'.DS.'uploads';
move_uploaded_file($file_tmp_name,$dir.DS.$new_filename);
$this->request->data['Upload']['image'] = $new_filename;
if($this->Upload->save($this->request->data)) {
$this->Session->setFlash(__('Uploaded.'));
$this->redirect(array('action' => 'index'));
}
}
}
}
How will I add it here. Thank you in advance :)
Im using cakePHP
Just add the product id as a hidden input in the Form.
Then it will be included in the $this->data variable when you get the POST request.
For example in a controller method like the following
public function product($id) {
.....
}
You access it by the url (for example): www.mydomain.com/item/products/3 where Item is the controller, product is the method you are calling in that controller and 3 represent a parameter that is required to the function to work in this case $id. (assuming you don't have any routing configuration)
Is treated as a normal php variable, just do whatever you wanna do with it. Just make sure you pass the correct value