在Symfony中手动创建表单(Creating a form manually in Symfony)

我正在Symfony中构建一个电子商务应用程序,并且我有一个列出特定类别中的产品的页面,例如URL“/ categories / list / id / 1”:

Product 1
Product 2
...

我想要一些形式的东西:

Product 1
* Add [ 1 ] of these to your shopping cart [Go]

Product 2
* Add [ 1 ] of these to your shopping cart [Go]

在同一页面上,所以我认为我需要从sfForm类派生出来并构建自己的表单,就像自动生成的表单一样。 是否应该根据类别模型命名? 或者根据“购物车”模型(我的购物车将被存储在何处)进行命名会更合适? 这将如何链接到例如我的listProductsByCategorySuccess.php模板?

希望以上是有道理的!

谢谢,

-丰富


I'm constructing an ecommerce application in Symfony, and I have a page which lists the products within a specific category, eg at the URL "/categories/list/id/1":

Product 1
Product 2
...

I'd like to have something of the form:

Product 1
* Add [ 1 ] of these to your shopping cart [Go]

Product 2
* Add [ 1 ] of these to your shopping cart [Go]

on the same page, so I presume I'm going to need to derive from the sfForm class and construct my own form, as the automatically-generated forms have been. Should this be named according to the categories model? Or would it be more appropriate to be named according to the "cart" model (where my shopping cart will be stored)? and how would this link into eg my listProductsByCategorySuccess.php template?

Hope the above makes sense!

Thanks,

-rich


原文:https://stackoverflow.com/questions/1024854
2022-09-06 13:09

满意答案

它看起来像只有一个http请求被发送。 在这一行上:

timelink = requests.get('http://example.com/somelink')

abcStart()函数正在接收http响应,并在其运行的整个时间内使用该值。 这会导致我们每次都刮同一页。 如果我们想要有一个不同的页面来抓取每个循环迭代,我们需要每次执行另一个http请求。 像这样的东西:

def abcStart(timeLink):

while True:
    res = requests.get(timeLink) # send request here
    res.raise_for_status()
    timestamp = BeautifulSoup(res.content, 'html.parser').find_all('b')

    if timestamp[0].text == otherTimestamp[0].text:
        work on something
        break
    if timestamp[0].text > otherTimestamp[0].text:
         continue
    else:
        print('not yet')
    time.sleep(30)
break

timeLink = 'http://example.com/somelink' # declare url

threadobj = threading.Thread(target=abcStart, args=(timelink))
threadobj.start()
threadobj.join()

It looks like there is only one http request being sent. On this line:

timelink = requests.get('http://example.com/somelink')

the abcStart() function is receiving the http response, and using that one value the whole time it is running. This will cause us to scrape the same page every time. If we want to have a different page to scrape for each loop iteration, we need to perform another http request each time. Something like this:

def abcStart(timeLink):

while True:
    res = requests.get(timeLink) # send request here
    res.raise_for_status()
    timestamp = BeautifulSoup(res.content, 'html.parser').find_all('b')

    if timestamp[0].text == otherTimestamp[0].text:
        work on something
        break
    if timestamp[0].text > otherTimestamp[0].text:
         continue
    else:
        print('not yet')
    time.sleep(30)
break

timeLink = 'http://example.com/somelink' # declare url

threadobj = threading.Thread(target=abcStart, args=(timelink))
threadobj.start()
threadobj.join()

相关问答

更多

