Creating a toolbar for your component/es: Difference between revisions
From Joomla! Documentation
Created page with "Explicación útil sobre JToolBarHelper/personalizado aquí" |
Created page with "Category:Component Development/es Category:Tutorials/es" |
||
| Line 105: | Line 105: | ||
<noinclude> | <noinclude> | ||
[[Category:Component Development]] | [[Category:Component Development/es]] | ||
[[Category:Tutorials]] | [[Category:Tutorials/es]] | ||
</noinclude> | </noinclude> | ||
Revision as of 19:00, 15 September 2015
Nota: Esto se aplica cuando se usa la estructura MVC.
De forma predetermianda , la Barra de Herramientas de Joomlaǃ utilizaː Borrar, Editar, Nuevo, Publicar, Despublicar y los botones de los Parámetros. Para usar ellos en tu componente debes escribir el siguiente código en el archivo de tu vista view.html.php (dentro de tu función display).
JToolBarHelper::title( 'your_component_view_page_title', 'generic.png' );
JToolBarHelper::deleteList(); // Will call the task/function "remove" in your controller
JToolBarHelper::editListX(); // Will call the task/function "edit" in your controller
JToolBarHelper::addNewX(); // Will call the task/function "add" in your controller
JToolBarHelper::publishList(); // Will call the task/function "publish" in your controller
JToolBarHelper::unpublishList(); // Will call the task/function "unpublish" in your controller
JToolBarHelper::preferences('your_component_xml_file', 'height');
Entonces, (por ej.) el código sería así:
class HelloViewHellos extends JView
{
function display($tpl = null) {
JToolBarHelper::title( 'Hello Component', 'generic.png' );
JToolBarHelper::deleteList();
JToolBarHelper::editListX();
JToolBarHelper::addNewX();
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::preferences('com_hello', '500');
Un ejemplo de cómo crear un botón personalizado en el administrador de la lista de registros de tu componente
podría ser:
administrator/views/hellos/view.html.php
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
parent::display($tpl);
}
protected function addToolbar()
{
// assuming you have other toolbar buttons ...
JToolBarHelper::custom('hellos.extrahello', 'extrahello.png', 'extrahello_f2.png', 'Extra Hello', true);
}
administrator/controllers/hellos.php
public function extrahello()
{
// Get the input
$input = JFactory::getApplication()->input;
$pks = $input->post->get('cid', array(), 'array');
// Sanitize the input
JArrayHelper::toInteger($pks);
// Get the model
$model = $this->getModel();
$return = $model->extrahello($pks);
// Redirect to the list screen.
$this->setRedirect(JRoute::_('index.php?option=com_hello&view=hellos', false));
}
administrator/models/hello.php (nota: el modelo en singular)
public function extrahello($pks)
{
// perform whatever you want on each item checked in the list
return true;
}
Explicación útil sobre JToolBarHelper/personalizado aquí - http://docs.joomla.org/JToolBarHelper/custom