我有一个服务器,我需要在其中存储一些图像。现在图像可以上传或动态创建,让我们说只需向某些默认图片添加一些文本(所以我为此创建了一个文件 MakenewForm.php
)。我的数据库中的表将文件名存储在本地文件系统上。现在上传很简单,我只需使用默认的 _new 操作即可。为了创建图片,我做了一个新动作,比如makenew
。 new
和 makenew
都显示在列表视图上。我将 newSuccess.php
复制到 makenewSuccess.php
。现在我想要为他们提供一组不同的提交按钮。我似乎不知道该怎么做。我看到的只是这样:
<div id="sf_admin_content">
<?php include_partial('poster/form', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper)) ?>
</div>
我不知道什么是$configuration,什么是$helper。有人可以告诉我关于他们的事吗?我需要更改哪一项以及如何更改?
另外,正如您可以推断的,new
操作的提交操作只需要执行$form->save()
,但makenew的提交操作需要执行$form->save()
需要获取所有文本输入并写入图像文件(假设使用imagejpeg)
我需要一些实现这一目标的指示。
I have a server where I need to store some images. Now the images can be either uploaded or created on the fly let us say just by adding some text to some default picture(So I made a file MakenewForm.php
for that) . The table in my database stores filename on the local filesystem. Now upload is simple, I can just use the default _new action for that. For creating picture, I made a new action, say makenew
. new
and makenew
both are diplayed on the list view. I copied newSuccess.php
to makenewSuccess.php
. Now I want a different set of submit buttons for them. I can't seem to figure out how to do that. All I see is this:
<div id="sf_admin_content">
<?php include_partial('poster/form', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper)) ?>
</div>
I don't know what is $configuration and what is $helper. Can someone tell me about them? Which one do I need to change and How?
Also, as you can infer, the submit action of the new
action only needs to do a $form->save()
but the submit action of makenew
needs to take all the text input and write an image file(let's say using imagejpeg)
I need some pointers towards achieving this.
发布评论
评论(1)
我希望能够很好地关注您正在寻找的东西。
关于
$configuration
和$helper
,您可以在cache\mypplication\dev\modules\autoMymodule\actions\actions.class.php
中找到函数preExecute()
也用于创建它们:这些类位于
apps\docdesk\modules\mymodule\lib
中。您可以在cache\mypplication\dev\modules\autoMymodule\lib
中找到基类。查看这些基类以了解如何使用以及管理生成器提供哪些配置函数和辅助函数。为了处理您的新操作,我不知道您正在开发的功能,因此我将尝试想象两种可能的场景。您只能使用一个表单,通过自定义小部件切换上传/创建图片的功能,覆盖模板
_form.php
(在您的代码片段中调用)以及新操作等等,或者,这就是按照您所遵循的方式,创建一个完全独立的操作、表单和所有需要的模板。因此,在 makenewSucces.php 中,您可以包含一个使用$poster, 'form' => $form) 调用的模板 _makeform.php , 'configuration' => $configuration, 'helper' => $helper)) ?>
当然你必须把模板
apps\docdesk\modules\mymodule\template
中的_makeform.php
作为每个新的或覆盖的。我不太明白你对图像保存的麻烦...我想你是在询问图像的保存链以及如何以及在哪里管理你所需要的内容。
要添加小部件以在
PosterForm
类中上传图像,您可以使用这样的代码片段,其中我们假设photo
作为小部件名称,根据架构字段photo : { type: varchar(255), required: true }
,那就当然是自定义了:注意我的
upload_image_dir
设置是%SF_UPLOAD_DIR%/images/
Symfony 将为您上传并保存图像!
然后,您可以根据您的需要重写
doSave
函数,将相同的函数放入您的PosterForm
类中:最后删除您的图像,即文件,当您删除对象,即图像名称为字段的数据库记录,您必须将此代码放入您的模型类
Poster
中:我希望这可以帮助您。
I hope to well focus about what you are looking for.
About
$configuration
and$helper
, as you can find incache\mypplication\dev\modules\autoMymodule\actions\actions.class.php
the functionpreExecute()
is used also to create them:These classes are in
apps\docdesk\modules\mymodule\lib
. You can find base classes incache\mypplication\dev\modules\autoMymodule\lib
. Have a look to these base classes to understand how are used and so which configuration functions and helper functions the admin generator makes available.To deal with your new action, I don't know the feature you're developing so I'll try to imagine two possible scenarios. You can use only a form switching your functions of upload/create picture trough a custom widget, overriding the template
_form.php
, called in your snippet, and the new action and so on or, this is the way you're following, create a completely separate action, form and all needed templates. So in your makenewSucces.php you can include a template _makeform.php called with<?php include_partial('poster/makeform', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper)) ?>
Of course you have to put the template
_makeform.php
inapps\docdesk\modules\mymodule\template
as each new or overrided one.I don't well understand your trouble about the image saving... I suppose you're asking for the saving chain of an image and how and where you can manage what you need.
To add the widget to upload an image inside your
PosterForm
class you can use a snippet like this where we supposephoto
as widget name, according with a schema fieldphoto: { type: varchar(255), required: true }
, that is of course to customize:Note that my setting for
upload_image_dir
is%SF_UPLOAD_DIR%/images/
Symfony will upload and save the image for you!
Then you can override the
doSave
function, according to your needs, putting the same one yet in yourPosterForm
class:Finally to remove your image, that is the file, when you delete the object, that is the db record where the image name is a field, you have to put this code in your model class
Poster
:I hope this can help you.