class LC_News_Helper_Data extends Mage_Core_Helper_Abstract {
}
?>
At this point, all this does is create a menu item called News and a sub-menu item called Manage News. If you click on it, it will show the items.phtml file and highlight the News menu item as active (impressive I know ). Now this is where I run into trouble trying to expand it. I would like to create a Block that is called using the Grid Widget.
/LC/News/Block/Adminhtml/News.php
<?php
class LC_Adminhtml_Block_News_News extends Mage_Adminhtml_Block_Widget_Grid_Container { public function __construct() { $this->_controller = 'items'; $this->_headerText = Mage::helper('news')->__('News Manager'); $this->_addButtonLabel = Mage::helper('news')->__('Add News Item'); parent::__construct(); } }
And this is the error that I end up with:
Fatal error: Cannot redeclare class LC_Adminhtml_Block_News_News in C:\xampp\htdocs\magento\app\code\local\LC\News\Block\Adminhtml\News.php on line 14
This is great work people, thanks for the help. I had gotten a couple hours into doing this without guidance before I found this post.
I’m interested though in knowing how you know all of this. I just can’t seem to follow the directory structure, naming conventions, etc well enough yet to really set out on the several modules we need to build from scratch - a blog being one of them.
I keep thinking there’s some great resource out there I don’t know about but i’ve been pretty much everywhere on this site.
Or could it be having trouble finding the grid widget since I am doing this outside of the Mage namespace?
@JWoods
There isn’t really any resource out there, the best so far has been the PHP|Architect book but even that is fairly incomplete but at least it is a start. Magento has a high learning curve for learning the architecture and it can be very challenging. Really I just kept at it until I figured out enough and was a lot of trial and error. I am trying to figure out as much as I can and get it up here for others.
public function indexAction() { $this->loadLayout(); $this->_setActiveMenu('news/items'); $this->_addContent($this->getLayout()->createBlock('news/adminhtml_news')); $this->renderLayout(); }
And that is calling the right block, obviously if I take that out then it just pulls in the news.phtml file in the design section of adminhtml.
No matter what change I make to the the class definition it does not want to work and just gives the “Cannot redeclare class error”. I am about to duplicate this module and change all LC references to Mage (in a corresponding Mage directory under local) to see if maybe the namespace is causing a problem.
/LC/News/Block/Adminhtml/News.php
<?php
class LC_News_Adminhtml_Block_News extends Mage_Adminhtml_Block_Widget_Grid_Container {
public function __construct() { $this->_controller = 'items'; $this->_headerText = Mage::helper('news')->__('News Manager'); $this->_addButtonLabel = Mage::helper('news')->__('Add News Item'); parent::__construct(); }
}
Any thoughts?
EDIT: Nope not a namespace issue, I changed everything to Mage and it still gave the same error.
Ok, after banging my head against the wall forever it was a simple change. It doesn’t make sense why this works and it could be a bug, but it will let me redeclare the class when I change around the class declaration.
This:
class LC_News_Adminhtml_Block_News extends Mage_Adminhtml_Block_Widget_Grid_Container
To this:
class LC_News_Block_Adminhtml_News extends Mage_Adminhtml_Block_Widget_Grid_Container
-Adam
P.S. I am going as fast as I can, but many more bugs to work out. I will keep this updated as I go.
Thank you, I appreciate the words of encouragement. I know how much time it takes to answer all these questions, especially with the work load you guys have. Any little bit is appreciated and I am glad that I can help take a bit of work off of your guy’s shoulders and give back.
Fatal error: Call to a member function setSaveParametersInSession() on a non-object in C:\xampp\htdocs\magento\app\code\core\Mage\Adminhtml\Block\Widget\Grid\Container.php on line 53
Most likely related to this code in /app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php in _prepareLayout:
I would assume this is because I am missing a required file and it is related to the controller. Would I need a NewsControllerGrid.php or something like that?
Here is my News.php Block:
<?php
class LC_News_Block_Adminhtml_News extends Mage_Adminhtml_Block_Widget_Grid_Container {
public function __construct() { $this->_controller = 'news'; $this->_headerText = Mage::helper('news')->__('News Manager'); $this->_addButtonLabel = Mage::helper('news')->__('Add News'); parent::__construct(); }
I just noticed that and I did a var_dump on $this. It looks like if nothing is entered for _controller or _blockGroup it defaults to adminhtml/empty_grid. If I set _controller = ‘ news’ then I will get adminhtml/news_grid and this doesn’t exist with _grid.
Would I have to change block group and controller?