「タブ」を使用してモジュールを作成しました。各タブは次のようにコンポーネントを呼び出します。
include_component('logotipo', 'index');
コンポーネントのコードは次のとおりです。
class logotipoComponents extends sfComponents {
public function executeIndex(sfWebRequest $request) {
$id_empresa = $this->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
$this->sdriving_logotipo = Doctrine_Core::getTable('SdrivingLogotipo')->createQuery('a')->leftJoin('a.SdrivingEmpresa e')->where('e.idempresa = ?', $id_empresa)->execute();
}
}
そして、これはテンプレート_index.php
です:
<?php if ($sdriving_logotipo->count() > 0): ?>
<div class="span3">
<span class="gris">Vista previa</span>
<?php echo image_tag('/uploads/' . $sdriving_logotipo[0]->getArchivo()); ?>
</div>
<?php else: ?>
<div class="alert alert-block">
<h4><?php echo __('Información!') ?></h4>
<?php echo __('No se ha subido ningún logotipo aún. Haga clic en el botón "Subir nuevo" para crear uno.') ?>
</div>
<?php endif; ?>
このコードは正常に動作しますが、もう少し必要です。ここで行う必要があるのは、logotipo を更新して新しいものをアップロードし、ファイル システムとデータベースから既存のものを削除するか、既存のレコードを編集して値を更新することです。これを見てみましょうschema.yml
:
SdrivingEmpresa:
columns:
idempresa:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
idlogotipo:
type: integer(4)
unsigned: true
primary: true
nombre_empresa:
type: string(250)
notnull: true
ruta_emp:
type: string(45)
notnull: true
autoincrement: false
relations:
SdrivingLogotipo:
local: idlogotipo
foreign: idlogotipo
type: one
SdrivingEmisor:
local: idempresa
foreign: idempresa
type: many
SdrivingMaquina:
local: idempresa
foreign: idempresa
type: many
SdrivingOperador:
local: idempresa
foreign: idempresa
type: many
SdrivingTurno:
local: idempresa
foreign: idempresa
type: many
SfGuardUserProfile:
local: idempresa
foreign: idempresa
type: many
SdrivingLogotipo:
columns:
idlogotipo:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
archivo:
type: string(250)
relations:
SdrivingEmpresa:
local: idlogotipo
foreign: idlogotipo
type: many
最初のオプションを選択した場合、DB からファイル名を取得するためのクエリを作成し、ファイル システムからファイルを削除し、新しいファイルをアップロードして、SdrivingEmpresa
アップロードされたファイルの新しい ID でテーブルを更新する必要があります。この場合、ID を取得する方法と、これらのアクションのロジックをどこに書き込むかがわかりませんprotected function processForm(sfWebRequest $request, sfForm $form) { }
。'doSave($con = null){ }' でSdrivingLogotipoForm.class.php
? どこ?
何か助けはありますか?