Magento Admin Custom Module Common Problems

Hello friends,

Custom development in any technology is continuous process. The common reason for custom development is frequently changing requirements.

By applying same rule in Magento, developers are developing more and more custom modules. And some of those modules are related to admin functionality.

Just before a week I was developing a magento custom module in which 60% of functionalities were related to admin. While developing those admin related functionalities I faced some common problems.

So here I want to discuss those problems and its solutions.

Problem 1: In my module I have successfully created admin grid. Where add and edit functionalities were working fine. But while editing an item, there was no DELETE button in the form. I surprised, checked my code but didn’t get an idea for that problem. So I searched the web and found the under given solution.

Solution 1: The problem is in Edit.php block, I put


at the first line of



But it should be after the



I did that change and my problem get solved.

Problem 2: In my module, an admin form has facility to upload the file. There I was able to add the item and upload the file successfully. Whenever I edit the item a very small thumbnail image of the uploaded file along with the browse button and delete option was displaying. Then I tick marked the delete option and click on “Save and Continue” button and it gave me the under given error.

Warning: preg_match() expects parameter 2 to be string, array given  in /lib/Varien/Data/Form/Element/Image.php on line 56

Solution 2: Above error occurred, just because there wasn’t any code in custom module’s controller to delete the uploaded file.

So to solve the problem I did the changes in the /app/code/local/Company/Modulename/controllers/Adminhtml/ModulenameController.php file.

Where I looked for the code block like:

if(isset($_FILES['image_file']['name']) && $_FILES['image_file']['name'] != '')

And added the under given else condition block right after the above if condition block.

elseif (isset($data['image_file']['delete']) && $data['image_file']['delete'] == 1) {
    $path = Mage::getBaseDir('media') . '/';
    if(file_exists($path . $data['image_file']['value'])) {
        unlink($path . $data['image_file']['value']);
    $data['image_file'] = '';
} elseif (isset($_POST['image_file']['value'])) {
    $data['image_file'] = $_POST['image_file']['value'];
} else {
    $data['image_file'] = '';

And the problem got solved.

That’s it.

Hope this will help you.


Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: