If I want to display sidemenu only on affiliates page (affiliates.php) than I'm enclosing code in:
if (App::getCurrentFilename() == 'affiliates'){
}
But how to do same for page index.php?m=somepage ?
You can use the php builtin variables to get the URI, however if you want to use the application object to fetch a specific argument you could do something like:
$whmcs = App::self();
$module = $whmcs->get_req_var('m');
Related
When I set #Url.PageLink("Project") on a page it generates a link like "http://localhost:5236/Project". But when I set the route parameter in the "Project.cshtml" page like:
#page "{id}", link #Url.PageLink("Project") returns "http://localhost:5236/?page=%2FProject".
I can't understand why. How it works?
How to generate a relative path with a parameter that is set in javascript.
Like:
a.href = '#Url.PageLink("Project")'+'/123';
If you want to add a parameter to url in js,you can try to use Url.Page():
a.href= '#Url.Page("Project")'+'/123';
I am trying to save the HTTP_REFERER to a $_SESSION[] variable and only updating it if the referring page does not match the current page. This way if I reload the page through a PHP script it does not save the current page I'm on as the referrer.
First I am getting the REFERER and comparing it to the current URL:
$referer = $_SERVER["HTTP_REFERER"];
preg_match('/^(.*?\:\/\/)/', $referer, $start);
$url = $start[0].$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
Then I have an IF statement that says if they DONT match to update Session:
if($url != $referer){
$_SESSION['referer'] = $_SERVER["HTTP_REFERER"];
}
Then I check the output:
echo $_SESSION['referer'];
The issue is that it updates the session no matter what!
I have tried to do the same with cookies instead of the session variable. With cookies, I can see it changing in the consol. It won't update, and then a second later it updates. Almost as if the page is loading twice.
When I set this code
setcookie('test', $_SERVER["HTTP_REFERER"]);
When I go to a new page, it will correctly display the correct refer, and then after a second, it switches to the current page.
My current setup uses .htaccess so that I don't have to type the file names of the pages. I have all requests of any subfolders go to /index.php
So http://example.com/home or http://example.com/coolpage will all go back to http://example.com/index.php
Then with PHP I look for the file named the same as that subfolder and then "include" it in my index.php file as a sort of simple templating system.
Are these .htaccess redirects messing with the $_SERVER["HTTP_REFERER"]? If I just use the $_SERVER["HTTP_REFERER"] directly within my code it works fine (it's not updating). It's only when I try to save it to another variable that things go wonky.
Is there a better way to have a back button that sends the user back to where they came from without taking into account multiple page loads of the same URI?
I found a workaround that seems a bit odd, but it achieves the effect I want.
I wrap the whole thing in an if statement only executing if the $uri != favicon.ico
if($uri != 'favicon.ico'){
$referer = $_SERVER["HTTP_REFERER"];
preg_match('/^(.*?\:\/\/)/', $referer, $start);
$url = $start[0].$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($url != $referer){
$_SESSION['referer'] = $_SERVER["HTTP_REFERER"];
}
$backButton = $_SESSION['referer'];
}
Let's say I want to get a zip file (and then extract it) from a specific URL.
I want to be able to use a wildcard character in the URL like this:
https://www.urlgoeshere.domain/+*+-one.zip
instead of this:
https://www.urlgoeshere.domain/two-one.zip
Here's an example of the code I'm using (URL is contrived):
import requests, zipfile, io
year='2016'
monthnum='01'
month='Jan'
zip_file_url='https://www.urlgoeshere.domain/two-one.zip'
r = requests.get(zip_file_url, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall()
Thanks in advance!
HTTP does not work that way. You must use the exact URL in order to request a page from the server.
I'm not sure if this helps you, but Flask has a feature that works similarly to what you require. Here's a working example:
#app.route('/categories/<int:category_id>')
def categoryDisplay(category_id):
''' Display a category's items
'''
# Get category and it's items via queries on session
category =session.query(Category).filter_by(id=category_id).one()
items = session.query(Item).filter_by(category_id=category.id)
# Display items using Flask HTML Templates
return render_template('category.html', category=category, items=items,
editItem=editItem, deleteItem=deleteItem, logged_in = check_logged_in())
the route decorator tells the web server to call that method when a url like */categories/(1/2/3/4/232...) is accessed. I'm not sure but I think you could do the same with the name of your zip as a String. See here (project.py) for more details.
Is it possible to change Magento template via query string?
I am developing a custom template and sometimes I want to check if I broke something, so I want to change via query string the theme for the default one.
I am looing for something like this:
?_theme=default
Does something like this exists?
Programmatically:
You could write an observer that is listening to event <controller_action_predispatch>
The observer method could look like this:
public function changeTheme(){
if (Mage::app()->getRequest()->getParam('layout_switch') == '1'){
Mage::getDesign()->setArea(‘frontend’)
->setPackageName(Mage::app()->getRequest()->getParam('package'))
->setTheme(Mage::app()->getRequest()->getParam('theme'));
}
return;
}
}
Then you would just need to call your page with e.g.
yourdomain.com/index.php/layout_switch/1/package/default/theme/default
The short answer is no you can't (as far as I know)
However if it's your local installation (which you use only as a development enviroment!) you can use a trick:
Create another Store view and assign whatever theme you want to that store view and then access it like yourstore.com/?___store=storecode
as simple as 1-2-3.:) Create a new dev theme and copy all the files from the current live theme to the new one (both app/design and sking). Then observe controller_action_predispatch event and then in the observer function simply:
$controllerAction = $observer->getControllerAction();
if ($controllerAction->getLayout()->getArea() == Mage_Core_Model_App_Area::AREA_FRONTEND) {
$ipAddress = Mage::helper('core/http')->getRemoteAddr();
$ipAddresses = array('xxx.xxx.xxx.xxx');
if (in_array($ipAddress, $ipAddresses)) {
Mage::getDesign()->setTheme('theme-wanted');
}
}
Very helpful for design tweaks indeed. After the work is finished the observer should be disabled or module deactivated until next time
Essentially I am looking to have a url query parameter persist throughout the life of the grails application (POST or GET). ex.
http://localhost:8080/demo/controller/action/?myParam=foobar
I have tried a couple routes. Dynamic method overriding redirect and customizing application tags for createLink. However, since I also use grails webflows it doesn't quite get every single URL. I also tried using a groovy servlet (groovlet) to capture every URL and append the query parameter. The last attempt hasn't been very successful. Am I missing an obvious component to grails? Am I on the right track? Is there another avenue I haven't explored yet?
Thanks in advance
Have you tried using a filter? The following filter will add the param to every request
class MyFilters {
def filters = {
addParam(controller:'*', action:'*') {
before = {
params.myParam = 'foobar'
}
} } }