I'm a newbie on Joomla developing and I'm trying to fix an old administration module made by 'someone before me'. Module's been developed using MVC Components, it has several CRUDs and I'm stucked at deleting an item. The template view adds the toolbar icon like this:
JToolbarHelper::deleteList('', 'paises.delete', JTOOLBAR_DELETE);
It also has at the list controller (DistribuidoresControllerPaises), the getModel function:
public function getModel($name = 'Pais', $prefix = 'DistribuidoresModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
The model class:
class DistribuidoresModelPais extends JModelAdmin
When selecting an item on the list, and clicking the trash button an empty page opens with this ending:
administrator/index.php?option=com_distribuidores&view=pais
If I come back to grid, the item still remains.
Any suggestion?
Thanks in advance
You can debug this by enabling debugging from Joomla configuration or you can try to to check with exit with in "delete" function of "paises" controller and can check you get item ids in post request or not.
Also you are using view "pais" also using model "pais" then why you are using "paises" controller for delete function, you should use "pais" controller to delete.
Also provide delete function which you are using to delete items, it may contain some issue.
Related
Our site is based on Magento 1.
We installed Mega menu extension which purchased from magestore team.
But, when we click the catalog/Manage categories on backend admin setting, we got this error.
How to solve this issue?
**There has been an error processing your request**
Source model "megamenu/menutype" not found for attribute "menutype"
/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php(386): Mage::exception('Mage_Eav', 'Source model "m...')
/app/code/core/Mage/Adminhtml/Block/Widget/Form.php(201): Mage_Eav_Model_Entity_Attribute_Abstract->getSource()
app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php(113): Mage_Adminhtml_Block_Widget_Form->_setFieldset(Array, Object(Varien_Data_Form_Element_Fieldset))
...
screenshot of error page
This issue was solved successfully.
Menutype was conflicted by old one.
We had used Peerforest_Megamenu extension on our site. Although we disabled the old mega menu extension, but this attribute was remained on our database.
So, when we installed new extension whose name is Magestore mega menu extension, that issue was occurred.
Furthermore. Peerforest_Megamenu had created some new attribute like megamenu/menutype on category table and these attribute required a model source to display the options.
When we disabled Peerforest_Megamenu, they couldn't find the their model source anymore.
I just created some new model source files for those attributes.
This is new menu type code block.
<?php
class Magestore_Megamenu_Model_Menutype extends
Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
protected $_options = array();
public function getAllOptions()
{
$this->_options[] = array('value' => 'megamenu-horizontal','label' => 'Mega Menu');
$this->_options[] = array('value' => 'megamenu-vertical','label' => 'Vertical');
return $this->_options;
}
}
Hope my answer will help others.
Thank you for your consideration.
Regards.
This is my first experience with Laravel, and so far I'm having some difficulties passing data to views. My app is a single page website with one menu on the top listing all the product categories and below there is a grid of thumbnails for each item or product. Visitors are able to filter the products by their category of choice.
Route::get('home/{category}', array('as'=>'itemshome', 'uses'=>'ItemsController#index'));
So in my ItemsControllers I fetch some items from the item model and pass them to the view.
class ItemsController extends \BaseController {
public function index($category)
{
return View::make('home/index', ['items' => Item::where('publishtime', '<',
date('Y-m-d H:i:s'))->where('category_id','=',$category)->paginate(24)]);
}
At this point I'm not sure if I should send data from the Category model to the home view using the ItemsController, or if it would it be a better approach to define a new CategoryController and pass the values from there.
You can't just use another controller to send data to the same view during the same request.
Either add it to the view make call:
return View::make('home/index', [
'items' => Item::where('publishtime', '<', date('Y-m-d H:i:s'))->where('category_id','=',$category)->paginate(24),
'categories' => Category::all()
];
Or, if the category data actually has nothing to do with the items controller but is needed by the view, you could register a view composer
View::composer('home/index', function($view){
$view->with('categories', Category::all());
});
Now every time when the home/index view gets rendered, categories will be injected.
You can actually place the view composer anywhere you want. However I recommend you add a new file app/composers.php to store all your view composers. Then you need to include it somewhere. For example in app/start/global.php at the bottom:
require app_path().'/composers.php';
I'm going through the Joomla 2.5 tutorial to build a custom component. Now I'm facing an issue on the redirection after using JToolbar::save() or JToolBarHelper::cancel for that matter. By default Joomla wants to redirect to the default layout (from the edit layout). However I don't want it to do that. I want it to redirect back to another view. In Joomla 1.5 I would have done this through adding the function into the controller - something like
function cancel()
{
//redirects user back to blog homepage with Cancellation Message
$msg = JText::_( 'COM_BLOG_POST_CANCELLED' );
$this->setRedirect( 'index.php?option=com_jjblog&view=jjblog', $msg );
}
Now that works beautifully for the cancel function, however for save this is a much more complex thing. If I want to overwrite the url do I have to redirect the controller to the model and then write in all the code for the model interaction? Because that seems slightly excessive just for a url redirection like you would in Joomla 1.5?
Hope you have added the save toolbar code with the proper controller name like this
JToolBarHelper::save('controllerName.save');
Create a save function in appropriate controller.
Add the task in the form
Finnally make sure you have added form action withthe corresponding component name.
You can try this-
In the controller firstly you call the parent save function than redirect to url.
function save(){
parent::save();
$this->setredirect('index.php?option=com_mycomponent');
}
OK it didn't need to $this->setRedirect at all. Just needed me to change the value to
protected $view_list = 'jjBlog';
which then sets the redirects of everything back to that list view.
Source link for this is here.
Thanks for all the responses though!!
view.html.php
protected function addToolbar ()
{
JRequest::setVar ('hidemainmenu', false);
JToolBarHelper::title (JText::_ ('Configuration'), 'configuration.gif');
JToolBarHelper::save($task = 'save', $alt = 'JTOOLBAR_SAVE');
}
controller.php
public function save()
{
$mainframe = JFactory::getApplication();
$mainframe->enqueueMessage (JText::_ ('COM_SOCIALLOGIN_SETTING_SAVED'));
$this->setRedirect (JRoute::_ ('index.php', false));
}
I think you can use
global $mainframe;
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
If you are overriding joomla's default save function in your custom component like
function save( $task = 'CustomSave', $alt = 'Save' ) // or even same name Save
Inside your controller you can use the CustomSave as the task and use $mainframe for redirect.
or
$mainframe = &JFactory::getApplication();
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
Hope this may help you..
I have created a module in "Magento"in this module I have successfully added mutiple tab as tab appear on product page when we add a product(ex.general,inventory).
In my module I want to apply a feature on selected products.for this I want to show product listing as it as appear when we click on related product (When we add new product).
For this I did the same coding as it is on catalogue controller.
But still there is a error occur.
I have added following code on my controller page
public function relatedAction()
{
$gridBlock = $this->getLayout()->createBlock('customoption/adminhtml_edit_tab_related')
->setGridUrl($this->getUrl('*/*/gridOnly', array('_current' => true, 'gridOnlyBlock' => 'related')));
$iTemplateId = $this->getRequest()->getParam('template_id');$product2tpl = Mage::getResourceModel('customoption/customoption');
$productsArray = $product2tpl->getTemplateProducts($iTemplateId);
$serializerBlock = $this->_createSerializerBlock('links[related]', $gridBlock, $productsArray);
$this->_outputBlocks($gridBlock, $serializerBlock);
}
I have also extend the class Mage_Adminhtml_Controller_Action and following error occure when click on related tab.
"Call to a member function setGridUrl() on a non-object"
Please guide me where i am wrong.
Thanks in advance.
I need to create module in Magento which will have few database tables. One of the function of the module is adding multiple images.
For example while being on the "Add new item" or "Edit item" page in the admin, from the left side I have tabs, one of them is "Item Images". When being clicked I want the content of this tab to be my own custom one.
After digging into the code, found out that the way it renders this content, Magento is using one of the Varien_Data_Form_Element classes for each element in the full form. I want to add my own class here that will render form elements the way I want.
Is this a good practice to do so, or there is some other more elegant way of adding own content in the admin forms?
EDIT: I must add that none of the existing classes is helping my problem.
SOLUTION EDIT:
I have a controller in my custom module that is in Mypackage/Mymodule/controllers/Adminhtml/Item.php. In the editAction() method which I am using for adding and creating new items, I am creating 2 blocks, one for the form and one left for the tabs:
$this->_addContent($this->getLayout()->createBlock('item/adminhtml_edit'))
->_addLeft($this->getLayout()->createBlock('item/adminhtml_edit_tabs'));
$this->renderLayout();
The Block/Adminhtml/Edit/Tabs.php block is creating 2 tabs on the left: General Info and Item Images, each of them are rendering different content on the right side using Block classes.
protected function _beforeToHtml()
{
$this->addTab('item_info', array(
'label' => Mage::helper('mymodule')->__('Item Info'),
'content'=> $this->getLayout()->createBlock('item/adminhtml_edit_tab_form')->toHtml(),
));
$this->addTab('item_images', array(
'label' => Mage::helper('mymodule')->__('Item Images'),
'active' => ( $this->getRequest()->getParam('tab') == 'item_images' ) ? true : false,
'content' => $this->getLayout()->createBlock('item/adminhtml_images')->toHtml(),
));
return parent::_beforeToHtml();
}
I wanted the tab item_images to render my own form elements and values, not the default varien form elements.
class Mypackage_Mymodule_Block_Adminhtml_Images extends Mage_Core_Block_Template
{
public function __construct()
{
parent::__construct();
$this->setTemplate('item/images.phtml'); //This is in adminhtml design
}
public function getPostId()
{
return $this->getRequest()->getParam('id');
}
public function getExistingImages()
{
return Mage::getModel('mymodule/item')->getImages($this->getPostId());
}
}
Then in the template app/design/adminhtml/default/default/template/item/images.phtml you can use these values:
//You can add your own custom form fields here and all of them will be included in the form
foreach($this->getExistingImages() as $_img):
//Do something with each image
endforeach;
//You can add your own custom form fields here and all of them will be included in the form
No, it's not. You should never edit or add to files that provided by a vendor. If you absolutely must replace a class file you should use the local code pool. For example, if you wanted to change the behavior of a text field,
lib/Varien/Data/Form/Element/Text.php
You should place a file in the local or community code pool
app/code/local/Varient/Data/Form/Element/Text.php
However, doing the replaces the class, and it becomes your responsibility to maintain compatibility with future versions. That means if Magento Inc. changes lib/Varien/Data/Form/Element/Text.php, you need to update your version to be compatible.
Based on what you said I'd look into creating a class rewrite for the Block class that renders the form.