Symfony how to include controller on base.html.twig

I have a small question, I’m new to symfony, I created a controller and a menu template that I want to integrate into my base.html.twig.

I absolutely need the controller to be called because I am testing to know if the session variable is empty or not.

    {% block menu %}
    {% include 'menu/index.html.twig' %}
    {% endblock %}
    
    <body>
        {% block body %}{% endblock %}
    </body>

So I tried this (it works perfectly BUT it didn’t call my controller so when I do my test on session it won’t work….)

I searched but I can’t include the controller instead of the template…

thanks in advance

call or activate the php function by html button or javascript [duplicate]

I want to call the php function by html button or javascript code.
for example if I click a button, a php function should display or do some function. I know ajax is the only way to do this, but I could not understand the ajax code for simply call the function,
so please anyone give a simple example ajax code to control the php function by html button. and please do not give any code with jquery or any other library, because I not yet learn any libraries for php or javascript.

Facebook Graph API display feed content on website

I took over my site to update it and I saw that my facebook feed is no longer displayed, I inquired and apparently new permissions are now required.

I would simply like to display on my site the latest facebook posts

I don’t have a facebook login on my site, it’s useless to me

I did some tests with postman and now I’m being asked for pages_read_engagement and Page Public Content Access permissions

here is my postman link

https://graph.facebook.com/v9.0/:page_id/:feed?key=value&access_token={access_token}&fields=id,message,picture,link,name,description,type,icon,created_time,from,object_id,likes,comments,attachments{media{image}}

and the result:

{
    "error": {
        "message": "(#10) This endpoint requires the 'pages_read_engagement' permission or the 'Page Public Content Access' feature. Refer to https://developers.facebook.com/docs/apps/review/login-permissions#manage -pages and https://developers.facebook.com/docs/apps/review/feature#reference-PAGES_ACCESS for details.",
        "type": "OAuthException",
        "code": 10,
    }
}

when I asked for Page Public Content Access permission, facebook tells me that my use case does not require this permission, I don’t know what to do now, do you have any idea?

thank you

How to check if a record in a table also exists in another table or not in MYSQL

I have two tables “order_manager” and “aamarpay”. Both the table has a column named “transaction_id”. It is a 10 character long randomly generated string. I’m trying to verify if a payment is made successfully or not. If the payment is successful the transaction_id from “order_manager” table would also exist in the “aamarpay” table. Here are the structures of the tables:
order_manager
aamarpay

If the condition returns true then I would update “payment_status” from “order_manager” table to “successful”.

AJAX POST Not Returning php mysql ajax

I’m trying to get data from the database using ajax to insert it in other element but the post data not passing to get-data.php
so what the reason can be and the solution
enter image description here
passed data shown here but no resposns

addBuilding.php

<?php
require_once("./dbConfig.php");
$selectIL = "SELECT * FROM  iller ";
$selectIL = $db->prepare($selectIL);
$selectIL->execute();
$res = $selectIL->get_result();
?>

<form action="" method="post">
    <select name="pp" id="cites">
        <option value="">-select state-</option>
        <?php
        while ($row = $res->fetch_assoc()) {
        ?>
            <option value="<?= $row['id'] ?>"><?= $row['il_adi'] ?></option>
        <?php
        }
        ?>
    </select>
    <select name="district" id="district">
         <option value="">-select district-</option>
    </select>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
   <script src="getdata.js"></script>

getdata.js

$(document).ready(function() { 
    $("#cites").change(function() {
        if ( $("#cites").val()!="") {
            $("#district").prop("disabled",false);
        }else  {
            $("#district").prop("disabled",true);
        }
        var city = $("#cites").val(); 
        $.ajax({ 
            type: "POST",    
            url:"get-data.php",
            data:$(city).serialize(),
            success: function(result) {
                $("#district").append(result); 
            }
        });

    });
});

get-data.php
I can see the form data in network inspection put no data passing to get-data.php

<?php
require_once("./dbConfig.php"); 

if (isset($_POST['pp'])) {
   
    $cites = $_POST['cites'];
    $selectIlce = "SELECT * FROM  ilceler where il_id=? ";
    $selectIlce = $db->prepare($selectIlce);
    $selectIlce->bind_param("i", $cites);
    $selectIlce->execute();
    $res = $selectIlce->get_result();
?>
    <?php
    while ($row = $res->fetch_assoc()) {
    ?>
        <option value="<?= $row['id'] ?>"><?= $row['ilce_adi'] ?></option>
<?php
    }
}
?>

run command line program and enter password from php

I have a command line program which requires for the user to type a password in order to run. I want to run it and enter the password through a php script.

I have tried using proc_open, using the following code, but it does not work. It reads the input, but fwrite does not seem to do anything.

$cmd = "cmd /c command_line_program";

$descriptorspec = array(
    0 => array('pipe', 'r'),  //STDIN
    1 => array('pipe', 'w'),  //STDOUT
    2 => array('pipe', 'r'),  //STDERR
);
$process = proc_open(
    $cmd,
    $descriptorspec, $pipes, null, null);
if (is_resource($process)) {
    $buffer = "";
    // Read from the command's STDOUT until it's closed.
    while (!feof($pipes[1])) {
        $input = fread($pipes[1], 8192);
        $buffer .= $input;

        if (strpos($buffer, 'Password:') !== false){
            fwrite($pipes[0], "userpassn");
        }
    }
    proc_close($process);
} else {
    echo 'Not a resource';
}

What am I doing wrong? Is there some other solution except proc_open? I am using windows and php 7.2.

Paypal Integration in PHP checkout/v2/UpdateOrder REFERENCE_ID_NOT_FOUND

I try to implement paypal express checkout in a way that users are able to manipulate their order after they logged in with Paypal and when they are done, click “bux now” and the actual payment is capured.

To do so, I created the order with paypal before with intend “Authorize”. The user logs into paypal and comes back to my shop to manage the order. When done, I want to use paypals updateOrder Call to apply the users changes. But It always bounces with error REFERENCE_ID_NOT_FOUND.

Here is the documentation:
https://developer.paypal.com/api/orders/v2/#orders_patch

Here is, what I send to Paypal.


[{
    "op": "replace",
    "path": "/purchase_units/@reference_id=='default'",
    "value": [{
        "reference_id": "2295037",
        "description": "Your order at Shop",
        "custom_id": "Shop Id 2295037",
        "soft_descriptor": "Shopname",
        "invoice_id": "2295037",
        "amount": {
            "currency_code": "EUR",
            "value": 59.98,
            "breakdown": {
                "item_total": {
                    "currency_code": "EUR",
                    "value": 50.4
                },
                "shipping": {
                    "currency_code": "EUR",
                    "value": 0
                },
                "discount": {
                    "currency_code": "EUR",
                    "value": 0
                },
                "tax_total": {
                    "currency_code": "EUR",
                    "value": 9.58
                }
            }
        },
        "items": [{
            "name": "Product 1",
            "description": "Product Descr. 1",
            "sku": "1019879",
            "unit_amount": {
                "currency_code": "EUR",
                "value": 16.8
            },
            "tax": {
                "currency_code": "EUR",
                "value": 3.19
            },
            "quantity": "1",
            "category": "PHYSICAL_GOODS"
        }, {
            "name": "Product 2",
            "description": "Product Descr. 2",
            "sku": "1024593",
            "unit_amount": {
                "currency_code": "EUR",
                "value": 33.61
            },
            "tax": {
                "currency_code": "EUR",
                "value": 6.38
            },
            "quantity": "1",
            "category": "PHYSICAL_GOODS"
        }],
        "shipping": {
            "name": {
                "full_name": "John Doe"
            },
            "address": {
                "address_line_1": "Badensche Str. 24",
                "address_line_2": "",
                "admin_area_2": "Berlin",
                "postal_code": "10715",
                "country_code": "DE"
            }
        }
    }]
}]

The answer from Paypal is “REFERENCE_ID_NOT_FOUND”. Paypal itself suggests ‘default’ if there is only one purchase unit (which it is). I also tried to replace ‘default’ with the reference_id in our system (which was provided with the createOrder call) or paypal´s own transactionId (which is provided through the endpoint anyway). The error is always the same.

How can I change this call so that Paypal accepts it and updates the order in its system?

Tui calendar javascript working on localhost but not working host

