Вопрос

Я использую Magento 1.8.1.0 Community Edition.

Мне удалось добавить пользовательский контроллер администратора, а метод индексации () по умолчанию работает. Однако, если я попытаюсь получить доступ к другому способу, другому, другому перенаправленному на приборную панель администратора.

Обменные имена методов работает, поэтому я не думаю, что есть какие-либо проблемы с кодом в другом методе, и кэширование было выключено.

Обеспокоенные 2 URL:

Я сделал немного копания и обнаружил, что запрос на / другое действие выполнено с перенаправлением 302 на приборную панель администратора.

Любые указатели на то, что может быть проблема?

В основном я пытаюсь добавить новый контроллер с 2 действиями в качестве новой администратора. Я не хочу меняться / переопределять текущую функцию.

Спасибо заранее!

<?

class Printo_CategoryAttribute_IndexController extends Mage_Adminhtml_Controller_Action
{
    private $filepath = 'var/import/latest_categories.csv'; // location of file

    public function indexAction()
    {   
        $category = Mage::getModel ('catalog/category');
        $tree = $category->getTreeModel ();
        $tree->load ();
        $ids = $tree->getCollection()->getAllIds();

        if ($ids)
    {
       mkdir('var/import');
       file_put_contents($this->filepath,"Category ID, Category Name" . PHP_EOL);

           foreach ( $ids as $id )
           {
               $string = $id . ', ' .$category->load($id)->getName() . PHP_EOL;
               file_put_contents($this->filepath,$string,FILE_APPEND);
            }

           $x = print_r(get_class_methods($this),TRUE);
       $this->loadLayout();
           //create a text block with the name of "printo-block"
           $block = $this->getLayout()
           ->createBlock('core/text', 'printo-block')
           ->setText("<h1><a href ='/category_info/index/download'>Download</a></h1><h2><pre>$x</pre></h2>");

           $this->_setActiveMenu('printo_menu/category_info');  

           $this->_addContent($block);
           $this->renderLayout();
        }
    }


    public function downloadAction()
    {
/*            
           $this->getResponse()
                    ->setHttpResponseCode(200)
                    ->setHeader('Content-Type', 'text/csv', TRUE)
                    ->setHeader('Content-Length', filesize($this->filepath), TRUE)
                    ->setHeader('Content-Disposition', 'attachment; filename="latest_categories.csv"', TRUE);
           $this->getResponse()->clearBody();
           $this->getResponse()->sendHeaders();
           readfile($this->filepath);

           $this->loadLayout();
           //create a text block with the name of "printo-block"
           $block = $this->getLayout()
           ->createBlock('core/text', 'printo-block')
           ->setText("<h1>YAY IT WORKS!</h1>");
           $this->_setActiveMenu('printo_menu/category_info');
           $this->_addContent($block);
           $this->renderLayout();
*/
       $fileName ='Category Info.csv';
       $this->_prepareDownloadResponse($filename, file_get_contents($this->filepath));
     }

}


?>
.

Вот конфигурация .xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Printo_CategoryAttribute>
            <version>0.0.1</version>
        </Printo_CategoryAttribute>
    </modules>

    <admin>
        <routers>
            <Printo_CategoryAttribute_Admin_Page>
                <use>admin</use>
                <args>
                    <module>Printo_CategoryAttribute</module>
                    <frontName>category_info</frontName>
                </args>
            </Printo_CategoryAttribute_Admin_Page>
        </routers>
    </admin>

   <adminhtml>
        <menu>
            <printo_menu translate="title" module="CategoryAttribute">
                <title>Printo</title> 
                <sort_order>5000</sort_order>
                <children>
                    <category_info module="CategoryAttribute">
                        <title>Category Info</title> 
                        <action>category_info/index/index</action>
                    </category_info>
                </children>
            </printo_menu>
        </menu> 
    </adminhtml>

    <global>

    <helpers>
        <CategoryAttribute>
            <class>Printo_CategoryAttribute_Helper</class>
        </CategoryAttribute>
    </helpers>

    <resources>
            <add_category_attribute>
                <setup>
        <module>Printo_CategoryAttribute</module>
        <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </add_category_attribute>
            <add_category_attribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </add_category_attribute_write>
            <add_category_attribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </add_category_attribute_read>
    </resources>
    </global>

</config>
.

Это было полезно?

Решение

Я выяснил, какова была проблема.Вам нужно использовать:

$url = $this->getUrl('category_info/index/download');
.

Чтобы получить полный URL, включая ключ, используемый для аутентификации текущего зарегистрированного сеанса.

Результатом этого является то, что вы получите ссылку, как так

http://dev.printo.in/index.php/category_info/index/download/key/4745379c10d9a5fa01bb4bb4645b59bc/
.

раньше я просто использую catechation_info / index / download, и это не будет работать.

Другие советы

Если вы добавите этот пользовательский контроллер администратора

Использование Rewrite Admicontroller:

Тогда это должно быть

SiteUrl/admin/index/index
.

всякий раз, когда переписать как

<admin>
<routers>
    <adminhtml>
    <args>
        <modules>
        <Printo_CategoryAttribute before="Mage_Adminhtml">Printo_CategoryAttribute</Printo_CategoryAttribute>
        </modules>
    </args>
    </adminhtml>
</routers>
</admin>
.

Согласно SiteanmeUrl/admin/controllername/ActionName

.see / a>

Использование базового URL-адреса admin определяет:

Если http://dev.printo.in/index.php/category_info/ index / index Работа при включении конфигурации администратора

как

<admin>
<routers>
    <customadmin>
    <use>admin</use>
    <args>
        <module>Printo_CategoryAttribute</module>
        <frontName>category_info</frontName>
    </args>
    </category_info>
</routers>
</admin>
.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top