如果传递给注释函数的参数类型与指定的参数不匹配,是否有可能产生python抛出错误?(Is it possible to make python throw errors if the type of the argument passed to the annotated function doesn't match the one specified?)

键入提示实现PEP 0484 ,其明确列出为非目标 : 尽管提议的打字模块将包含用于运行时类型检查的一些构建块,特别是get_type_hints()函数,但第三方包必须被开发来实现特定的运行时类型检查功能,例如使用装饰器或元类。 使用类型提示进行性能优化是读者的一项练习。 由此看来,Python开发人员没有计划添加您所寻求的功能。 引用提到装饰器,这似乎是要走的路。 在概念中,它看起来很简单 - 装饰器将在要被修饰的函数上使用get_type_hints() ,并遍历参数,检查它们的类型是否存在...

子程序参数未正确地从Python传递到Fortran(Subroutine argument not passed correctly from Python to Fortran)

将itimes子程序包装在模块中也是如此。 这是我做的: itimes.f90: module itime contains subroutine itimes(th) use fd implicit none real(dp) th write(*,*) 'th - it',th call lprsmf(th) end subroutine itimes end module 编译运行: gfortran -c fd.f90 c:\python27_w32\pyth...

Python获取参数(Python get passed arguments)

这是一个简单的遗漏冒号: 。 https://docs.python.org/2/library/getopt.html 选项是脚本想要识别的选项字符串,其中需要参数后跟冒号(':';即与Unix getopt()使用的格式相同)的选项。 将"hle:t:p:cu"更改为"hle:t:p:cu:"并且它应该可以工作(至少它对Win7 / Python3.5有帮助)。 当你用你的代码执行print(opts, args)时,你会得到: ([('-l', ''), ('-c', ''), ('-p',...

从命令行传递的json参数与python无法解码(json argument passed from the command line with python can't be decoded)

如果你运行print sys.argv[1]你可能得到'{favorited: json模块无法解码为json对象。 尝试转义内部引号,以便将其作为1参数传递,如下所示: "{"\""favorited"\"": false, "\""contributors"\"": null}" if you run print sys.argv[1] you probably get '{favorited: which the json module cannot decode into a json ...

Python C API:使用引用传递的参数调用Python函数(Python C API: Call a Python function with argument(s) passed by reference)

我认为你误解了变量如何在Python中运行。 Python中的变量不包含值; 他们引用它们 - 就像在Java中一样,除了没有“原语”(甚至不是int )。 赋值给变量不会覆盖旧值; 它只是使变量引用新值并停止引用旧值(如果没有其他任何引用它,则可以对其进行垃圾收集)。 为什么不直接返回(并使用)一个值(因为Python函数总是返回一些东西,即使它只是隐式返回None )? 编辑:通过一个例子,因为评论回复太长了。 从C开始,我们调用PyObject_CallFunction,它将PyObject...

Python - 如何获取作为参数传递的更新链接?(Python - how to get updated link that was passed as an argument?)

它看起来像只有一个http请求被发送。 在这一行上: timelink = requests.get('http://example.com/somelink') abcStart()函数正在接收http响应,并在其运行的整个时间内使用该值。 这会导致我们每次都刮同一页。 如果我们想要有一个不同的页面来抓取每个循环迭代,我们需要每次执行另一个http请求。 像这样的东西: def abcStart(timeLink): while True: res = requests.get(ti...

如何获得与Python3链接的boost.python教程示例?(How to get boost.python tutorial example to link with Python3?)

因此,通过反复试验,我找到了一种有效的方法。 我无法从Python27重新编译一个boost库到Python34 但是如果我从一个干净的区域(即刚刚7zipped)开始并执行以下操作(所有在Visual Studio 2010命令提示符下): 确保主目录中有user-config.jam文件,其中包含以下内容: # MSVC configuration using msvc : 10.0 ; # Python configuration: using python : 3.4 : C:\\Pyt...

检查通过python cmd模块传递的参数(Check argument passed via python cmd module)

从cmd文档 : 可选参数completekey是完成键的readline名称; 它默认为Tab 。 如果completekey不是None且readline可用,则命令完成自动完成。 您需要有可用于标签完成的readline才能工作。 命令方法只接受一个参数,您需要在命令方法本身中解析参数。 当然,如有必要,您可以调用self.do_help()或self.help_<cmd>()方法。 From the cmd documentation: The optional argument comp...

Python获取作为参数传递的文件夹中文件的完整路径(Python get full path for files in folder passed as argument)

你可能想要使用os.path.join for image in imagesToStitch: print os.path.join(args["first"], image) You'll likely want to use os.path.join for image in imagesToStitch: print os.path.join(args["first"], image)

论证没有通过部分(Argument not being passed through partial)

get_search_results_partial = partial(get_search_results, toolbar_search_field.get()) 这会立即调用toolbar_search_field.get() (可能是一个空字符串),然后将其传递给partial。 现在get_search_results_partial是一个零参数的函数, get_search_results('')调用get_search_results('') 。 它与工具栏没有任何关联。 正如评...

相关文章

更多

Symfony2网站开发

http://blog.csdn.net/liubei5/article/details/132902 ...

HTML5 智能form表单新属性

内容摘要:HTML5 智能form表单新属性,主要包括智能表单介绍和智能表单使用与规范。但在不同支持H ...

关于一个页面多个form问题????????

当前我的页面是用一个&lt;c:forEach &gt;遍历出来的。有多个form每个都不一样,我可以 ...

form中如何接收传入的值

如题,怎么给form的一个hidden隐藏域中传个id进去 问题补充:不能存在那里面 ...

Drupal Forums instead of phpBB or vBulletin: A casestudy

5th Jan, 10 Drupal drupal advanced forum drupa ...

ext里window里放form的布局?

window里布局了一个form,window有个最大化按钮,点击最大化,form的布局就占windo ...

form load 的问题

baseinfoForm.form.load({ url: '/Url/Institution/In ...

如何把复选框中的值传到form里?

&lt;td&gt; &lt;input type=&quot;checkbox&quot; nam ...

a favorite song

曲名: I COULD BE THE ONE 歌手: Donna Lewis 专辑: blue p ...

ServletOutputStream cannot be resolved to a type

在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本