I’m building a calendar application using tui calendar.
With the changes I made in ‘app-calendar.js’ and ‘schedules.js’, I brought the calendar to the format I wanted.
It works fine on localhost. But when I upload it to the live server, the changes I made in ‘app-calendar.js’ and ‘schedules.js’ are not visible, not working as i want.

Change background color based on product type in Woocommerce admin orders list

I want to conditionally change order’s background color in Woocommerce admin orders list. There is an item called assortment and another item called multiple, if order contains one of them or both of them, the background color will change. My code does work, the probolem is when I delete any item from the store that has a purchase history, I get a fatal error which is said there is an uncaught error in my code, and I have to delete all purchases for this item to stop the fatal error, how can I resolve it? Anyone can tell me what’s wrong with my code?

My Code:

add_action( 'manage_shop_order_posts_custom_column', 'custom_orders_column', 10, 2 );
function custom_orders_column( $column, $post_id ) {
    $order = wc_get_order( $post_id );
    $items = $order->get_items();
    $order_has_assortment = false;
    $product_ids = array( 1911, 1919 );
    foreach ( $items as $item ) {
    if ( in_array( $item->get_product_id(), $product_ids ) ) {
        $order_has_assortment = true;
        break;
        }
    }
    $order_has_multiple = false;
    $term_names = array( 'Twice', '3 times', '4 times', '5 times', '6 times', '7 times', '8 times', '9 times', '10 times', '11 times', '12 times' );
    foreach ( $items as $item ) {
    $product = $item->get_product();
    if ( in_array( $product->get_attribute('pa_frequency'), $term_names ) ) {
        $order_has_multiple = true;
        break;
        }
    }
    if ( $order_has_assortment && !$order_has_multiple ) {
    ?>
    <script>
    jQuery(document).ready(function(){
        jQuery("#post-<?php echo $post_id; ?>").css("background-color", "#ffccd5");
    });
    </script>
    <?php
    }
    elseif ( !$order_has_assortment && $order_has_multiple ) {
    ?>
    <script>
    jQuery(document).ready(function(){
        jQuery("#post-<?php echo $post_id; ?>").css("background-color", "#ffff99");
    });
    </script>
    <?php
    }
    elseif ( $order_has_assortment && $order_has_multiple ) {
    ?>
    <script>
    jQuery(document).ready(function(){
        jQuery("#post-<?php echo $post_id; ?>").css("background-color", "#ccffcc");
    });
    </script>
    <?php
    }
}

PHPUnit prints require to terminal instead of loading the file

I’m not very familiar with PHP and struggling with the PHPUnit setup for hours. This is the situation:

  • functions.php – contains functions to be tested
<?
/**
 * test function
 */
function simple($url){
    return true
}
...
  • phpunit.xml – phpunit configuration
<phpunit bootstrap="tests/bootstrap.php">
    <testsuites>
        <testsuite name='Functions tests'>
            <directory prefix="" suffix=".test.php">./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>
  • tests/functions.test.php – contains the unit tests for the functions
<?php
use PHPUnitFrameworkTestCase;
class FunctionsTest extends TestCase {

    public function test_simple(){
        $this->assertEquals(simple(), true);
    }
    ...
}
  • tests/bootstrap.php – bootstrapping file for the unittests

The content of bootstrap.php is

<?php
require_once(__DIR__ . '/../functions.php');

I then run php vendor/bin/phpunit which has a weird output.

  1. The content of the functions.php file gets printed to the terminal
  2. All tests fail with Call to undefined function simple

When I copy the content of functions.php in front of the functions.test.php all tests pass, but this shouldn’t be the solution.

How to get data from wordpress database to android-studio app without passing password and login

I would like to create app available both on web browser and android.
I would like site created using WordPress and phpMyAdmin.

For browser it’s easy for me to connect it to the database and get/set data there using php but my problem starts when I want to connect android app to the same database. I found java library that request me to put in database login details. I want to avoid that because I’m afraid of that someone could get this data. Is there a way to use XML and SQL to get data from wordpress database without passing database login and pass?

ACF/WP add form values to new repeater row

  • I work on WordPress.
  • I use ACF for all form interaction.
  • I have posts with products.

I want to create different kind of ratings in the comment (quality/price – design – functionnalities – etc…) and hold them on a repeater in order to get that kind of result :

