php

WooCommerce Add to cart redirection to previous URL

自闭症网瘾萝莉.ら 提交于 2021-02-20 04:19:47
问题 At the request of users, I need the add to cart button on the individual product page to redirect users to the previous page after clicking add product to cart. With following code, customer returns to a specific page (in this case the shop page): function my_custom_add_to_cart_redirect( $url ) { $url = get_permalink( 311 ); // URL to redirect to (1 is the page ID here) return $url; } add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' ); with this code the users

Laravel viaRemember always returning false

余生颓废 提交于 2021-02-20 04:16:14
问题 I've had trouble with keeping my users logged in, so I did some testing and I noticed that the function viaRemember always returns false . This is my login controller function with all the irrelevant code stripped off: public function postSignin(Request $request, AppMailer $mailer) { $this->validate($request, [ 'email' => 'required', 'password' => 'required', ]); $username = $request->get('email'); $password = $request->get('password'); $field = filter_var($username,FILTER_VALIDATE_EMAIL)?

How Can I extract the image path from <ri:attachment ri:filename=“stories-img-05.png” />

落爺英雄遲暮 提交于 2021-02-20 04:14:07
问题 Here is the original code where I am extracted the data using Simple HTML Dom: <div class="content-wrapper"><p><ac:image ac:height="250"><ri:attachment ri:filename="stories-img-05.png" /></ac:image></p></div> Here is the code which i am using : $html->find('div[class=content-wrapper] p ac:image ', 0)->innertext; How can I get Image Path? 回答1: For multiple use this code: $img=array(); foreach($html->find('div.content-wrapper ri:attachment[ri:filename]') as $article) { array_push($img, $article

How to pass the values of localstorage from view to controller to use as php variable in another view

老子叫甜甜 提交于 2021-02-20 04:12:56
问题 In view on click of button am using location.href to pass on to controller. How can i pass the localstorage value in order to use it as a php variable In view: echo Html::button('Proceed', [ 'onclick' => " var dataVal = localStorage.getItem('Customers'); if(dataVal.length > 0) { location.href = '" . Yii::$app->urlManager->createUrl(['customers/orders']) . "'; }else{ alert('Please add some items to order!') return false; }",]); 回答1: While this is generally not recommended practice, it is

using JS variable in PHP

微笑、不失礼 提交于 2021-02-20 04:12:34
问题 how can use JS variable in PHP like this ? <script> x = document.getElementById(1).value; var listOf = <?php echo $listOf[x]; ?>; </script> this doesn't work :( 回答1: And rightfully so. PHP is executed on the server , while JavaScript is executed in the client's browser . Those are two different contexts and the variables from one are not visible in the second. You need to have your PHP script output a JavaScript version of the array and then use this one in your script. Something like this: <

How to pass the values of localstorage from view to controller to use as php variable in another view

邮差的信 提交于 2021-02-20 04:12:12
问题 In view on click of button am using location.href to pass on to controller. How can i pass the localstorage value in order to use it as a php variable In view: echo Html::button('Proceed', [ 'onclick' => " var dataVal = localStorage.getItem('Customers'); if(dataVal.length > 0) { location.href = '" . Yii::$app->urlManager->createUrl(['customers/orders']) . "'; }else{ alert('Please add some items to order!') return false; }",]); 回答1: While this is generally not recommended practice, it is

using JS variable in PHP

懵懂的女人 提交于 2021-02-20 04:12:06
问题 how can use JS variable in PHP like this ? <script> x = document.getElementById(1).value; var listOf = <?php echo $listOf[x]; ?>; </script> this doesn't work :( 回答1: And rightfully so. PHP is executed on the server , while JavaScript is executed in the client's browser . Those are two different contexts and the variables from one are not visible in the second. You need to have your PHP script output a JavaScript version of the array and then use this one in your script. Something like this: <

How to connect with pervasive database via php

偶尔善良 提交于 2021-02-20 04:09:02
问题 I need to know how can I connect with pervasive database via php. As I know, I have to use ODBC . I configured it on my Windows 7 system and I created table in pervasive server. This is my code, but it does not work: $connect_string = "DRIVER={Pervasive ODBC Client Interface}; SERVERNAME=localhost; SERVERDSN=demodata;"; $conn = odbc_connect($connect_string, 'root', 'root'); 回答1: You probably already have the ODBC drivers installed; I obtained the latest by installing the Pervasive Client from

Make search in text file case-insensitive

戏子无情 提交于 2021-02-20 04:08:48
问题 I'm using the following function to search for words in a text file. The problem is that this function is case-sensitive. I don't want it to be case-sensitive! How can I make the function case-insensitive? $url = 'files/file.txt'; $thedata = file_get_contents($url); $lines = explode(PHP_EOL, $thedata); $search = 'some search words'; $pattern = preg_quote($search, '/'); $pattern = "/^.*$pattern.*\$/m"; if(preg_match_all($pattern, $thedata, $matches)) { echo implode('<br>', $matches[0]); } else

Woocommerce - Check if product was created less than 60 days ago

陌路散爱 提交于 2021-02-20 04:08:16
问题 I want to check if a Woocommerce product was created less than 60 days ago. - If true, do something. I am obtaining the date the product was created in backend/admin using the official Woocmmerce function $product->get_date_created . My code partially works, but it seems to be checking if $product->get_date_created literally contains the value 60 instead of perfoming the calculation and minusing 60 days from the current DateTime . I have come to this conclusion because my IF statement runs