Viewed   105 times

I've started to use Symfony2 but I've some problems. I wanted to render fields by hand but it doesn't work because my field yet rendered by me is displayed with the form_rest() function too, so I have two same fields.

Here is my code :

<div>
     {{ form_errors(form.contenu) }}
     <textarea id="{{ form.contenu.vars.id }}" name="{{ form.contenu.vars.full_name }}">{{ form.contenu.vars.value }}</textarea>
</div>

And, at the form's end, I must put this :

{{ form_rest(form) }}

But it displays the "contenu" field :(

Do you have an idea of what's the problem ?

 Answers

2

Another option is to explicitly mark the field as rendered:

{% do form.contenu.setRendered %}
Thursday, September 15, 2022
4

Just use this part of code and it works

if($loginForm->isSubmitted() && $loginForm->isValid()){
  //code
  //don't forget the return statement
}

if($registerForm->isSubmitted() && $registerForm->isValid()){
  //code
  //don't forget the return statement
}
Wednesday, August 17, 2022
 
3

You have to pass an instance of SymfonyComponentFormFormView instead of SymfonyComponentFormForm to your view.

Fix this using ...

... ->getForm()->createView();

FormBuilder::getForm builds the Form object ... Form::createView then creates a FormView object.

Monday, August 15, 2022
 
1

(1) Pass caller's environment. You can explicitly pass the parent environment and index into it. Try this:

f2a <- function(P, env = parent.frame()) {
    env$calls <- env$calls + 1
    print(env$calls)
    return(P + env$c + env$d)
}

a <- 1
b <- 2
# same as f1 except f2 removed and call to f2 replaced with call to f2a
f1a <- function(){
    c <- 3
    d <- 4
    calls <- 0
    v <- vector()
    for(i in 1:10){
        v[i] <- f2a(P=0)
        c <- c+1
        d <- d+1
      }
     return(v)
}
f1a()

(2) Reset called function's environment We can reset the environment of f2b in f1b as shown here:

f2b <- function(P) {
    calls <<- calls + 1
    print(calls)
    return(P + c + d)
}

a <- 1
b <- 2
# same as f1 except f2 removed, call to f2 replaced with call to f2b
#  and line marked ## at the beginning is new
f1b <- function(){
    environment(f2b) <- environment() ##
    c <- 3
    d <- 4
    calls <- 0
    v <- vector()
    for(i in 1:10){
        v[i] <- f2b(P=0)
        c <- c+1
        d <- d+1
      }
     return(v)
}
f1b()

(3) Macro using eval.parent(substitute(...)) Yet another approach is to define a macro-like construct which effectively injects the body of f2c inline into f1c1. Here f2c is the same as f2b except for the calls <- calls + 1 line (no <<- needed) and the wrapping of the entire body in eval.parent(substitute({...})). f1c is the same as f1a except the call to f2a is replaced with a call to f2c .

f2c <- function(P) eval.parent(substitute({
    calls <- calls + 1
    print(calls)
    return(P + c + d)
}))

a <- 1
b <- 2
f1c <- function(){
    c <- 3
    d <- 4
    calls <- 0
    v <- vector()
    for(i in 1:10){
        v[i] <- f2c(P=0)
        c <- c+1
        d <- d+1
      }
     return(v)
}
f1c()

(4) defmacro This is almost the same as the the last solution except it uses defmacro in the gtools package to define the macro rather than doing it ourself. (Also see the Rcmdr package for another defmacro version.) Because of the way defmacro works we must also pass calls but since it's a macro and not a function this just tells it to substitute calls in and is not the same as passing calls to a function.

library(gtools)

f2d <- defmacro(P, calls, expr = {
    calls <- calls + 1
    print(calls)
    return(P + c + d)
})

a <- 1
b <- 2
f1d <- function(){
    c <- 3
    d <- 4
    calls <- 0
    v <- vector()
    for(i in 1:10){
        v[i] <- f2d(P=0, calls)
        c <- c+1
        d <- d+1
      }
     return(v)
}
f1d()
Thursday, October 13, 2022
3

Well I'm not aware of how your current mapping looks. Also I don't know about NEST as well but I will explain

How to make Elastic Engine understand a field is not to be analyzed for an exact match?

by an example using elastic dsl.

For exact match (case sensitive) all you need to do is to define the field type as keyword. For a field of type keyword the data is indexed as it is without applying any analyzer and hence it is perfect for exact matching.

PUT test
{
  "mappings": {
    "properties": {
      "field1": {
        "type": "keyword"
      }
    }
  }
}

Now lets index some docs

POST test/_doc/1
{
  "field1":"SOME"
}

POST test/_doc/2
{
  "field1": "SOME OTHER LOAN"
}

For exact matching we can use term query. Lets search for "SOME" and we should get document 1.

GET test/_search
{
  "query": {
    "term": {
      "field1": "SOME"
    }
  }
}

O/P that we get:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.6931472,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.6931472,
        "_source" : {
          "field1" : "SOME"
        }
      }
    ]
  }
}

So the crux is make the field type as keyword and use term query.

Wednesday, August 3, 2022
 
lucy82
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :