Magento - Can't Save Role Resource for Custom Module - magento

I’ve created a custom module and my config.xml is as follows…
<?xml version="1.0"?>
<config>
<admin>
<routers>
<blacklist>
<use>admin</use>
<args>
<module>Leon_Blacklist</module>
<frontName>blacklist</frontName>
</args>
</blacklist>
</routers>
</admin>
<adminhtml>
<menu>
<blacklist translate="title" module="blacklist">
<title>Blacklist</title>
<sort_order>71</sort_order>
<children>
<items translate="title" module="blacklist">
<title>Manage Items</title>
<sort_order>0</sort_order>
<action>blacklist/adminhtml_blacklist</action>
</items>
</children>
</blacklist>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<Leon_Blacklist translate="title" module="blacklist">
<title>Blacklist Module</title>
<sort_order>10</sort_order>
<children>
<items translate="title" module="blacklist">
<title>Manage Items</title>
</items>
</children>
</Leon_Blacklist>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<blacklist>
<file>blacklist.xml</file>
</blacklist>
</updates>
</layout>
</adminhtml>
<config>
The module works as expected if an admin account is logged in. I can see the module in the admin panel and in the Role Resource Tab (System->Permissions->Roles), but when I tried to check the module and save the user role, it will say that it has been saved. But when I rechecked the user role, it is still unchecked.
And when I tried to login using the account with the said user role, the custom module is hidden. What seems to be the problem? Any kind of help is much appreciated..
Thanks.

Your acl section of config is a little wrong. Tags should be similar to menu section. So in your case it should look like this:
<acl>
<resources>
<admin>
<children>
<blacklist translate="title" module="blacklist">
<title>Blacklist Module</title>
<sort_order>10</sort_order>
<children>
<items translate="title" module="blacklist">
<title>Manage Items</title>
</items>
</children>
</blacklist>
</children>
</admin>
</resources>
</acl>

Here is my acl section of config.xml
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<banner translate="title" module="banner">
<title>Banner Module</title>
<sort_order>10</sort_order>
<children>
<banner translate="title" module="banner">
<title>Manage Banners</title>
</banner>
</children>
</banner>
</children>
</admin>
</resources>
</acl>
Also add the below function in your controller to avoid the "Access denied" message
protected function _isAllowed(){
return true;
}
Code taken from: http://chandreshrana.blogspot.in/2015/06/custom-module-role-not-save-in.html

Related

Magento - How to create new admin page

I'm using Magento 1.9.0.1 and i've created a new extension in which i've added a new tab in the admin panel take a look at the picture.
Here is what i have in my files.
In: /app/code/community/VivasIndustries/SmsNotification/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<VivasIndustries_SmsNotification>
<version>0.1.0</version>
</VivasIndustries_SmsNotification>
</modules>
<global>
<models>
<smsnotification>
<class>VivasIndustries_SmsNotification_Model</class>
</smsnotification>
</models>
<events>
<sales_order_save_after>
<observers>
<vivasindustries_smsnotification>
<class>smsnotification/observer</class>
<method>orderSaved</method>
</vivasindustries_smsnotification>
</observers>
</sales_order_save_after>
</events>
<helpers>
<smsnotification>
<class>VivasIndustries_SmsNotification_Helper</class>
</smsnotification>
<adminhtml>
<rewrite>
<data>VivasIndustries_SmsNotification_Helper_Adminhtml_Data</data>
</rewrite>
</adminhtml>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Here is what i have in: /app/code/community/VivasIndustries/SmsNotification/etc/adminhtml.xml:
<?xml version="1.0"?>
<config>
<menu>
<vivassms translate="title" module="smsnotification">
<title>SMS Center</title>
<sort_order>110</sort_order>
<children>
<sendsms translate="title" module="smsnotification">
<title>Send SMS</title>
<action>adminhtml/magesms_sendsms</action>
<sort_order>1</sort_order>
</sendsms>
<settings>
<title>Settings</title>
<action>adminhtml/system_config/edit/section/vivas/</action>
<sort_order>10</sort_order>
</settings>
<about translate="title" module="smsnotification">
<title>About</title>
<action>adminhtml/smsnotification_about</action>
<sort_order>11</sort_order>
</about>
</children>
</vivassms>
</menu>
<acl>
<resources>
<admin>
<children>
<vivassms>
<title>SMS</title>
<children>
<sendsms translate="title" module="smsnotification">
<title>Send SMS</title>
</sendsms>
<settings>
<title>Settings</title>
<children>
<smsprofile translate="title" module="smsnotification">
<title>Edit user account</title>
</smsprofile>
</children>
</settings>
<about translate="title" module="smsnotification">
<title>About</title>
</about>
</children>
</vivassms>
<system>
<children>
<config>
<children>
<vivassms translate="title" module="smsnotification">
<title>Vivas SMS</title>
</vivassms>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
I've added these three children tabs to the created new tab SMS Center but when i click on the About tab i got error 404 ON MY FRONTEND. This is awkward. Why i got redirected to the frontend ?
Can you please help me out to create a simple new custom page in the admin panel where i want to add a simple text?
Thanks in advance!
Seems like Magento recognizes your module is telling it "Check me for admin" controllers, but that Magento doesn't find any. The best way to figure out what Magento thinks your controller file should be named (as well as which folder it should be located in) is to add some temporary debugging to _validateControllerClassName
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
var_dump($controllerFileName); //add this line
return false;
}
This will dump out every file Magento checks for a controller. Look for the line with your module name in it, and compare paths between where your file is located and where Magento thinks it should be located.

