Magento Front End 404 Error - mysql

I am a newbie to magento, I have installed and put a few products, but then later I was getting Error:404 page not found in the front end. Backend is all OK, I am able to access everything but all of a sudden I don't know how this happened. I tried all the solutions like Flush Cache, replacing .htaccess, is_active field in database etc but all proved futile. Then lately I have put in system->Configuration->Web Base_url as http://sportiva.no/index.php/ (Previously it was http://sportiva.no/) and all is completely changed all the styles went away and I am not able to save anything. Please help, I am ready to give backend credentails.
Please help

Go to System > Configuration > Web > Default Pages and check "CMS Home Page" field value. If it is "404 Not Found", then change it to any of the CMS page available on the drop-down and save the configuration.

Refere to this link by Alan Storm,
http://magento-quickies.alanstorm.com/post/6462298634/404-debugging
excerpt from it,
Put this code in function _validateControllerClassName
<?php
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
/**
* Generating and validating class file name,
* class and if evrything ok do include if needed and return of class name
*
* #return mixed
*/
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
var_dump($controllerFileName);
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
var_dump($controllerClassName);
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
var_dump($controllerFileName . '----' . $controllerClassName);
return false;
}
return $controllerClassName;
}

Related

On a new Telescope installation on a Laravel project, Localhost:8000/telescope returns blank page

I am new to Laravel and I am trying to get Telescope working on my project. When I try to navigate, on Chrome, to Localhost:8000/telescope I get a blank page. I tracked down the error to laravel/telescope/resources/views/layout.blade.php.
<!-- Global Telescope Object -->
<script>
window.Telescope = #json($telescopeScriptVariables);
</script>
The developer console error I get:
window.Telescope
= {"path":"telescope","timezone":"UTC","recording":true};
My major concern is to find a solution to this. I also would like to know why this error happened. I couldn't find a similar problem through google.
After some further googling I was able to find the cause and solution. Foundhere in this article of a very similar problem on Laravel and Vue.
By double encoding, the JSON object the HTML entities are removed from the object. The article suggests setting blade double encoding in the AppServiceProvider.
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
Blade::doubleEncode();
}
}
Another solution that I used was to double encode inline in the layout.blade.php.
<!-- Global Telescope Object -->
<script>
window.Telescope = {!!json_encode($telescopeScriptVariables)!!}
// window.Telescope = #json($telescopeScriptVariables);
</script>

AngularJs Dynamic/Multiple HTML Templates

