选项卡内的模块视图和操作 [英] Modules views and actions inside tabs

查看:30
本文介绍了选项卡内的模块视图和操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Symfony 1.4.20 开发一个网站,但设计师想要这样的图片

每一个都是一个管理模块生成槽任务doctrine:generate-admin.

我是如何完成这个任务的?我的意思是可以与选项卡制作的一个界面中的每一个一起使用?

编辑

根据@antony 提出的建议,我这样做:在/frontend/modules/emiores/actions/components.class.php里面创建一个components.class.php,在class里面加入这段代码:

class emioresComponents 扩展 sfComponents {公共函数执行索引(sfWebRequest $request){$this->sdriving_emisors = Doctrine_Core::getTable('SdrivingEmisor')->createQuery('a')->execute();}}

在创建选项卡的视图中包含组件

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

但我收到此错误

<块引用>

sfComponents 初始化失败.

怎么了?

EDIT2我在分页方面遇到了一些问题,因为我被重定向到模块而不是在选项卡内获取分页.我将组件更改为:

公共函数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();}

然后在视图(_index.php)中我写了这个:

 0): ?><table class="table table-condensed table-striped table-bordered table-hover marginBottom"><头><tr><th><?php echo __('Número') ?></th><th>&nbsp;</th></tr></thead><?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">编辑器<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><?php 其他:?><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.') ?>

<?php endif;?><div class="分页"><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'), 'emiores/index?page=' . $pager->getPreviousPage()) ?></li><?php $links = $pager->getLinks();?><?php foreach ($links as $page): ?><li><?php echo ($page == $pager->getPage()) ?$page : link_to($page, 'emiores/index?page=' . $page);?><?php if ($page != $pager->getCurrentMaxLink()): ?><?php endif ?><?php endforeach;?><li><?php echo link_to(__('Siguiente'), 'emisores/index?page=' . $pager->getNextPage()) ?></li><?php endif;?>

但正如我所说,我被重定向到 emisor 模块而不是在活动选项卡内分页,有什么建议吗?

解决方案

您使用选项卡的事实不应有太大变化.我仍然会创建一个单独的模块来处理每个选项卡的 CRUD 任务.您可能只需要使用部分并将它们嵌入到 usario 模块的模板中.例如,您可以将每个选项卡存储在 _form.php 部分中,您的结构可能是这样的:

 \app\行政\模块\usario\动作\模板编辑成功.php_form.php\emisore\动作\模板_form.php\马奎纳\动作\模板_form.php

您可以通过几种不同的方式在用户 editSuccess.php 模板中包含每个表单部分.您可以在用户编辑操作中创建表单,或使用组件.

//app\admin\modules\usario\actions\actions.class.php公共函数执行编辑(sfWebRequest $request){$usario =//代码到 usario;$this->usario = new UsarioForm($usario);$emisore =//获取emisore的代码;$this->emisore = new EmisoreForm($emisore);//...}公共函数执行更新(sfWebRequest $request){//... 在这里更新//跟踪正在编辑的选项卡$this->getUser()->setFlash('activeTab', 'usario');}

或者为每个其他模块创建一个组件类

//app\admin\modules\maquina\actions\components.class.php公共函数 executeNew(sfWebRequest $request){$maquina =//获取 Maquina 的代码;$this->form = new MaquinaForm($maquina);}

将它们像这样嵌入到您的模板中.还要跟踪刚刚在会话 Flash 对象中编辑的选项卡

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

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

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

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?

解决方案

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>

这篇关于选项卡内的模块视图和操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