Subscribe To RSS Feed


Mike D's SharpBlog

Just another Sharpdot weblog

Archive for March, 2009

Magento – module not working on unix/linux server

- Thursday, March 19th, 2009 -

I am writing this more as a reminder to my self and anyone else who makes a module for magento. I created a module and it was working fine locally on my windows machine. When I uploaded the site to a unix/linux server the module seemed to stop functioning correctly. Here was the problem:

I had a Block class called SideNavigation.php. I called it using a layout file. It was suppose to provide custom CMS functionality with a side navigation menue.

Below is the code from the layout file that did not work.

<?xml version="1.0"?>
     <layout version="0.1.0">
          <cms_page>
               <reference name="left">
                    <block type="advancedcms/sidenavigation" name="advancedcms.sidenav" />
               </reference>
          </cms_page>
     </layout>

The reason this did not work is because unix machines are case sensitive where as Windows is not case sensitive. Magento turns sidenavigation in the above code into Sidenavigation. It allways capitalizes the first letter. So windows would match Sidenavigation to SideNavigation because it is case insensitive. unix/linux machines would not match Sidenavigation to SideNavigation. So I had to change my code to the following to work.

<?xml version="1.0"?>
     <layout version="0.1.0">
          <cms_page>
               <reference name="left">
                    <block type="advancedcms/sideNavigation" name="advancedcms.sidenav" />
               </reference>
          </cms_page>
     </layout>

Now magento turns it into SideNavigation and the layout file correctly points to the SideNavigation.php file.

Hope this helps anyone with a simmilar problem.

Just a closing thought: Wouldn’t it be nice to be able to make windows case sensitive, so you don’t have to do trouble shooting like this.

Posted in Uncategorized | 2 Comments »

Magento: error message – Notice: Undefined index: 0 app/code/core/Mage/Core/Model/Mysql4/Config.php on line 92

- Tuesday, March 17th, 2009 -

The Quick resolution to this problem it to move the database command line, and not use phpmyadmin. If you just need to fix your database keep reading.

I was moving a installation to a production server and was getting this error message: Notice: Undefined index: 0 in app/code/core/Mage/Core/Model/Mysql4/Config.php on line 92. It took alot of searching to figure out the problem, but here is what I found. When Magento installs it sets store and website ids in the database. When transferring the database the new database did not like having an id of 0 for the admin part of the site, so it made it have an id of 2. This is what my problem was. To fix it I went into the core_store and core_website Tables and gave the admin site an id of 0. It looks like this may only affect certain versions of magento(Earlier versions). Hope this helps someone else.

P.S. I also got foreign_key_constraint errors when importing my database. To solve this disable foreign key check when you export your database. Then when you need to change the core_store and core_website id’s you will probably need to surround your sql with the following code:

set foreign_key_checks=0;
//SQL to update ids
SET FOREIGN_KEY_CHECKS=1;

Tags: , ,
Posted in magento | 35 Comments »

Magento: Adding a static block to a view file (AKA: phtml file)

- Wednesday, March 11th, 2009 -

In magetnto you can add static blocks that you have created to pages using the layout xml files and adding code there. There is plenty of documentation on this method, but what if you want to call the static block from a view (view files generally end in .phtml). Well this is how I have been able to do it.

Just call

<?php
     echo  $this->getLayout()->createBlock('cms/block')->setBlockId('contacts_text')->toHtml() ;
?>

or

<?php
 echo $this->getLayout()->createBlock('catalog/product_list_related')->setTemplate('catalog/product/list/related.phtml')->toHtml() ;
?>

Where setBlockId is the identifier you set up in the static block.

Tags:
Posted in magento | 15 Comments »

Magento: Error – SimpleXMLElement::addAttribute() Attribute already exists

- Tuesday, March 10th, 2009 -

Warning: SimpleXMLElement::addAttribute() [simplexmlelement.addattribute]: Attribute already exists.

This Magento Error Message was giving me the hardest time. It seems to occur when you have a mis-match in your layout files.

What happend to me was I hard coded the newsletter into a page. In the newsletter layour file It was instructed to put the newsletter in the page also. This meant that it was included in the page more than once. That is why the error is thrown. Check your layout files to get a better grip on the problem.

I need to give thanks to Branko Ajzele for his post. It helped me realize what the problem was.

Tags: ,
Posted in magento | 3 Comments »