3

I have a grid from a custom module in my admin section which displays users that fit a specified criteria. When I click on one of those users to edit details I am transferred to a blank content area where I would expect to see a form.

I have gone over my code and what I understand to be correct and have changed the _blockGroup to = [module], [namespace], [module_namespace] but don't have any success.

class Ps_Prefs_Block_Adminhtml_Prefs_Edit
extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function _construct()
{
    parent::_construct();

    $this->_objectId = 'id';
    $this->_blockGroup = 'prefs';
    $this->_controller = 'adminhtml_prefs';
    $this->_mode = 'edit';
}

config.xml

<config>
.......
    <admin>
    <routers>
        <adminprefs><!--arbitary name but needs to be unique-->
            <use>admin</use>
            <args>
                <module>Ps_Adminprefs_AdminprefController</module>
                <frontName>admin</frontName><!--admin works!but all other custom admin modules fail! adminPrefs produce 404! -->
                <modules>
                    <Ps_Prefs after="Mage_Adminhtml">Ps_Prefs_Adminhtml</Ps_Prefs>
                </modules>
            </args>
        </adminprefs>
    </routers>
</admin>
........
</config>

adminhtml.xml

<config>
<menu><!--adds menu item called prefs > example onto the admin menu bar-->
    <customer>
        <children>
            <Prefs translate="title">
                <title>Prefs Centre</title>
                <sort_order>90</sort_order><!--sets the prefs towards the end of the list-->
                <action>adminhtml/adminprefs</action>
            </Prefs>
        </children>
    </customer>
</menu>
........    
<layout>
    <updates>
        <prefs>
            <file>prefs.xml</file>
        </prefs>
    </updates>
</layout>

Ps_Prefs_Adminhtml_AdminprefsController

public function editAction()
{
    $model = Mage::getModel('prefs/prefs');
    Mage::register('prefs_data', $model);
    $id = $this->getRequest()->getParam('id');

    try {
        if ( $id ) {
            if ( ! $model->load($id)->getId() ) {
                Mage::throwException($this->__( 'No record with that ID "%s" found', $id ));
            }
        }

        if ( $model->getId() ) {
            $pageTitle = $this->__('Edit %s (%s)', $model->getName(), $model->getType());
        } else {
            $pageTitle = $this->__('New User');
        }

        $this->_title($this->__('Customer'))
             ->_title($this->__('Preference'))
             ->_title($pageTitle);

        $this->loadLayout();
        $this->renderLayout();
    }   

    catch (Exception $e) {
        Mage::logException($e);
        $this->_getSession()->addError($e->getMessage());
        $this->_redirect('*/*/');
    }
}

I believe it is in the edit file but I have added the other files incase it helps with a solution.

===

EDIT

===

the problem was with the config. The below works

<admin><!--new way to define an admin route-->
  <routers>
     <prefsadminhtml>
        <use>admin</use>
        <args>
            <module>Ps_Prefs_Adminhtml</module>
            <frontName>admin</frontName>
           <modules>
              <syntax after="Ps_Prefs_AdminprefsController">Mage_Adminhtml</syntax><!--what is this syntax node mean? -->
              <prefsmodule before="Mage_Adminhtml">Ps_Prefs_Adminhtml</prefsmodule>
           </modules>
        </args>
     </prefsadminhtml>
  </routers>

  • can you post the url you end up with on the blank page? Also, the way you are defining the admin router, although not wrong, is a dated, less preferred way. See this post: stackoverflow.com/questions/15349319/… as well as the explanation by Alan Storm located here: alanstorm.com/magento_dispatch_admin_cms_default_routers – ProxiBlue Oct 11 '13 at 12:21
  • the url is magentodevtest.local/index.php/admin/adminprefs And thanks for that link re: the updated way of defining a router, it answers my confusion on the difference in some tutorials – tony09uk Oct 11 '13 at 12:36
  • Do you still get the same issue if you chnage how the router is done? In your router configuration you are using <frontName>admin</frontName>, which could/would clash with magento normal admin functionality. – ProxiBlue Oct 11 '13 at 14:59
  • So i've changed the router configuration and it has worked although the frontName is still admin. I wont be adding an answer as I have no idea how it has worked, I will update my post with what has worked, any answers as to why will be helpful – tony09uk Oct 14 '13 at 9:56
  • Hi, where did you come across that syntax for the admin router? never seen it done like that before, and never seen the 'syntax_after' tag before. It looks really over complicated. refer to this post: alanstorm.com/magento_admin_hello_world_revisited, specifically the section 'Setting up the Admin Controller' – ProxiBlue Oct 14 '13 at 14:45
2

To set up an admin router you can use the following snippet, it should be enough to have these few lines and a controller to get your admin router working:

<admin>
     <routers>
        <adminhtml>
            <args>
                <modules>
                    <your_module after="Mage_Adminhtml">Your_Module</your_module >
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.