Php 选项卡内的模块视图和操作
我正在开发一个使用Symfony 1.4.20的网站,但是设计师想要这样的图片 每个模块都是一个管理模块,通过任务Php 选项卡内的模块视图和操作,php,tabs,symfony-1.4,Php,Tabs,Symfony 1.4,我正在开发一个使用Symfony 1.4.20的网站,但是设计师想要这样的图片 每个模块都是一个管理模块,通过任务原则:生成管理 我如何完成这项任务?我的意思是,可以从一个标签制作的界面中使用每一个标签 编辑 根据@antony I的建议,我这样做: 在/frontend/modules/emissores/actions/components.class.php中创建components.class.php,在类中添加以下代码: class emisoresComponents extend
原则:生成管理
我如何完成这项任务?我的意思是,可以从一个标签制作的界面中使用每一个标签
编辑
根据@antony I的建议,我这样做:
在/frontend/modules/emissores/actions/components.class.php中创建components.class.php,在类中添加以下代码:
class emisoresComponents extends sfComponents {
public function executeIndex(sfWebRequest $request) {
$this->sdriving_emisors = Doctrine_Core::getTable('SdrivingEmisor')->createQuery('a')->execute();
}
}
在创建选项卡的视图中包括零部件
<?php include_component('emisores'); ?>
然后在视图(_index.php)中,我写了以下内容:
<?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> </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>
事实上,您使用的标签不会有太大的变化。我仍然会创建一个单独的模块来处理每个选项卡的CRUD任务。您可能只需要使用partials并将其嵌入到usario模块的模板中。
例如,您可以将每个选项卡存储在\u form.php
partial中,您的结构可能如下所示:
\app
\admin
\modules
\usario
\actions
\templates
editSuccess.php
_form.php
\emisore
\actions
\templates
_form.php
\maquina
\actions
\templates
_form.php
您可以通过几种不同的方式将每个表单部分包含在用户editsucture.php
模板中。可以在“用户编辑”操作中创建表单,也可以使用组件
// 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');
}
或者为每个其他模块创建一个组件类
// app\admin\modules\maquina\actions\components.class.php
public function executeNew(sfWebRequest $request)
{
$maquina = // Code to get Maquina;
$this->form = new MaquinaForm($maquina);
}
将它们像这样嵌入到模板中。还要跟踪会话flash对象中刚刚编辑的选项卡
<!-- 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>
看一看这张照片。即使您不需要它的所有功能,它也可以成为编写您自己的解决方案的良好起点。您能看看我在第一篇文章中的编辑吗?我遇到了一个问题,不知道为什么要这样做
?您还需要在templates文件夹中放置一个_index.php部分。是的,它现在可以工作了。我几分钟前才意识到这个解决方案,但在阅读本文时,我对管理生成器
模块使用了相同的方法?如果可能的话怎么办?
<!-- 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>