Magento: Access denied in admin of custom module

I was building a custom module in Magento. I had created a system.xml file for storing configuration data from admin. From the below system.xml file, you can see that I have created a section named ‘My Module Name‘ which can be accessed from Admin –> System –> Configuration.

In the file below, I have just displayed the section and groups name. I have omitted others fields with dots, as they are not necessary here.


<?xml version="1.0" encoding="UTF-8"?>
<config>
   <sections>         
		<my_section_name translate="label" module="mymodulename">
			<label>My Module Name</label>
			...
			..
			.
			<groups>
				<my_group_name translate="label" module="mymodulename">
					<label>My Group Name</label>
					...
					..
					.
					<fields>
						...
						..
						.
					</fields>
				</my_group_name>
			</groups>
			<groups>
				<second_group_name translate="label" module="mymodulename">
					<label>Second Group Name</label>
					...
					..
					.
					<fields>
						...
						..
						.
					</fields>
				</second_group_name>
			</groups>
		</my_section_name>			
    </sections>
</config>

Now, when I try to access the ‘My Module Name‘ tab present in Admin –> System –> Configuration, I get the ‘Access Denied‘ Error.

I searched the internet about this problem. In the magentocommerce forum, people suggested to log out and relogin. But it didn’t slove my problem.

Inchoo suggested to edit administrator roles. But, it didn’t solve either.

Then I tried Activecodeonline’s solution. It suggested me to set some nodes in config.xml file of my module. I also think that it’s XML related problem. But this solution didn’t solve my problem. The ‘Access Denied‘ error still exists.

Finally, Activecodeonline was very useful to me ;). Actually, I had 2 groups in my system.xml file (see above xml). Hence, I need to add both group names as children in config.xml file of my module.

Regarding my system.xml file, the following XML is to be added in the config.xml file.


<system>
	<children>
		<config>
			<children>
				<my_group_name>
					<title>My Group Name</title>
				</my_group_name>
				<second_group_name>
					<title>My Second Group Name</title>
				</second_group_name>
			</children>
		</config>
	</children>
</system>

Here is my config.xml file which solved my problem. Unnecessary parts for here are removed with dots (…) :)


<?xml version="1.0"?>
<config>
    <modules>
       ...
	   ..
	   .
    </modules>
    <frontend>
        ...
		..
		.
    </frontend>
    <admin>
        ...
		..
		.
    </admin>
    <adminhtml>
		<menu>
			...
			..
			.
		</menu>
		<acl>
			<resources>
				<all>
					<title>Allow Everything</title>
				</all>
				<admin>
					<children>
						<MyCompany_MyModule>
							<title>My Module</title>
							<sort_order>10</sort_order>
						</MyCompany_MyModule>
						<system>
							<children>
								<config>
									<children>
										<my_group_name>
											<title>My Group Name</title>
										</my_group_name>
										<second_group_name>
											<title>My Second Group Name</title>
										</second_group_name>
									</children>
								</config>
							</children>
						</system>
					</children>
				</admin>
			</resources>
		</acl>
		<layout>
			...
			..
			.
		</layout>
    </adminhtml>   
    <global>
        ...
		..
		.
    </global>
</config>

Hope this helps. Thanks.