I'm working on an AngularJs/MVC app with Web API etc. which is using a CDN. I have managed to whitelist two URLs for Angular to use, a local CDN and a live CDN (web app hosted in Azure).
I can successfully ng-include a template from my local CDN domain, but the problem arises when I push the site to a UAT / Live environment, I cant be using a template on Localhost.
I need a way to be able to dynamically get the base url for the templates. The location on the server will always be the same, eg: rooturl/html/templates. I just need to be able to change the rooturl depending on the environment.
I was thinking if there was some way to store a global variable, possibly on the $rootScope somewhere that I can get to when using the templates and then set that to the url via Web API which will get return a config setting.
For example on my dev machine the var could be http://Localhost:52920/ but on my uat server it could be https://uat-cdn.com/
Any help would be greatly appreciated as I don't want to store Js, css, fonts etc on the CDN but not the HTML as it feels nasty.
Thanks I'm advance!
I think it's good practice to keep environment and global config stuff outside of Angular altogether, so it's not part of the normal build process and is harder to accidentally blow away during a deploy. One way is to include a script file containing just a single global variable:
var config = {
myBaseUrl: '/templates/',
otherStuff: 'whatever'
}
...and expose it to Angular via a service:
angular.module('myApp')
.factory('config', function () {
var config = window.config ? window.config : {}; // (or throw an error if it's not found)
// set defaults here if useful
config.myBaseUrl = config.myBaseUrl || 'defaultBaseUrlValue';
// etc
return config;
}
...so it's now injectable as a dependency anywhere you need it:
.controller('fooController', function (config, $scope), {
$scope.myBaseUrl = config.myBaseUrl;
}
Functionally speaking, this is not terribly different from dumping a global variable into $rootScope but I feel like it's a cleaner separation of app from environment.
If you decide to create a factory then it would look like this:
angular.module('myModule', [])
.factory('baseUrl', ['$location', function ($location) {
return {
getBaseUrl: function () {
return $location.hostname;
}
};
}]);
A provider could be handy if you want to make any type of customization during config.
Maybe you want to build the baseurl manually instead of using hostname property.
If you want to use it on the templates then you need to create a filter that reuses it:
angular.module('myModule').filter('anchorBuilder', ['baseUrl', function (baseUrl) {
return function (path) {
return baseUrl.getBaseUrl() + path;
}
}]);
And on the template:
EDIT
The above example was to create links but if you want to use it on a ng-include directive then you will have a function on your controller that uses the factory and returns the url.
// Template
<div ng-include src="urlBuilder('path')"></div>
//Controller
$scope.urlBuilder = function (path) {
return BaseUrl.getBaseUrl() + path;
};
Make sure to inject the factory in the controller

How can a website call a file that no longer exists?

I have a website. I want to update my CSS file. After 20 minutes, uploading it 20 times, every browser still pulls the same CSS file. I delete the file off the server. There is literally no CSS file. I clear all my browser's cache's and history; everything. I load the website. It still pulls the old CSS file. Observations:
This is obviously a browser issue: when I load from mobile, the new file is there. So how can I give my Browser's a hint and actually make them clear cookies/cache etc?
Now I go to another computer that has never accessed the website, and it pulls old CSS file.
Please explain to me how, and why this is possible. Is it my host? I am using Netfirms, but how long can it possibly take to update a CSS file?
Its perfectly normal for browsers to cache content unless you take complete control over how long you want your pages and their resources to get cached.
What you want to do in these cases is implement something called "cache busting". What cache busting does is force browsers to treat a changed file on the server as a new request by simply making the browsers think its a different file or request.
The easiest way to do that is to append a query string like ?v=123 to your resource (JavaScript, CSS) URL. But do take care that some proxies will ignore to refresh their cached content if you use query strings. Therefore my preferred way of handling cache busting is to use rewrite rules to point requests for files like style-1391836063.css to a file which always has the same name on the server, i.e. style.css. The rewrite rule for that can be as simple as
RewriteRule (.+)-(\d+).(css|js)$ $1.$3 [L]
The whole magic is in the 1391836063 part which is actually a timestamp generated with filemtime(). That timestamp represents the last time the file was changed so it will retain the same value as long as style.css stays the same. In that case browsers will simply see the same resource name and will have no need to redownload its since its already cached and considered up to date.
However, if style.css does change the modiefied timestamp will also change which will result in a different numerical part, i.e. style-1391867247.css. If that happens browsers will be forced to discard any cached data and treat that request as a completely new resource.
However, for this to work you would also need server side support or in other words a script which will be doing all the fingerprinting (fingerprinting is actually the correct way to reference this technique). No matter what server side technology you use the process would be as follows.
With a DOM parser you look up for all the references to CSS and/or JavaScript files.
For every reference you find you check if the file exists on the server and if it does you read its modified timestamp with filemtime(). Then you append it to the actual resource name (style.css becomes something like style-1391867247.css)
You returne the fingerpinted code to the browser.
Here is a PHP class I wrote to perform fingeprinting on most of my projects. Please note that in order to avoid unnecessary processing this class should be used with some form of server-side caching to avoid fingeprinting if its not required. Additionally the code references some external constants and classes which should be disregarded as the code simply tries to demonstrate one way of how fingerprinting can be done.
/**
* CacheBusting class responsible for fingerprinting CSS and JavaScript resources in order to prevent caching issues.
*/
class CacheBuster {
/**
* Parses the loaded (X)HTML code and fingerprints all resources with their Last Modified timestamp.
*
* #param string $content XHTML content to fingerprint.
* #return mixed Either fingerprinted $content on success or false on failure.
*/
public static function fingerprint($content){
/**
* ExtendedDOMDocument for manipulating content data (something written by me to replace the gimpy DOMDocument class)
*
* #var ExtendedDOMDocument
*/
$dom;
/**
* XPath responsible for handling $dom.
*
* #var DOMXPath
*/
$xpath;
/**
* List of extracted DOM nodes.
*
* #var DOMNodeList
*/
$nodes;
/**
* Helper variable containing current resource URI.
*
* #var string
*/
$resource = '';
/**
* Helper variable containing all the results from regex matches.
*
* #var array
*/
$matches = array();
/**
* Array of resource URIs with their corresponding fingerprint versions.
*
* #var array
*/
$fingerprints = array();
// In case $content is not provided false is returned.
if(!strlen($content)){
return false;
}
// Loading $content into DOMDocument parser.
$dom = new ExtendedDOMDocument();
$dom->loadHTML($content);
// Extracting <script> and <link> nodes.
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//script|//link');
// Traversing the extracted nodes in order to find out the exact names of the CSS and JavaScript resources and then create the appropriate fingerprint.
foreach($nodes as $node){
//Only local resources with specified "src" or "href"" are taken into account.
switch($node->getAttribute('type')){
case 'text/javascript' :
$resource = $node->getAttribute('src');
break;
case 'text/css' :
$resource = $node->getAttribute('href');
break;
default:
// In case no type is specified we probe for either "src" or "href" but if nothing is found we skip this node.
/**
* Value of the 'src' attribute for the current node, if any.
*
* #var string
*/
$src = $node->getAttribute('src');
/**
* Value of the 'href' attribute for the current node, if any.
*
* #var string
*/
$href = $node->getAttribute('href');
if(strlen($src) && strpos($src, '.js')){
$resource = $src;
} else if(strlen($href) && strpos($href, '.css')) {
$resource = $href;
} else {
//No luck? Skipping the current node.
continue;
}
}
// Generating fingerprint pairs.
if(!strlen(trim($resource)) || (stripos($resource, 'http://') !== false) || (stripos($resource, 'https://') !== false)){
// Skipping inline and remote scripts.
continue;
} else {
// Fingerprinting resources...
preg_match('/(.+)\.(css|js)/', $resource, $matches);
if(file_exists(APP_FOLDER . $matches[0])){ // Resource exists.
$fingerprints[] = array(
'original' => $resource,
'fingerprinted' => $matches[1] . '-' . filemtime(APP_FOLDER . $matches[0]) . '.' . $matches[2]
);
}
}
}
// Time to make fingerprint pair replacements.
foreach($fingerprints as $pair){
$content = str_replace($pair['original'], $pair['fingerprinted'], $content);
}
return $content;
}
}
You can use the class as simple as calling it anywhere in the code.
$output = CacheBuster::fingerprint($MARKUP);
I think this is a classic case off "unintentionall" serverside caching. That meens that the server keeps a copy of your files to shorten the clients loading time.
Depening on the caching solution you could possibly turn the caching of with .htaccess.
Hope this helps!

Unknown path components using PHP to post

I adapted the Social Cafe PHP to post news as read everytime a user access to an article.
Everytime I access the page, it presents this error:
Unknown path components: /mv-news:read
The code is this:
try {
$urlartigo = get_permalink();
$story_id = $facebook->api('/me/mv-news:read?article='.$urlartigo.'','POST');
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
}
mv-news is a correct namespace.
EDIT: I've just tried to use news.reads?article= and still get the same error. This is driving me crazy, as I've searched throughout the whole internet and haven't found a solution.
EDIT2: I've just changed the $story_id line of code to:
$story_id = $facebook->api('/me/mv-news:news.reads','post', array('article' => $urlartigo));
But it still outputs the same error.
enter code here

How to access bootstrap.inc on external file

I need to bootstrap Drupal. I have a php-file with all my functions and in one of those functions, I need to use a Drupal function which is located in the bootstrap.inc file.
Structure of the server:(d) drupal (sd)includes (f)bootstrap.inc(d) scripts (sb)functions (f) functions.php
So I need to include in a self-written function the "variable_set" function, located in bootstrap.inc.
A little piece of the function my college wrote (I'm terribly sorry, but I don't know how to format php on the forum. If someone does, please let me know so I can edit this mess):
function readxml()
{
echo "<br/>READING...<br/>";
$file = './config.xml';
$xml = simplexml_load_file($file);
if($xml !== false)
{
foreach($xml->config->children() as $item){
$name = $item->getName(); // GETS CHILDREN UNDER 'CONFIG'
switch($name)
{
case 'website':
foreach($xml->config->website->children() as $kid){
$childname = $kid->getName();
switch($childname)
{
case 'theme':
if(inserttheme($kid)or die ('failed to insert theme<br/>')){
echo 'theme is installed.<br/>';}
break;
case 'slogan':
if(insertslogan($kid)or die('failed to insert slogan<br/>')){
echo 'slogan is installed.<br/>';}
break;
case 'sitename':
if(insertname($kid)or die('failed to insert name<br/>')){
echo 'website name is installed.<br/>';}
break;
}
}
break;
`
So, somewhere in the theme/slogan/name section, I have to call the variable_set function which is located in the bootstrap.inc file.
Somewhere I found this (again sorry for the non-formated text):
$drupal_directory = "/home/httpdocs/drupal"; // wherever Drupal is
$current_directory = getcwd();
chdir($drupal_directory);
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
chdir($current_dir);
return;
I included it both in my function.php as well as in my final php-file (where all the functions are called) but no result... What am I doing wrong?
That code you found looks about right, what is exactly is "no result", are you getting errors or nothing or...? Also, where did you put it exactly? (If it is not in a function, you need to remove the last line (return))
Also, the proper way to fix this would be to integrate your custom code as a Drupal module, then you don't have to worry about stuff like this: http://drupal.org/developing/modules
Or if it is a CLI script, expose it as a drush command: http://drupal.org/project/drush
Answer to the question, just include the file inside the Drupal folder!