[0]
- user : 5
- Comment : Super !
- Quality/price : 5
- design : 4
- functionnalities : 4
[1]
- user : 3
- Comment : Very bad !
- Quality/price : 2
- design : 4
- functionnalities : 1
...

How to display a form that once sent by the user will add a new row in the repeater on the post Meta?

maitain filtering and pagination on moving to next page on filtering Pls help i need it

I can filter data and show pagination. But i cannot keep product filter checked after i go on next page,and also on applying filter on say for eg page5 i cannot redirect user to filtered products to page 1.

          this is how i display filter checkboxes.    

               <?php
                $query = "
                SELECT DISTINCT(area) FROM property  ORDER BY area DESC
                ";
                $statement = mysqli_query($conn,$query);
                while($row=mysqli_fetch_assoc($statement)){?>
                 <div class="options" >
                    <label><input type="checkbox" class="common_selector area" 
                    value="<?php echo $row['area']; ?>" > <?php echo $row['area']; ? 
                    > </label>
                 </div>
                <?php    
                }?>

fetchdata.php

 if(isset($_POST["area"]))
 {
  $area_filter = implode("','", $_POST["area"]);
  $query .= "
   AND area IN('".$area_filter."')
  ";
 }
 $query .= " 
 LIMIT  $this_page_first_result , $results_per_page
 ";
 $statement=mysqli_query($conn,$query);
 $total_row=mysqli_num_rows($statement);
 $output = '';
 if($total_row > 0)
 {//display output 

pagination variables and display pagination links

                     $results_per_page = 7;
                     include "connect.php";
                     
                     $sql="SELECT * FROM property";
                     $resul=mysqli_query($conn,$sql);
                     $number_of_results=mysqli_num_rows($resul);
                     $number_of_pages = ceil($number_of_results/$results_per_page);
                     if (!isset($_GET['page'])) {
                                  $page = 1;
                                } else {
                                  $page = $_GET['page'];
                                }
                     $this_page_first_result = ($page-1)*$results_per_page;
                     $get = $_GET; 
                     $current_page = isset($get['page'])?$get['page'] : 1;
                     for($i=1;$i<=$number_of_pages;$i++){
         
                     $get['page'] = $i;
                     $qs = http_build_query($get,'','&amp;');
                     if($i==$current_page) {
                     $pagLink = "<a class='active' href='rooms.php?$qs'>$i</a>";
                        }else{
                         $pagLink = "<a  class='inactive' href='rooms.php?$qs'>$i</a>";
                        }
                       echo $pagLink;echo str_repeat('&nbsp;', 2); 
                       }

and finally ajax request which i send to fetchdata.php.I dont know how much you need so i am sending whole data,i dont need updation in all filter types you can just show me logic.


   function filter_data()
   {
       $('.filter_data').html('<div id="loading" style="" ></div>');
       var action = 'fetch_data';
       var minimum_price = $('#hidden_minimum_price').val();
       var maximum_price = $('#hidden_maximum_price').val();
       var typeofproperty = get_filter('typeofproperty');
       var area = get_filter('area');
       var fortypepro = get_filter('fortypepro');
       $.ajax({
           url:"fetch_data.php",
           method:"POST",
           data:{action:action, minimum_price:minimum_price, maximum_price:maximum_price, typeofproperty:typeofproperty, area:area, fortypepro:fortypepro},
           success:function(data){
               $('.filter_data').html(data);
           }
       });
   }

   function get_filter(class_name)
   {
       var filter = [];
       $('.'+class_name+':checked').each(function(){
           filter.push($(this).val());
       });
       return filter;
   }

   $('.common_selector').click(function(){
       filter_data();
   });

   $('#price_range').slider({
       range:true,
       min:1000,
       max:65000,
       values:[1000, 65000],
       step:500,
       stop:function(event, ui)
       {
           $('#price_show').html(ui.values[0] + ' - ' + ui.values[1]);
           $('#hidden_minimum_price').val(ui.values[0]);
           $('#hidden_maximum_price').val(ui.values[1]);
           filter_data();
       }
   });```
Please help me to :
1 maintain filter data on going to next page and also keep filter checkboxes on next page,
2 redirect user to page 1 on applying filter on any page,