Modules views and actions inside tabs

痞子三分冷 提交于 2020-01-06 08:13:12

问题


I'm developing a site using Symfony 1.4.20 but the designer wants things like this image

Each of this is a admin module generate trough task doctrine:generate-admin.

How I achieve this task? I mean works with every from one interface made by tabs?

EDIT

Based on suggestions made by @antony I do this: Create a components.class.php inside /frontend/modules/emisores/actions/components.class.php, add this code inside the class:

class emisoresComponents extends sfComponents {

    public function executeIndex(sfWebRequest $request) {
        $this->sdriving_emisors = Doctrine_Core::getTable('SdrivingEmisor')->createQuery('a')->execute();
    }
}

Include the component in the view where tabs are created

<?php include_component('emisores'); ?>

But I get this error

sfComponents initialization failed.

What's wrong?

EDIT2 I'm getting some problems with pagination because I got redirected to module instead of get the pagination inside the tab. I change the component to this:

public function executeIndex(sfWebRequest $request) {
        $this->pager = new sfDoctrinePager('SdrivingEmisor', 10);
        $this->pager->setQuery(Doctrine_Core::getTable('SdrivingEmisor')->createQuery('a'));
        $this->pager->setPage($request->getParameter('page', 1));
        $this->pager->init();
}

Then in the view (_index.php) I wrote this:

<?php if (count($pager) > 0): ?>
    <table class="table table-condensed table-striped table-bordered table-hover marginBottom">
        <thead>
            <tr>
                <th><?php echo __('Número') ?></th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($pager->getResults() as $sdriving_emisor): ?>
                <tr>
                    <td><?php echo $sdriving_emisor->getNumero() ?></td>
                    <td>
                        <a href="<?php echo url_for('emisores/edit?idemisor=' . $sdriving_emisor->getIdemisor() . '&idempresa=' . $sdriving_emisor->getIdempresa()) ?>" class="btn btn-success btn-mini">Editar</a>
                        <a href="<?php echo url_for('emisores/delete?idemisor=' . $sdriving_emisor->getIdemisor() . '&idempresa=' . $sdriving_emisor->getIdempresa()) ?>" class="btn btn-danger btn-mini">Eliminar</a>
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php else: ?>
    <div class="alert alert-block">
        <h4><?php echo __('Información!') ?></h4>
        <?php echo __('No se ha creado ningún emisor aún. Haga clic en el botón "Crear Nuevo" para crear uno.') ?>
    </div>
<?php endif; ?>

<div class="pagination">
    <strong><?php echo count($pager) ?></strong> <?php echo __('emisores encontrados') ?>
    <?php if ($pager->haveToPaginate()): ?>
        <div class="clearfix"></div>
        <ul>
            <li><?php echo link_to(__('Anterior'), 'emisores/index?page=' . $pager->getPreviousPage()) ?></li>
            <?php $links = $pager->getLinks(); ?>
            <?php foreach ($links as $page): ?>
                <li>
                    <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'emisores/index?page=' . $page); ?>
                    <?php if ($page != $pager->getCurrentMaxLink()): ?> 
                    <?php endif ?>
                </li>
            <?php endforeach; ?>
            <li><?php echo link_to(__('Siguiente'), 'emisores/index?page=' . $pager->getNextPage()) ?></li>
        </ul>
    <?php endif; ?>
</div>

But as I said I get redirected to emisor module instead of paginate inside the active tab, any advice?


回答1:


The fact that you're using tabs shouldn't change much. I'd still create a separate module that handles the CRUD tasks for each tab. You just might need to use partials and embed them into your usario module's template. So for example, you could store each tab in a _form.php partial, and your structure might be something like this:

   \app
     \admin
         \modules
            \usario
               \actions
               \templates
                  editSuccess.php
                  _form.php
            \emisore
               \actions
               \templates
                  _form.php
            \maquina
               \actions
               \templates
                  _form.php

You can include each form partial in your user editSuccess.php template a few different ways. You can create the forms in the user edit action, or use components.

// app\admin\modules\usario\actions\actions.class.php
public function executeEdit(sfWebRequest $request)
{
    $usario = // Code to usario;
    $this->usario = new UsarioForm($usario);

    $emisore = // Code to get emisore;
    $this->emisore = new EmisoreForm($emisore);

    //...
}

public function executeUpdate(sfWebRequest $request)
{
    // ... Do update here

    // Keep track of the tab being edited
    $this->getUser()->setFlash('activeTab', 'usario');
}

Or create a component class for each of the other modules

// app\admin\modules\maquina\actions\components.class.php
public function executeNew(sfWebRequest $request)
{
   $maquina = // Code to get Maquina;
   $this->form = new MaquinaForm($maquina);
}

Embed them like this in your template. Also keep track of the tab that was just being edited in your session flash object

<!-- app\admin\modules\usario\templates\editSuccess.php -->

<div class="tab-content<?php echo $sf_user->getFlash('activeTab') == 'usario' ? ' active' : '' ?>">
    <?php include_partial('usario/form', array('form' => $usarioForm))); ?>
</div>

<div class="tab-content<?php echo $sf_user->getFlash('activeTab') == 'emisore' ? ' active' : '' ?>">
    <?php include_partial('emisore/form', array('form' => $emisoreForm))); ?>
</div>

<div class="tab-content<?php echo $sf_user->getFlash('activeTab') == 'maquina' ? ' active' : '' ?>">
    <?php include_component('maquina', 'form'); ?>
</div>


来源:https://stackoverflow.com/questions/17011598/modules-views-and-actions-inside-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!