Posts by Rodrigo Rigotti • 12,139 points
344 posts
-
0
votes1
answer61
viewsA: Form which class method to use
You can use the Symfony Form Component to perform this task. With this component, it is possible to use an object to render a form; just as it is possible to map the values submitted through a form,…
-
0
votes1
answer40
viewsA: Doubt Distinct with Doctrine_query
Thete the following DQL: $this ->getEntityManager() ->createQuery(' SELECT DISTINCT(c.anodecorrente) FROM CtNoticias c WHERE c.categoria = :categoria') ORDER BY c.ntId ASC…
-
2
votes5
answers2441
viewsA: How to concatenate String within a repeat loop?
Use the function str_repeat for that reason: $valor = 'palavra,'; // a cadeia de caracteres que será repetida $string = str_repeat($valor, 3); // geramos uma nova cadeia com a quantidade de…
-
1
votes2
answers260
viewsA: How to check the 4 vertical and horizontal elements in a matrix based on the current position?
The first thing you should do is validate the position of the reference element, i.e.: If the position of the element itself is valid; If the element is between two rows and two columns. After this…
-
3
votes2
answers268
viewsA: How to mount an SQL to display grouped content per month?
Your situation does not require any particular query. Most of the implementation is at the time of drawing the tables. Let’s assume you made a very simple query, sorted by date: SELECT id, titulo,…
-
0
votes2
answers114
viewsA: php day counting system
As I imagine you wish to bring the object regardless of whether it is new or not, I suggest the following logic: // $objeto é o objeto que você trouxe do banco, e possui a data como um atributo…
-
1
votes1
answer1851
viewsA: Facial recognition system in php
As already mentioned in the comments, PHP is not the ideal language to do the facial recognition itself. However, as you will develop a web service, it is interesting to think of PHP as the web…
phpanswered Rodrigo Rigotti 12,139 -
4
votes6
answers896
viewsA: Rewrite and close array of a file
I will divide the answer into three parts: reading the file, modification and writing. Reading The function require usually includes a file to be executed - but if its return is assigned to a…
phpanswered Rodrigo Rigotti 12,139 -
0
votes1
answer421
viewsA: Update one entity after entering data into another
The first thing I noticed is that there’s a mistake in catching the client_id of the form, besides being necessary a small Refactoring: public function addAction(Request $request) { $form =…
-
3
votes2
answers154
viewsA: Read XML received from ajax - PHP
The array already tells you where the file is located. Just open it: simplexml_load_file($_FILES['filexml']['tmp_name']); However, it is not recommended to treat a file that is in a temporary…
-
2
votes2
answers1462
viewsA: Is it possible to register . go domains?
Top-level domains .go there are no. Source: https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains…
domainanswered Rodrigo Rigotti 12,139 -
5
votes3
answers949
viewsA: Why does the User-Agent header always return "Mozilla /5.0" independent of the browser?
That excellent article on the history of browsers explains a little about their history, and the section below is what matters most to the context of the question: (...) Mozilla built Gecko, and…
-
4
votes1
answer104
viewsA: Unexpected Behavior, XOR Logical Operator - PHP
The first case is returning false because the operator = takes precedence over the operator xor. $bool = false xor true; // false Instead, do it like this: $bool = (false xor true); // true Source:…
-
3
votes1
answer137
viewsA: How could you create the array_column function in versions prior to PHP 5.5
It is possible to implement the method array_column using the function array_map: function array_column(array $array, $column) return array_map(function($row) use($column) { return $row[$column]; },…
-
3
votes1
answer118
viewsA: Find the index of an array that matches a regular expression
If you combine the functions array_keys, array_intersect_keys and array_flip, you’ll get what you want: $dados = [ 'id' => 3, 'idade' => 25, 'nome' => 'Wallace de Souza', 'profissão' =>…
-
1
votes1
answer96
viewsA: Symfony2 - Updating an entity’s field when executing action in another entity’s Controller
It’s all right in your code. You just forgot to persist the $Client and give the flush, the same way you do with the budget.…
-
2
votes1
answer878
viewsA: Why does creating the model not create Migration for me?
According to the documentation of the Laravel, you need to pass the argument --migration or -m in that command: If you would like to generate a database Migration when you generate the model, you…
-
4
votes1
answer995
viewsQ: How to avoid "zend_mm_heap corrupted" error?
In my day to day PHP development and release delivery, I get back and forth the following error when a build is made in our continuous integration environment: zend_mm_heap corrupted This is a fatal…
phpasked Rodrigo Rigotti 12,139 -
2
votes1
answer30
viewsQ: How to avoid dependency dependencies in Composer?
I own a project A which has a dependency on project B which in turn has a dependency on project C. So the dependency chart would look like this: A -> B -> C (ps: all projects are developed…
commiserateasked Rodrigo Rigotti 12,139 -
3
votes2
answers1842
viewsA: how to separate array values by "," and "and"
Take all elements of the array down to the penultimate of them and concatenate them with a comma; then concatenate the latter with an "and": function concatena($meses) { $string = implode(', ',…
phpanswered Rodrigo Rigotti 12,139 -
4
votes1
answer3088
viewsA: Back repository to previous state
First, give a git log to recover the hash of all the last commits. For example: git log -n 20 # lista os últimos 20 commits In this list, copy the hash from the last stable commit. Then, take a git…
-
3
votes1
answer877
viewsQ: Command to delete all folders except the three most recent
On my application server, I would like to keep a release history of it. However, I don’t want to keep them all, because we rarely have to do rollback for very old releases. Therefore, I would like…
-
3
votes4
answers1277
viewsA: View last 5 lines of a PHP file?
Open the file with the function file and use the function array_slice to catch the last 5 lines: $linhas = file('arquivo.txt'); $linhas = array_slice($linhas, -5); print_r(implode(PHP_EOL,…
-
1
votes1
answer119
viewsA: Diff Ignore blank spaces and line breaks
You can use the tool diff for that reason. Argument -b: ignores changes in the amount of spaces blank. diff -b arq_1.txt arq_2.txt Argument -B: ignores changes in the amount of lines blank. diff -B…
diffanswered Rodrigo Rigotti 12,139 -
3
votes1
answer330
viewsA: How to go emptying PHP buffer while running
The method you seek is the ob_flush. It’s also possible, rather than letting the buffer from time to time, to output the buffer whenever a echo with: ob_implicit_flush(true); Finally, you can set up…
-
2
votes2
answers1654
viewsA: Php and guzzle, how do you get to an address and pick up what you return?
Just go through true as a method parameter Response::getBody() to receive the HTML body as a string. $html = $response->getBody(true);
-
4
votes3
answers49921
viewsA: Convert string number to PHP integer
Use the function intval. intval("123"); // retorna 123 Documentation: http://php.net/manual/en/function.intval.php Other functions of the same type: boolval($val); // retorna o valor de $val…
-
8
votes3
answers256
viewsA: use the PHP implode
The final content of $valor is a string containing valorAvalorBvalorC, and not an array. You need to do it like this: $valor = array(); $valor[] = "valorA"; $valor[] = "valorB"; $valor[] = "valorC";…
phpanswered Rodrigo Rigotti 12,139 -
3
votes3
answers1117
viewsA: Read Remote Server log.txt on Real-Time Local Server
Use the program multitail. With it you can see two (or more) logs at the same time, rendered in the command line in the same window or in separate windows. Official website:…
-
1
votes1
answer97
viewsA: Criteria query with contains expression in the Manytoone entity field
From what I understand, you need a collection of orders whose name of the customer who placed the orders is "Felippe", correct? I would do it using a DQL even: <?php namespace Admin\Repositories;…
-
3
votes3
answers1828
viewsA: How does version naming work for private or public projects?
I will give a response based on the website proposal Semver.org (semantic versioning): Given a version number MAJOR.MINOR.PATCH, increment the: MAJOR version when you make incompatible API changes,…
-
0
votes1
answer460
viewsA: Relationship between 3 entities
It depends on the case. You can create a relationship Many-to-Many between entities Produto and Categoria, or two relationships Many-to-one, being one among Produto and ProdutoVsCategoria, and…
-
9
votes1
answer12506
viewsA: Generate ssh key in git
As you said, there are two ways to authenticate to Github when you push: via HTTP and via SSH. Via HTTP you provide your credentials, in the same way you would provide them when logging into the…
-
0
votes2
answers125
viewsA: Show date field information - php symfony
The error occurs because the content of $tbdeliberacoes->getData() is an object of the type \DateTime, and not an integer (in this case, the date in UNIX format). Just use the method format to…
-
1
votes2
answers452
viewsA: How to get the sum of three tables in sql
If it is not in your interest to change the data model, with Subqueries works like this: SELECT e.nome_escola, (SELECT COUNT(p.id) FROM Professor p WHERE p.id_escola = e.id) AS professors_count,…
-
5
votes1
answer231
viewsA: How to create an anonymous (Closure) recursive function?
Simply assign your anonymous function to a variable and pass this variable by reference. Take for example an anonic function that calculates the factorial of a value: $factorial = function($n)…
-
1
votes1
answer89
viewsA: Insert multiple objects with Dbal Doctrine
Normally, with Doctrine, multiple objects with persist before using the command flush: $em = $this->getEntityManager(); foreach ($objects as $object) { $em->persist($object); }…
-
0
votes1
answer117
viewsA: Service to manage PHP sessions (Symfony2)
It is not necessary to create a service to manage sessions in Symfony applications, since it already has a built-in service for this purpose, called session. If you want to use the session in your…
-
0
votes2
answers142
viewsA: current_date Doctrine
Use the class \DateTime to generate a current date: ->where('a.data_hora = ?', new \DateTime('now')); // ou simplesmente new \DateTime() You can still specify the time zone if the application is…
-
0
votes2
answers120
viewsA: How to return only one column
The query generated by QueryBuilder is wrong, since it is returning not only the result of the COUNT(t.id), but also all columns of t. Exchange the above code for: $ent->createQueryBuilder()…
doctrine-2answered Rodrigo Rigotti 12,139 -
64
votes3
answers97159
viewsA: How do I delete a local and remote Git branch(branch)?
To delete the branch locally: git branch -D <nome do branch> To delete the branch remotely: git push <nome do origin> <nome do branch> --delete…
-
11
votes2
answers2562
viewsQ: How to implement the hidden layer in a character recognition neural network?
I’m studying neural networks - more specifically multilayer perceptron neural networks (MLP) - and I’m having some doubts about implementing such a network for character recognition. The question is…
-
24
votes3
answers9925
viewsA: Difference between './', '.. /' and '/'
Each of these changes the way a directory is referenced. Suppose a file teste.txt: /teste.txt: means that the file teste.txt is in the system root folder; ./teste.txt: means that the file teste.txt…
-
1
votes1
answer229
viewsA: Get data on a PUT route using Silex
According to the documentation of Silex, you have to instruct your application to accept a request via JSON: use Symfony\Component\HttpFoundation\Request; use…
-
2
votes2
answers93
viewsA: Insert null into a Doctrine relationship
The problem in the specific case of your question, is that you are not persisting the user before persisting the vote. You should do something like this: $entityManager->persist($user);…
-
0
votes1
answer54
viewsA: How to access the Sqls of the updates made by Doctrine Orm:schema?
Instead of accessing the executable commands ../vendor/bin/doctrine, you can create a web-accessible script (of course, with some necessary authentication) to do what you need. Behold this section…
-
1
votes1
answer270
viewsA: Self relationship Doctrine
What you need to do is create a One-To-Many Self-referencing Relationship. Read this section in the Doctrine documentation:…
-
4
votes1
answer177
viewsA: Managing Composer Dependencies
Enter the project directory from the command line and run the following command: composer update If you already have the file composer.lock (which is where Composer saves references to each of the…
-
1
votes1
answer262
viewsA: GIT: Problems with conflicts when there is white space
When giving a git merge, you can ignore checks on whitespace using the following parameter: git merge -Xignore-all-space or git merge -Xignore-space-change…
gitanswered Rodrigo Rigotti 12,139 -
1
votes1
answer96
viewsA: How to run methods of all classes extending an interface on symfony
I will give an answer based on what the doctrine/data-fixtures-bundle makes, and you can base your system on that. In the archive LoadDataFixturesCommand.php, which is exactly where the command…