I've inherited a CodeIgniter project which is displaying PHP notice errors all over the place. I've tried to alter the logging level to prevent them from appearing, but they're still showing.
Here's how I'm setting the logging level in index.php;
// I Have confirmed that the value of ENVIRONMENT is 'development'
define('ENVIRONMENT', !empty(getenv('CI_ENV')) ? getenv('CI_ENV') : 'production');
switch (ENVIRONMENT) {
case 'development':
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
break;
case 'testing':
case 'production':
ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>=')) {
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
} else {
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
}
break;
default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR
}
Looks like you're on development env. Try the below.
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
Perhaps also set the CI log threshold to 0
goto
application/config/config.php
$config['log_threshold'] = 0;
Related
On my Woocommerce shop settings I have checked the option:
[✓] Redirect to the cart page after successful addition.
And that's good behaviour for 99% of my shop.
On 1 single page (custom page with custom template) I need to enable Ajax functionality though.
Is there a way to accomplish this task in functions.php?
Ok insert this code into your functions.php. You have to replace the variable $your_ajax_page_slug with the name of your page that you want the redirect to cart functionality to be disabled. Ensure that you have 'Enable AJAX add to cart buttons on archives" checked in settings.
add_filter( 'woocommerce_get_script_data', 'modify_woocommerce_get_script_data', 20, 2 );
function modify_woocommerce_get_script_data ( $params, $handle ) {
global $wp;
$page_slug = '';
$your_ajax_page_slug = 'your-page-slug';
$current_url = home_url( $wp->request );
// Break the URL by the delimiter
$url_pieces = explode('/', $current_url);
// Get the page slug
if( is_array( $url_pieces ) )
$page_slug = end( $url_pieces );
if( $handle == 'wc-add-to-cart' && $page_slug == $your_ajax_page_slug ) {
$params['cart_redirect_after_add'] = false;
}
return $params;
}
I'm working on a Joomla! 2.5/3.x editor-xtd button and I have a problem loading a layout from file on button click.
I have tried this method:
$link = 'plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;
$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link = $link;
$button->text = 'Insert something';
$button->name = 'myplugin';
$button->options = "{handler: 'iframe', size: {x: 500, y: 300}}";
... but the full generated link in admin looks like http://my.local.host/mywebsite/administrator/plugins/editor-xtd/link-etc.. and it doesn't work. I also have tried including JURI::base in my $link, but the administrator path is still loaded.
I'm new in plugin dev with Joomla! and I have search a lot but no solution found.
** I also tried a link like this index.php?folder=plugins.editors-xtd.myplugin&file=myplugin.layout.php&name=$name but still nothing.
Is there a workout for this or I'll have to create&use a javascript function to run on button click?
Solution
Modify link variable like this (if application is admin):
$link = '../plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;
... and delete button options (this means that file contents will be loaded via ajax inside modal)
Further more, in myplugin.layout.php we can add a little security check and we can import Joomla! framework library and defines so that we can make use of Joomla! framework in our file (things like language load for eg.)
This is my actual header of file:
<?php
// No direct access
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
if( ! IS_AJAX) die;
// Include J!Framework for later use
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php');
//more magic goes here...
Unfortunately there is a bit of a gotcha here in that the JED checker process requires that ALL php files start with defined('_JEXEC') or die; on the very first line of code so if you want to share it on extensions.joomla.org then you are stymied...
Back on the OP you can detect whether you are in the Admin or Site before generating the link:
$app = JFactory::getApplication();
// ...
if ($app->isAdmin()) {
$root = '../'; // Joomla expects a relative path, leave site folder "administrator"
} else {
$root = '';
}
$button->link = $root.'/plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;
Also, as you may already know the $button->name = 'myplugin'; needs to be the name of the icon from the Joomla icomoon set - you can see them here https://ma.tvtmarine.com/en/blog/112-joomla-icomoon-icons-directory
The name needs to be the icon name without the .icon- bit eg:
$button->name = 'warning-2';
code block doesn't seem to be working properly...sorry about the formatting
I have two stores within a single installation of Magento, and I have a separate domain for the second store that just points to the main installation (there are no files in the second domain at all). However, the second store isn't loaded when the user visits through the second domain, the categories and products of the default store are loaded. I added the following lines to the .htaccess file in Magentos' root but they doesn't seem to be working.
############################################
enable rewrites
SetEnvIf Host www\.testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host www\.testsite\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host ^testsite\.com MAGE_RUN_TYPE=website
Options +FollowSymLinks
RewriteEngine on
############################################
shoe_store is the code for the 'Website Name' of the second store, not the 'Store View Name' but neither of them work. I'm not sure what all the back slashes are for but they are in all the tutorials I've read. I've also checked the Base URL in both the Secure and Unsecure sections and it's the correct address with a / at the end (http://testsite.com/).
I've got multiple stores working with sub-domains but separate domains is proving more difficult. Anyone know what I'm doing wrong?
Edit: Added in the index.php code below
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category Mage
* #package Mage
* #copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
if (version_compare(phpversion(), '5.2.0', '<')===true) {
echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
Find out how to install</a>
Magento using PHP-CGI as a work-around.</p></div>';
exit;
}
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
/**
* Compilation includes configuration file
*/
define('MAGENTO_ROOT', getcwd());
$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
include $compilerConfig;
}
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';
if (!file_exists($mageFilename)) {
if (is_dir('downloader')) {
header("Location: downloader");
} else {
echo $mageFilename." was not found";
}
exit;
}
if (file_exists($maintenanceFile)) {
include_once dirname(__FILE__) . '/errors/503.php';
exit;
}
require_once $mageFilename;
#Varien_Profiler::enable();
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
umask(0);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
if (file_exists($autoload = __DIR__.'/vendor/autoload.php')) {
require_once $autoload;
}
switch($_SERVER['HTTP_HOST']) {
case 'mainsite.com':
case 'www.mainsite.com':
$mageRunCode = 'base'; //not your website code, it should be code for your first store
$mageRunType = 'website'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
break;
case 'testsite.com':
case 'www.testsite.com':
$mageRunCode = 'shoe_store'; //code of second store
$mageRunType = 'website';
break;
}
Mage::run($mageRunCode, $mageRunType);
By going through your issue, I feel that your domains are working perfectly. However for your two domains same store (default one) is loading. This is because you didn't specify that which store to load for which domain. For magento, your two domains are strangers and hence it will load with default store for each one.
So we want to inform magento that, for each of domain, a particular store should load. Store is loading in index.php itself (in root directory.).
Please go to index.php file and you will see the last line that loads the desires store and store view. We need to alter it some how so that magento should load the correct store according to our need.
So add the following code just above this code snippet Mage::run($mageRunCode, $mageRunType);
switch($_SERVER['HTTP_HOST']) {
case 'firstdomain.com':
case 'www.firstdomain.com':
$mageRunCode = 'store_code'; //not your website code, it should be code for your first store
$mageRunType = 'store'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
break;
case 'seconddomain.com':
case 'www.seconddomain.com':
$mageRunCode = 'store_code'; //code of second store
$mageRunType = 'store';
break;
}
Mage::run($mageRunCode, $mageRunType);
Hope that helps...
Sorry if this is really obvious, not great at coding and new to cookies so stil trying to get my head round it. I am trying to create a website redirect for my Magento installation. In the index.php I have placed the following code which checks the users IP location, directs them to the correct website and sets a cookie. If a cookie is already set it takes the value from the cookie and directs to a website based on this.
if ((isset($_COOKIE['penstore']) )){
$_SERVER['MAGE_RUN_CODE'] = $_COOKIE['penstore'];
$_SERVER['MAGE_RUN_TYPE'] = "website";
}
else
{
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, "$ip");
geoip_close($gi);
switch($country_code)
{ case "CA": case "US":
$_SERVER['MAGE_RUN_CODE'] = "usa";
$_SERVER['MAGE_RUN_TYPE'] = "website";
setcookie("penstore",'usa',time()+43200);
break;
case "GB":
$_SERVER['MAGE_RUN_CODE'] = "uk";
$_SERVER['MAGE_RUN_TYPE'] = "website";
setcookie("penstore",'uk',time()+43200);
break;
default:
$_SERVER['MAGE_RUN_CODE'] = "int";
$_SERVER['MAGE_RUN_TYPE'] = "website";
setcookie("penstore",'int',time()+43200);
}
}
This all appears to work okay, my problem is finding a way to allow customers to change websites by clicking an image in the header. I have tried several different methods based on code found on the web and this site but I can't get any of it to work. I currently have the following code in my header.phtml:
<script language="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
location.reload();
}
</script>
<img src="http://mysite.com/images/INT.gif">
<img src="http://mysite.com/images/US.gif">
<img src="http://mysite.com/images/GB.gif">
The idea is that the customer clicks on the image which causes the cookie value to be updated and the current page to be reloaded, which based on the code in the index.php, would cause a different website to load. All that happens is the # gets added to the url?
Edit: To clarify, I'm trying to switch websites, not stores, so can't use Magento store switcher.
How to upload images in web context (frontend) without reloading the page in modx revolution? I am trying to use fileupload extra for uploading images but it is reloading the page. Can anyone help me, please?
finally i got the answer. we can do it without using FILEUPLOAD addon by using the simple php code and a small javascript..
php code:-
<?php
$path = "uploads/";
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024)) // Image size max 1 MB
{
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
echo "image uploaded";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
for other javascript and all u can refer the below link:-
http://www.9lessons.info/2011/08/ajax-image-upload-without-refreshing.html