The goal should be following:
I have an edit view with a custom field (dropdown) that depends on another table. There I can choose from a list of adresses (the second table) to save the id of the data row. I started with this:
Custom field code:
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
JHTML::_('behavior.modal');
class JFormFieldInvoiceAdress extends JFormFieldList
{
protected $type = 'invoiceadress';
protected function getInput() {
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id,zip,city,adress');
$query->from('#__pb_invoiceadresses');
$db->setQuery((string)$query);
$types = $db->loadObjectList();
$options = array();
foreach($types as $type) {
$options[] = JHTML::_('select.option', $type->id, $type->zip . " " . $type->city . ", " .$type->adress);
}
$dropdown = JHTML::_('select.genericlist', $options, $this->name, 'class="inputbox"', 'value', 'text', $this->value);
$link = 'index.php?option=com_mycomponent&view=invoiceadresseedit&layout=edit&id=0';
$dropdown .= "<a href=\"" . JRoute::_($link) . "\" class=\"modal\" rel=\"{handler: 'iframe', size: {x: 875, y: 550}, onClose: function() {}}\" >Neue Adresse</a>";
return $dropdown ;
}
}
This works so far but I have to update the content of the dropdown on closing this modal window and not getting the list view of the invoiceadresses in the modal window.
My second attempt was to add 'tmpl=component' in the link but then I don't have a save button. I have no idea how to accomplish that. Anyone have already solved this?
Found the solution and I am answering it for the next person who comes along with the same question.
Call the edit view with this link:
$link = 'index.php?option=com_mycomponent&view=invoiceadresseedit&layout=edit&id=0&tmpl=component';
This will display only the form without the rest of the administration gui and toolbar.
Add a save button to your edit form like this:
<input class="button" type="submit" value="<?php echo JText::_('SAVE');?>" onClick="window.parent.location.reload();" />
And thats it. The data will be saved and after this the modal windows closes and the current page reloads, the dropdown will be updated with the new data.
Related
First step - create a new a Gallery (Name and Type).
Click 'Next' button.
Second step - upload multiple images to that gallery.
What can I do in order to achieve that in Laravel Nova admin panel? I can't follow documentation and just add HasMany::make('Images') to a Gallery resource, I need a two steps form.
If I understand right first step you need to make from view input <input type="file" multiple>
than send request and in your controller you need something like this:
$date = Carbon::now()->format('Y-m-d-hh-mm-ss');
$files = request('images');
$pluss = 1;
foreach ($files as $file) {
$imageName = $date . '.' . $pluss . $file->getClientOriginalExtension();
$file->move(public_path('/images/products'), $imageName);
$pluss++;
$data = [
'image' => $imageName,
'product_id' => $product->id
];
Image::create($data);
}
I want to show filter of category on submenu, my code works!!
My problem is that if page are already filtered, my code does not return the options
I believe it has to do something in the code that bypasses the filter page and again bring the options in the submenu even if already have the filter on page
HTML of submenu:
{{block type="core/template" category="3" template="page/html/icons_submenu.phtml"}}
Content of page icons_submenu.phtml:
<?php
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel('catalog/category')->load($this->getCategory());
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'color') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
echo '<strong>Color:</strong><br />';
foreach($result->getItems() as $option) {
echo ' ' . $option->getValue() . ' - ' . $option->getLabel() . '<br />';
}
}
}
?>
Example:
I would really suggest you to actually move all that logic into a proper module, a proper block and a proper model and not in a template like you are doing right now.
If you actually want further help for that, feel free to ask, making something according to the coding guide lines of Magento would make you even happier of your job, I can assure you.
This being said, what you actually want is a current filter model based on the current category and a specify attribute.
You don't need to go by the block catalog/layer_filter_attribute in a way to do this, you can directly go by the model based on the layer you already load.
So, this way of doing it should work, although it should not be in a template or view, once again :
<?php
$category = Mage::getModel('catalog/category')
->load($this->getCategory());
$layer = Mage::getModel('catalog/layer')
->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'color') {
// $filterBlockName = 'catalog/layer_filter_attribute';
/** This is actually your only problem in your code **/
// $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
/** But would work with this line **/
$result = Mage::getModel('catalog/layer_filter_attribute')
->setLayer($layer)
->setAttributeModel($attribute);
echo '<strong>Color:</strong><br />';
foreach($result->getItems() as $option) {
echo ' ' . $option->getValue() . ' - ' . $option->getLabel() . '<br />';
}
}
}
?>
Then you can see it still works based on only the colours I have in the current category
But also when the category is already filtered on a specific colour
Looking for a way to add a description field to invididual attribute values in Magento. Please note I'm referring to Attribute Value options, not the actual Attribute itself.
As an example:
Attribute = colour
Attribute values:
Red, Green, Blue
I want to add a description field for each of the 3 colours (1 for Red, 1 for Green, 1 for Blue). The purpose of this is to show a tooltip on the frontend to give more information about each colour option.
Does anyone know how to do this? There are lots of solutions round which apply to the Attribute itself (colour) but not the individual options (Red, Green, Blue).
The descriptions should be editable from within the Admin panel. I don't want a solution which relies on editing these straight in the database using, for example, phpMyAdmin.
I understand that the values are stored in the 'eav_attribute_option_value' table and that a further column may be needed to store the Description. No idea how to get all that set up in the Admin panel. Ideas?
EDIT: I've added a screenshot of where the Description text would need adding. So next to each colour (on the screenshot: Black, Blue, Green, Grey, Red, White, etc) - each one needs to have a description next to it.
This maybe 11 months out of date, but for anyone else having this problem then perhaps this can assist you. I hope it will save you from the hours of head banging against a wall like myself and my colleague experienced. For my purpose, I was trying to create an Image URL field for Magento version 1.9 to support a product migration from an older platform.
This answer has been partially answered here - Creating new options for Magento attributes but there are some extra things I had to figure out:
1.) This answer assumes you have created your own module (if you do not know how then start here: http://www.smashingmagazine.com/2012/03/01/basics-creating-magento-module/)
2.) It also leaves you to create the extra fields in catalog/product/attribute/options.phtml yourself. But to save you time here are the amendments I made to to get it to appear in the admin. Create a new table head option on line 88:
<th><?php echo Mage::helper('catalog')->__('YOUR_ATTRIBUTE_NAME_HERE') ?></th>
Next create a new td on line 101:
<td class="a-left"><input class="input-text" type="text" name="option[YOUR_ATTRIBUTE_NAME_HERE][{{id}}]" value="{{TABLE_COLUMN_NAME_HERE}}" <?php if ($this->getReadOnly()):?> disabled="disabled"<?php endif;?>/></td>
And also, most of the logic is done in Javascript so we need to replicate the field here on line 126:
'<td><input class="input-text" type="text" name="option[YOUR_ATTRIBUTE_NAME_HERE][{{id}}]" value="{{TABLE_COLUMN_NAME_HERE}}" <?php if ($this->getReadOnly()):?> disabled="disabled"<?php endif;?>/><\/td>'+
3.) The longest part for me was creating the custom logic for _saveOption method. I overrode the parent class, but to save you the trouble here is my logic:
protected function _saveOption(Mage_Core_Model_Abstract $object)
{
$option = $object->getOption();
if (is_array($option)) {
$adapter = $this->_getWriteAdapter();
$optionTable = $this->getTable('eav/attribute_option');
$optionValueTable = $this->getTable('eav/attribute_option_value');
$stores = Mage::app()->getStores(true);
if (isset($option['value'])) {
$attributeDefaultValue = array();
if (!is_array($object->getDefault())) {
$object->setDefault(array());
}
foreach ($option['value'] as $optionId => $values) {
$intOptionId = (int) $optionId;
if (!empty($option['delete'][$optionId])) {
if ($intOptionId) {
$adapter->delete($optionTable, array('option_id = ?' => $intOptionId));
}
continue;
}
$sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
$imgUrl = !empty($option['image_url'][$optionId]) ? $option['image_url'][$optionId] : 0;
if (!$intOptionId) {
$data = array(
'attribute_id' => $object->getId(),
'sort_order' => $sortOrder,
'image_url' => $imgUrl
);
$adapter->insert($optionTable, $data);
$intOptionId = $adapter->lastInsertId($optionTable);
} else {
$data = array('sort_order' => $sortOrder, 'image_url' => $imgUrl);
$where = array('option_id =?' => $intOptionId);
$adapter->update($optionTable, $data, $where);
}
if (in_array($optionId, $object->getDefault())) {
if ($object->getFrontendInput() == 'multiselect') {
$attributeDefaultValue[] = $intOptionId;
} elseif ($object->getFrontendInput() == 'select') {
$attributeDefaultValue = array($intOptionId);
}
}
// Default value
if (!isset($values[0])) {
Mage::throwException(Mage::helper('eav')->__('Default option value is not defined'));
}
$adapter->delete($optionValueTable, array('option_id =?' => $intOptionId));
foreach ($stores as $store) {
if (isset($values[$store->getId()])
&& (!empty($values[$store->getId()])
|| $values[$store->getId()] == "0")
) {
$data = array(
'option_id' => $intOptionId,
'store_id' => $store->getId(),
'value' => $values[$store->getId()]
);
$adapter->insert($optionValueTable, $data);
}
}
}
$bind = array('default_value' => implode(',', $attributeDefaultValue));
$where = array('attribute_id =?' => $object->getId());
$adapter->update($this->getMainTable(), $bind, $where);
}
}
return $this;
}
My custom field was named image_url so I added it to the $data variable to be inserted. This will insert values into the column "image_url" of the eav_attribute_option table, but you can manipulate it to store in eav_attribute_option_value in the same method.
4.) For some reason that stack overflow post stated that this _saveOption method would be fired on save but mine was not, therefore I also overrode the _afterSave method in the same class which looks like this:
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$this->_clearUselessAttributeValues($object);
$this->_saveStoreLabels($object)
->_saveAdditionalAttributeData($object)
->saveInSetIncluding($object)
->_saveOption($object);
return $this;
}
5.) Now it will attempt to save your new value. But it will cause an error since your custom table column most likely doesn't exist yet. You are welcome to create this manually if it is appropriate for you. Unfortunately I needed to create this programmatically for my situation, so for those of you in the same boat (this is a slightly unclean approach) but for speed I re-routed the app/code/core/Mage/Core/Model/Resource/Setup.php by creating the local revision here: app/code/local/Mage/Core/Model/Resource/Setup.php and add this to line 154 in the constructor class:
$installer = $this;
$installer->getConnection()->addColumn($installer->getTable('eav/attribute_option'), 'YOUR_COLUMN_NAME_HERE', 'VARCHAR(256) NULL');
$installer->endSetup();
6.) Okay, everything should now be saving to the database, but we still need to read the value into our <td> - this had me stumped for a while, but figured out that the Javascript is responsible for replacing the {{id}} and {{sort_order}} tags in the HTML on line 230. Therefore we need to add our new column to this getOptionsValues() method. I added the following code in on line 70 of catalog/product/attribute/options.phtml:
<?php foreach ($this->getOptionValues() as &$val) {
$imgUrl = $this->getImageUrl($val->id);
if ($imgUrl != "0") {
$val->_data["YOUR_TABLE_COLUMN_NAME_HERE"] = $imgUrl;
}
} ?>
Then, in your YOUR_MODULE_Block_Adminhtml_Options class add the method getImageUrl() that the above calls:
/**
* Retrieve results from custom column
*
* #return Mage_Core_Model_Mysql4_Store_Collection
*/
public function getImageUrl($option_id)
{
//Get the resource model
$resource = Mage::getSingleton('core/resource');
//Retrieve the read connection
$readConnection = $resource->getConnection('core_read');
//Retrieve our table name
$table = $resource->getTableName('eav/attribute_option');
$query = 'SELECT ' . $this->custom_col . ' FROM ' . $table . ' WHERE option_id = '
. (int)$option_id . ' LIMIT 1';
//Execute the query and store the result
$imgUrl = $readConnection->fetchOne($query);
return $imgUrl;
}
And there you have it. I really hope that this helps anyone in a similar situation.
Try this out
By default Magneto only provide custom options without any description, if you want to customize with description then you must change in following files:
Step 1:-
In File
app\design\adminhtml\default\default\template\catalog\product\edit\option\type\select.phtml
Find the below code:
'<th class="type-sku"><?php echo Mage::helper('catalog')->__('SKU') ?></th>'+
Add these after just after
'<th class="type-description"><?php echo Mage::helper('catalog')->__('Description') ?></th>'+
Find the below code:
'<td><input type="text" class="input-text" name="product[options][{{id}}][values][{{select_id}}][sku]" value="{{sku}}"></td>'+
Add these after just after
'<td><input type="text" class="input-text" name="product[options][{{id}}][values][{{select_id}}][description]" value="{{description}}"></td>'+
Step 2:-
In File
app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php
Find the below code:
$value['sku'] = $this->htmlEscape($option->getSku());
Add these code just after
$value['description'] = $this->htmlEscape($option->getDescription());
Find the below code:
'sku' => $this->htmlEscape($_value->getSku()),
Add these code just after
'description' => $this->htmlEscape($_value->getDescription()),
Step 3:-
Add field in “catalog_product_option_type_value” table description.
Let me know if you have some query.
I have been using this documentation (the only one I can find on the web) to build a component:
http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Introduction
I can understand it to a certain extent, however it does really lack any definition. The component I have created works to a degree, though I am having some wier problems.
Basically all I need the component to do is simply load a settings area to set a few values, and through it be able to change those values. Here is a breakdown of what I have:
A view for a form, loading in form data from database.
toolbars setup for save/apply and cancel.
This loads with no errors, and according to all docs on joomla I have found, by initializing a JControllerForm instance with a JTable connected in the model, simple saving of forms should work automatically. However even though there is absolutely no reference anywhere in the code to a view with an s at the end (main view is tireapi, the forms always redirects to tireapis).
This brings up a 500 error, as there is no place set that has that view. The documentation does include a list for a view, however I have only one row I need to edit, so a list is pointless. I know parameters can be set to components rather then making a database field, however I am unable to find any documentation relating to it.
What I am looking for is direction on how to stop the component from redirecting to a none existent view, and properly save the data. Links to documentation that not only shows example code, but describes functions and how they work would be beneficial.
Here is some of the code, feel free to point out anything I might be completely overlooking (I am newer to creating components):
tireapi.php:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by TireAPI
$controller = JController::getInstance('TireAPI');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = $jinput->get('task', "", 'STR' );
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
?>
controller.php:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
class TireAPIController extends JController{
function display($cachable = false){
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'TireAPI'));
// call parent behavior
parent::display($cachable);
}
}
?>
controllers/tireapi.php:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controllerform library
jimport('joomla.application.component.controllerform');
class TireAPIControllerTireAPI extends JControllerForm{}
?>
models/tireapi.php:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modeladmin');
class TireAPIModelTireAPI extends JModelAdmin{
protected $settings; //define settings
public function getTable($type = 'TireAPI', $prefix = 'TireAPITable', $config = array()){
return JTable::getInstance($type, $prefix, $config);
}
public function getSettings(){ //grab settings from database
if(!isset($this->settings)){
$table = $this->getTable();
$table->load(1);
$this->settings = $table;
}
return $this->settings;
}
public function getForm($data = array(), $loadData = true){
// Get the form.
$form = $this->loadForm('com_tireapi.tireapi', 'tireapi',
array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)){
return false;
}
return $form;
}
protected function loadFormData(){
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_tireapi.edit.tireapi.data', array());
if (empty($data)){
$data = $this->getSettings();
}
return $data;
}
}
?>
tables/tireapi.php:
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
// import Joomla table library
jimport('joomla.database.table');
class TireAPITableTireAPI extends JTable
{
function __construct( &$db ) {
parent::__construct('#__tireapi', 'id', $db);
}
}
?>
views/tireapi/view.html.php:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
class TireAPIViewTireAPI extends JView{
function display($tpl = null){
$form = $this->get('Form');
$item = $this->get('Settings');
// Check for errors.
if(count($errors = $this->get('Errors'))){
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this->item = $item;
$this->form = $form;
$this->addToolBar();
// Display the template
parent::display($tpl);
}
protected function addToolBar() {
$input = JFactory::getApplication()->input;
JToolBarHelper::title(JText::_('COM_TIREAPI_MANAGER_TIREAPIS'));
JToolBarHelper::apply('tireapi.apply');
JToolBarHelper::save('tireapi.save');
JToolBarHelper::cancel('tireapi.cancel');
}
}
?>
views/tireapi/tmpl/default.php:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
// load tooltip behavior
JHtml::_('behavior.tooltip');
?>
<form action="<?php echo JRoute::_('index.php?option=com_tireapi&layout=edit&id='.(int) $this->item->id); ?>"
method="post" name="adminForm" id="tireapi-form">
<fieldset class="adminform">
<legend><?php echo JText::_( 'COM_TIREAPI_DETAILS' ); ?></legend>
<ul class="adminformlist">
<?php foreach($this->form->getFieldset() as $field): ?>
<li><?php echo $field->label;echo $field->input;?></li>
<?php endforeach; ?>
</ul>
</fieldset>
<div>
<input type="hidden" name="task" value="tireapi.edit" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
These are all the files I can think of that may matter, let me know if I should include anymore.
UPDATE:
Now I can get the redirect problem to stop, however it will not save data.
I get this error:
You are not permitted to use that link to directly access that page (#1).
This is the last hurdle to get this extremely basic admin feature to work. Any ideas?
To clarify, I set the forms though an xml file and that loads properly, even filling them with the proper data from database. However when I click "apply" it just directs me back to the form with the error listed above, without saving.
The main question that you left open is where do you want it to redirect? Joomla by default redirects to the list view (by adding an 's' to the view name unless you specify a list view directly).
You can override this in a couple of ways:
In your controller (controllers/tireapi.php), set your own list view. I think you can even make this the same view:
function __construct() {
$this->view_list = 'tireapi';
parent::__construct();
}
Override the save function to change the redirect that happens after save (again in the controller). This works by changing the redirect that happens naturally to something else:
public function save($key = null, $urlVar = null) {
$return = parent::save($key, $urlVar);
$this->setRedirect(JRoute::_('index.php?option=com_tireapi&view=tireapi'));
return $return;
}
One of those should do the trick for you.
** UPDATE
To get the item to checkout initially you will want to change how your component handles no view being set. Right now you just set the view, instead, let's redirect! Updated controller.php is below.
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
class TireAPIController extends JController{
function display($cachable = false){
// set default view if not set
$input = JFactory::getApplication()->input;
$view = $input->get('view');
if (!$view) {
JFactory::getApplication()->redirect('index.php?option=com_tireapi&task=tireapi.edit&id=1');
exit();
}
// call parent behavior
parent::display($cachable);
}
}
?>
NOTE: This will work really poorly if more than one person needs to edit this, since the system checks it out when you open the component if you also have it redirect back to this page after saving. Because then it will always be checked out to the last person that edited it so the next person won't be able to open it. If only one person edits it, it will be fine.
SECOND NOTE: If you don't want to hack the checkout system you can also ignore it during the save process, which is basically the same level of hacking.
Below is a copy of the save function from controllerform.php in libraries/joomla/application/component/. This is what is running on save normally (because of where you inherit from. I have removed the check if the item is checked out. So if you put this in your tireapi.php controller where the parent::save... bit is, it will run instead and you don't have to bother with checking the item out (i.e. ignore all the comments...). (Honestly, in your case, you can probably delete a lot more of this, but this is what is happening on save, btw!)
public function save($key = null, $urlVar = null)
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$app = JFactory::getApplication();
$lang = JFactory::getLanguage();
$model = $this->getModel();
$table = $model->getTable();
$data = JRequest::getVar('jform', array(), 'post', 'array');
$checkin = property_exists($table, 'checked_out');
$context = "$this->option.edit.$this->context";
$task = $this->getTask();
// Determine the name of the primary key for the data.
if (empty($key))
{
$key = $table->getKeyName();
}
// To avoid data collisions the urlVar may be different from the primary key.
if (empty($urlVar))
{
$urlVar = $key;
}
$recordId = JRequest::getInt($urlVar);
// Populate the row id from the session.
$data[$key] = $recordId;
// The save2copy task needs to be handled slightly differently.
if ($task == 'save2copy')
{
// Check-in the original row.
if ($checkin && $model->checkin($data[$key]) === false)
{
// Check-in failed. Go back to the item and display a notice.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar), false
)
);
return false;
}
// Reset the ID and then treat the request as for Apply.
$data[$key] = 0;
$task = 'apply';
}
// Access check.
if (!$this->allowSave($data, $key))
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(), false
)
);
return false;
}
// Validate the posted data.
// Sometimes the form needs some posted data, such as for plugins and modules.
$form = $model->getForm($data, false);
if (!$form)
{
$app->enqueueMessage($model->getError(), 'error');
return false;
}
// Test whether the data is valid.
$validData = $model->validate($form, $data);
// Check for validation errors.
if ($validData === false)
{
// Get the validation messages.
$errors = $model->getErrors();
// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
{
if ($errors[$i] instanceof Exception)
{
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
}
else
{
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Save the data in the session.
$app->setUserState($context . '.data', $data);
// Redirect back to the edit screen.
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar), false
)
);
return false;
}
// Attempt to save the data.
if (!$model->save($validData))
{
// Save the data in the session.
$app->setUserState($context . '.data', $validData);
// Redirect back to the edit screen.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar), false
)
);
return false;
}
// Save succeeded, so check-in the record.
if ($checkin && $model->checkin($validData[$key]) === false)
{
// Save the data in the session.
$app->setUserState($context . '.data', $validData);
// Check-in failed, so go back to the record and display a notice.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar), false
)
);
return false;
}
$this->setMessage(
JText::_(
($lang->hasKey($this->text_prefix . ($recordId == 0 && $app->isSite() ? '_SUBMIT' : '') . '_SAVE_SUCCESS')
? $this->text_prefix
: 'JLIB_APPLICATION') . ($recordId == 0 && $app->isSite() ? '_SUBMIT' : '') . '_SAVE_SUCCESS'
)
);
// Redirect the user and adjust session state based on the chosen task.
switch ($task)
{
case 'apply':
// Set the record data in the session.
$recordId = $model->getState($this->context . '.id');
$this->holdEditId($context, $recordId);
$app->setUserState($context . '.data', null);
$model->checkout($recordId);
// Redirect back to the edit screen.
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar), false
)
);
break;
case 'save2new':
// Clear the record id and data from the session.
$this->releaseEditId($context, $recordId);
$app->setUserState($context . '.data', null);
// Redirect back to the edit screen.
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(null, $urlVar), false
)
);
break;
default:
// Clear the record id and data from the session.
$this->releaseEditId($context, $recordId);
$app->setUserState($context . '.data', null);
// Redirect to the list screen.
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(), false
)
);
break;
}
// Invoke the postSave method to allow for the child class to access the model.
$this->postSaveHook($model, $validData);
return true;
}
This is not a real answer but your question is also not a real question (I had to read it 3 times).
The thing with the plural "s" (for tireapis) is what Joomla! does automatically. You can override that.
I suggest that you take a look at the core components (like com_banners).
What you need to do is to avoid the redirect. You should have only the "Save" button, that should keep you on the same page. While "Save & Close" redirects you to the plural page.
I have pagination setup on a custom Joomla component. To avoid a page long explanation, we're kind of doing some intricate iframe embedding and forward masking. This is pagination for the front end of the component.
In my iframe, I have a list of puppies (from the custom component). It is paginated. In order for the puppies to display correctly in the iframe it has to have the URL :
http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-2.html?tmpl=component&view=microsite
However when I actually click on the pagination link for page 2 it drops the view=microsite which causes problems. How can I adjust this so that it does not drop the view=microsite?
The original URL is http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-1.html?tmpl=component&view=microsite
The code for this pagination is long and between the model, view and view.html.php so it seems difficult for me to post all the related code. Here's some though where I have been looking.
Any ideas or hints on where / how to do this?
Thanks
Zach
// Get the pagination request variables
$limit = $app->input->get('limit', $params->get('display_num', 20), 'uint');
$limitstart = $app->input->get('limitstart', 0, 'uint');
$this->setState('puppies.limit', $limit);
$this->setState('puppies.limitstart', $limitstart);
// Load the parameters.
$this->setState('params', $params);
}
/** Method to get a store id based on the model configuration state. **/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('puppies.breed_alias');
$id .= ':' . $this->getState('puppies.limit');
$id .= ':' . $this->getState('puppies.limitstart');
$id .= ':' . serialize($this->getState('puppies.filter'));
$id .= ':' . $this->getState('puppies.featured');
return parent::getStoreId($id);
}
/** Method to get a JPagination object for the data set. **/
public function getPagination()
{
// Create the pagination object.
$limit = (int) $this->getState('puppies.limit');
$page = new JPagination($this->getTotal(), $this->getStart(), $limit);
return $page;
}
/** Method to get the total number of items for the data set. **/
public function getTotal()
{
return $this->items_total;
}
/** Method to get the starting number of items for the data set. **/
public function getStart()
{
$start = $this->getState('puppies.limitstart');
$limit = $this->getState('puppies.limit');
$total = $this->getTotal();
if ($start > $total - $limit)
{
$start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
}
return $start;
}
Again, a portion of the code here but I have no idea what to begin posting for an answer to this so please I will post any code but point me in the right direction, thanks.
Somewhere at the bottom of your "adminform" in that view, there should be the all the hidden inputs that submit the view / controller / token.
Something like this:
<input type="hidden" name="option" value="com_puppies" />
<input type="hidden" name="view" value="microsite" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<inupt type="hidden" name="controller" value="microsite" />
<input type="hidden" name="filter_order" value="<?php echo $this->escape($this->state->get('list.ordering')); ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->escape($this->state->get('list.direction')) ?>" />
<?php echo JHtml::_('form.token'); ?>
Feel free to remove the inputs you won't use (i.e the filter_order ones if you handle that differently). The vital one is the view input. Also, leave the controller input out if you are not using a controller for that view (meaning you are using the default controller for that component)
Can you give this link http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-1.html?tmpl=component&view=microsite without SEF? you can try to create file /templates/{$your_template}/html/pagination.php with such code
<?php
function pagination_item_active(&$item){
$getData = new JInput($_GET);
$view = $getData->get('view','','string');
$link_part = ($view == 'microsite' ? '&view=microsite' : '');
$link = "<a title=\"" . $item->text . "\" href=\"" . $item->link.$link_part . "\" class=\"pagenav2\">" . $item->text . "</a>";
return $link;
}
function pagination_item_inactive(&$item){
return "<span class=\"pagenav\">" . $item->text . "</span>";
}
Also i think your problem in incorrect link. How you got this link http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-1.html?tmpl=component&view=microsite? If you use ready link with view=microsite, try create link on your view (microsite) in admin panel and use this link.