I'm try to access the index action of frontend index controller but it redirect to home page.
When I'm try to access index action it redirect to home page.
My extension code in community.
Note: The code is working fine on local on windows OS But when these code is upload on linux server it's not working
Below is my Code & files path:
IndexController.php
Path:`app/code/community/Magentostudy/News/controllers/IndexController.php`
<?php
/**
* News frontend controller
*
* @author Magento
*/
class Magentostudy_News_IndexController extends Mage_Core_Controller_Front_Action
{
/**
* Pre dispatch action that allows to redirect to no route page in case of disabled extension through admin panel
*/
public function preDispatch()
{
parent::preDispatch();
if (!Mage::helper('magentostudy_news')->isEnabled()) {
$this->setFlag('', 'no-dispatch', true);
$this->_redirect('noRoute');
}
}
/**
* Index action
*/
public function indexAction()
{ die('kailas');
$this->loadLayout();
$listBlock = $this->getLayout()->getBlock('news.list');
if ($listBlock) {
$currentPage = abs(intval($this->getRequest()->getParam('p')));
if ($currentPage < 1) {
$currentPage = 1;
}
$listBlock->setCurrentPage($currentPage);
}
$this->renderLayout();
}
/**
* News view action
*/
public function viewAction()
{
$newsId = $this->getRequest()->getParam('id');
if (!$newsId) {
return $this->_forward('noRoute');
}
/** @var $model Magentostudy_News_Model_News */
$model = Mage::getModel('magentostudy_news/news');
$model->load($newsId);
if (!$model->getId()) {
return $this->_forward('noRoute');
}
Mage::register('news_item', $model);
Mage::dispatchEvent('before_news_item_display', array('news_item' => $model));
$this->loadLayout();
$itemBlock = $this->getLayout()->getBlock('news.item');
if ($itemBlock) {
$listBlock = $this->getLayout()->getBlock('news.list');
if ($listBlock) {
$page = (int)$listBlock->getCurrentPage() ? (int)$listBlock->getCurrentPage() : 1;
} else {
$page = 1;
}
$itemBlock->setPage($page);
}
$this->renderLayout();
}
}
Config.xml
Path: app/code/community/Magentostudy/News/etc/config.xml
<?xml version="1.0"?>
<!--
/**
* Module configuration
*
* @author Magento
*/
-->
<config>
<modules>
<Magentostudy_News>
<version>1.0.0.0.1</version>
</Magentostudy_News>
</modules>
<global>
<models>
<magentostudy_news>
<class>Magentostudy_News_Model</class>
<resourceModel>news_resource</resourceModel>
</magentostudy_news>
<news_resource>
<class>Magentostudy_News_Model_Resource</class>
<entities>
<news>
<table>magentostudy_news</table>
</news>
</entities>
</news_resource>
</models>
<helpers>
<magentostudy_news>
<class>Magentostudy_News_Helper</class>
</magentostudy_news>
</helpers>
<blocks>
<magentostudy_news>
<class>Magentostudy_News_Block</class>
</magentostudy_news>
</blocks>
<resources>
<magentostudy_news_setup>
<setup>
<module>Magentostudy_News</module>
<class>Mage_Core_Model_Resource_Setup</class>
</setup>
</magentostudy_news_setup>
</resources>
<events>
<before_news_item_display>
<observers>
<magentostudy_news>
<class>magentostudy_news/observer</class>
<method>beforeNewsDisplayed</method>
</magentostudy_news>
</observers>
</before_news_item_display>
</events>
</global>
<frontend>
<routers>
<magentostudy_news>
<use>standard</use>
<args>
<module>Magentostudy_News</module>
<frontName>news</frontName>
</args>
</magentostudy_news>
</routers>
<layout>
<updates>
<magentostudy_news>
<file>magentostudy_news.xml</file>
</magentostudy_news>
</updates>
</layout>
</frontend>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Magentostudy_News before="Mage_Adminhtml">Magentostudy_News_Adminhtml</Magentostudy_News>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<magentostudy_news>
<file>magentostudy_news.xml</file>
</magentostudy_news>
</updates>
</layout>
</adminhtml>
<default>
<news>
<view>
<enabled>1</enabled>
<items_per_page>20</items_per_page>
<days_difference>3</days_difference>
</view>
</news>
</default>
</config>
magentostudy_news.xml (Layout XML)
Path: app/design/frontend/base/default/layout/magentostudy_news.xml
<?xml version="1.0"?>
<!--
/**
* Magento frontend layout
*
* @author Magento
*/
-->
<layout version="0.1.0">
<default>
<reference name="footer_links">
<action method="addLink" translate="label title" module="magentostudy_news" ifconfig="news/view/enabled">
<label>News</label>
<url>news</url>
<title>News</title>
<prepare>true</prepare>
</action>
</reference>
</default>
<magentostudy_news_index_index translate="label">
<label>News Page</label>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-right.phtml</template>
</action>
<action method="setHeaderTitle" translate="title" module="magentostudy_news">
<title>Site News</title>
</action>
</reference>
<reference name="content">
<block type="magentostudy_news/list" name="news.list" template="magentostudy/news/list.phtml">
<block type="page/html_pager" name="news.list.pager" as="news_list_pager" />
</block>
</reference>
</magentostudy_news_index_index>
<magentostudy_news_index_view translate="label">
<label>News Item Page</label>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-right.phtml</template>
</action>
</reference>
<reference name="content">
<block type="magentostudy_news/item" name="news.item" template="magentostudy/news/item.phtml" />
</reference>
</magentostudy_news_index_view>
</layout>
Magentostudy_News.xml (enable module)
Path: app/etc/modules/Magentostudy_News.xml
<?xml version="1.0"?>
<!--
/**
* Module initial config
*
* @author Magento
*/
-->
<config>
<modules>
<Magentostudy_News>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Adminhtml />
</depends>
</Magentostudy_News>
</modules>
</config>
list.phtml (template phtml file)
Path:app/design/frontend/base/default/template/magentostudy/news/list.phtml
<?php
/**
* News template for items list
*
* @author Magento
*/
/**
* @var $this Magentostudy_News_Block_List
* @see Magentostudy_News_Block_List
*/
?>
<div id="news_list_messages"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="page-title">
<h1><?php echo Mage::helper('magentostudy_news')->__('Site News') ?></h1>
</div>
<div class="news_list_view">
<?php foreach ($this->getCollection() as $newsItem): ?>
<div id="item_<?php echo $newsItem->getId() ?>" class="news_list_item">
<h2>
<a href="<?php echo $this->getItemUrl($newsItem) ?>">
<?php echo $this->escapeHtml($newsItem->getTitle()) ?>
</a>
</h2>
<div class="news_item_subtitle">
<?php echo $this->formatDate($newsItem->getTimePublished(), 'medium') ?> |
<?php echo $this->escapeHtml($newsItem->getAuthor()) ?>
</div>
<?php if ($imageUrl = $this->getImageUrl($newsItem, 100)): ?>
<p><img src="<?php echo $imageUrl ?>" alt="<?php echo $this->escapeHtml($newsItem->getTitle()); ?>" /></p>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php echo $this->getPager() ?>