Menu is not displaying in Magento Admin

I want to add a section in magento dashboard for a particular user type with user add/edit/delete facility, so I have created a module for magento Admin but it not diplay in Admin menu.
I want to display association menu in magento admin.
Although it is displaying in system -> config ->advance to give enable/disable facility.
The config xml is.
0.1.0
<global>
<models>
<association>
<class>yanga_association_Model</class>
<resourceModel>association_mysql4</resourceModel>
</association>
<association_mysql4>
<class>yanga_association_Model_Mysql4</class>
<entities>
<association>
<table>association</table>
</association>
</entities>
</association_mysql4>
</models>
<resources>
<association_setup>
<setup>
<module>yanga_association</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</association_setup>
<association_write>
<connection>
<use>core_write</use>
</connection>
</association_write>
<association_read>
<connection>
<use>core_read</use>
</connection>
</association_read>
</resources>
<blocks>
<association>
<class>yanga_association_Block</class>
</association>
</blocks>
<helpers>
<association>
<class>yanga_association_Helper</class>
</association>
</helpers>
</global>
<admin>
<routers>
<association>
<use>admin</use>
<args>
<module>Yanga_Association</module>
<frontName>association</frontName>
</args>
</association>
</routers>
</admin>
<adminhtml>
<menu>
<association module="association">
<title>Association</title>
<sort_order>71</sort_order>
<children>
<items module="association">
<title>Manage Association</title>
<sort_order>0</sort_order>
<action>association/adminhtml_association</action>
</items>
</children>
</association>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<Association>
<title>Association Module</title>
<sort_order>10</sort_order>
</Association>
</children>
</config>
</children>
</system>
<Yanga_Association>
<title>System Configuration Tab</title>
<sort_order>10</sort_order>
</yanga_Association>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<association>
<file>association.xml</file>
</association>
</updates>
</layout>
</adminhtml>
Kindly provide us the solution if have.
Thanks in advance.
If you are trying to access sytem settings than you have to code like
<config translate="title">
<title>Configuration</title>
<sort_order>1</sort_order>
<action>adminhtml/system_config/edit/section/association</action>
</config>
Instead of .Replace this code with and check it.Hops it works
You forgot to add your menu's permission in your acl declaration, your ACL should look like this -:
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<Association>
<title>Association Module</title>
<sort_order>10</sort_order>
</Association>
</children>
</config>
</children>
</system>
<association>
<title>Association</title>
<children>
<items translate="title" module="association">
<title>Manage Association</title>
</items>
</children>
</association>
<Yanga_Association>
<title>System Configuration Tab</title>
<sort_order>10</sort_order>
</yanga_Association>
</children>
</admin>
</resources>
</acl>`
Hope it helps!
Cheers
S

Magento custom tab and admin controller acl

I have an issue with a custom controllers ACL for the admin backend.
Ive read, re-read, checked....and still cant find my issue. Dammit.
First, the code...the module itself is working...i have blocks, helpers, front end controllers...system->config tab/group data...all working fine. My issue is just relating to admincontroller acl...so ill just add the relevant code for that area for now.
My backend tab is showing, but the urls (admin/mynewmodule/index, admin/mynewmodule/list) go to a 404 page.
config.xml, admin routers:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<mynewmodule before="Mage_Adminhtml">
Mworkz_MyNewModule_Adminhtml
</mynewmodule >
</modules>
</args>
</adminhtml>
</routers>
</admin>
Adminhtml.xml, backend tab, and acl
<?xml version="1.0"?>
<config>
<menu>
<mynewmodule module="mynewmodule " translate="title">
<title>MyNewModule</title>
<sort_order>71</sort_order>
<children>
<items module="mynewmodule " translate="title">
<title>Index Action</title>
<sort_order>1</sort_order>
<action>adminhtml/mynewmodule/</action>
</items>
<list module="mynewmodule " translate="title">
<title>List Action</title>
<sort_order>2</sort_order>
<action>adminhtml/mynewmodule/list/</action>
</list>
</children>
</mynewmodule >
</menu>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<mynewmodule translate="title">
<title>MyNewModule</title>
</mynewmodule>
</children>
</config>
</children>
</system>
<mynewmodule translate="title" module="mynewmodule">
<title>MyNewModule</title>
<sort_order>-100</sort_order>
<children>
<items translate="title">
<title>Index Action</title>
<sort_order>1</sort_order>
</items>
<list translate="title">
<title>List Action</title>
<sort_order>2</sort_order>
</list>
</children>
</mynewmodule>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<mynewmodule>
<file>mworkz/mynewmodule.xml</file>
</mynewmodule>
</updates>
</layout>
</config>
Admin controller
class Mworkz_MyNewModule_Adminhtml_MyNewModuleController extends Mage_Adminhtml_Controller_action
{
protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('extbuilderpro/items')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
return $this;
}
public function indexAction() {
$this->_initAction()
->renderLayout();
}
public function listAction() {
$this->_initAction()
->renderLayout();
}
}
If you write your own extension, path must be module_name/admin_html/list. Download free magento extension, for example: http://www.magentocommerce.com/magento-connect/news-by-commercelab-3436.html and look at etc/config.xml.
So right code:
<menu>
<modulename module="modulename" translate="title">
<title>Module Name</title>
<sort_order>1</sort_order>
<children>
<add translate="title" module="modulename">
<title>Add New Item</title>
<sort_order>0</sort_order>
<action>modulename/adminhtml_news/new</action>
</add>
<items translate="title" module="modulename">
<title>Items Manager</title>
<sort_order>10</sort_order>
<action>modulename/adminhtml_news/index</action>
</items>
<settings translate="title" module="modulename">
<title>Settings</title>
<sort_order>40</sort_order>
<action>adminhtml/system_config/edit/section/modulename</action>
</settings>
</children>
</clnews>
</menu>

How do I add a submenu to an existing menu in Magento?

My existing code creates a menu that looks like this.
But I want a menu that is a sub-menu of the Catalog menu.
Here is my existing code in adminhtml.xml
<?xml version="1.0" ?>
<config>
<menu>
<mycustom_menu translate="title" module="brands">
<title>My Custom Menu Item</title>
<sort_order>300</sort_order>
<children>
<!-- child items go here -->
<subitem translate="title" module="brands">
<title>Manage Brands</title>
<sort_order>10</sort_order>
<action>adminhtml/mycustom_controller/</action>
</subitem>
</children>
</mycustom_menu>
</menu>
<acl>
<resources>
<admin>
<children>
<mycustom_menu translate="title" module="brands">
<title>My Custom Menu Item</title>
<sort_order>300</sort_order>
<children>
<subitem translate="title" module="brands">
<title>Subitem</title>
<sort_order>10</sort_order>
</subitem>
</children>
</mycustom_menu>
</children>
</admin>
</resources>
</acl>
</config>
Instead of using <mycustom_menu> you need to re-use the nodename that was used in the adminhtml.xml of the catalog module. That name is catalog.
So your XML should look like:
<?xml version="1.0"?>
<config>
<menu>
<catalog>
<children>
<your_subitem>
<title>Subitem 1</title>
<sort_order>10</sort_order>
<action>adminhtml/your_action</action>
</your_subitem>
</children>
</catalog>
</menu>
<acl>
<resources>
<admin>
<children>
<catalog>
<title>Subitem 1</title>
<sort_order>10</sort_order>
</catalog>
</children>
</admin>
</resources>
</acl>
</config>
For example to add submenu in customer tab:
<menu>
<customer>
<children>
<vendor module="yourmodule">
<title>Your Title</title>
<sort_order>0</sort_order>
<action>admin_yourmodule/adminhtml_yourmoduleaction</action>
</vendor>
</children>
</customer>
</menu>

How to link Magento admin menu to role resources

Here's the situation:
I would like to add a Menu in the Magento backend navigation menu.
I accomplished this by adding the following code in app/etc/config.xml:
<adminhtml>
<menu>
<example translate="title" module="adminhtml">
<title>Inventory</title>
<sort_order>110</sort_order>
<children>
<set_time>
<title>Set It!</title>
<action>helloworld/index/goodbye</action>
</set_time>
</children>
</example>
</menu>
The problem is I can't include this menu in the permission->role resources so I can't assign this to a specific user.
How do I include this menu in the permission->role resources?
Thank you and more power!
You need to tell magento that you want your new menu position to be visible in the permission tree. To do this you have to add an ACL section to your configuration data. Put this inside your module's config.xml file:
<acl>
<resources>
<admin>
<children>
<example>
<title>Inventory</title>
<sort_order>110</sort_order>
<children>
<set_time>
<title>Set It!</title>
<sort_order>0</sort_order>
</set_time>
</children>
</example>
</children>
</admin>
</resources>
</acl>
thanks.. I got it to work with a few tweakings..
<adminhtml>
<acl>
<resources>
<admin>
<children>
<helloworld_options translate="label" module="helloworld">
<title> MENU</title>
<sort_order>999</sort_order>
<children>
<hello_children1>
<title> RELATION</title>
<sort_order>10</sort_order>
</hello_children1>
<hello_children2>
<title> MACHINE</title>
<sort_order>20</sort_order>
</hello_children2>
<hello_children3>
<title> INVOICE</title>
<sort_order>30</sort_order>
</hello_children3>
</children>
</helloworld_options>
<system>
<children>
<config>
<children>
<helloworld_options translate="label" module="helloworld">
<title> MENU</title>
</helloworld_options>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
this will display the following menu with sub menus in the backend.. plus this can be configured in the role resources.. :)

Resources