我一直试图找到一种方法来确定Laravel中的ajax调用,但我没有找到任何关于它的文档.
我有一个index()
函数,我想根据请求的性质不同地处理情况.基本上这是一个绑定到GET请求的资源控制器方法.
public function index()
{
if(!$this->isLogin())
return Redirect::to('login');
if(isAjax()) // This is what i am needing.
{
return $JSON;
}
$data = array();
$data['records'] = $this->table->fetchAll();
$this->setLayout(compact('data'));
}
Run Code Online (Sandbox Code Playgroud)
我知道在PHP中确定Ajax请求的其他方法,但我想要一些特定于Laravel的东西.
谢谢
更新:
我试过用
if(Request::ajax())
{
echo 'Ajax';
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误: Non-static method Illuminate\Http\Request::ajax() should not be called statically, assuming $this from incompatible context
该类显示这不是静态方法.
我在Laravel中使用MongoDB.我有一个叫categories
有一个文档的集合
[
{
"_id": "567dc4b4279871d0068b4568",
"name": "Fashion",
"images": "http://example.com/1.jpg",
"specifics": [
"made"
],
"brands": [
{
"name": "Giordano",
"logo": "http://example.com/"
},
{
"name": "Armani",
"logo": "http://example.com/"
}
],
"updated_at": "2015-12-25 22:40:44",
"created_at": "2015-12-25 22:35:32"
}
]
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个函数,在上面的文档中添加特定数组的细节.
这是我的请求机构的方式
HTTP: POST
{
"specifics": [
"material"
]
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下功能处理此请求
/**
* Add specs to category
* @param string $category_id
* @return Illuminate\Http\JsonResponse
*/
public function addSpecifics($category_id)
{
$category = $this->category->findOrFail($category_id);
$category->specifics[] = $this->request->get('specifics');
$status_code = config('http.UPDATED');
return response()->json($category->save(), $status_code);
} …
Run Code Online (Sandbox Code Playgroud) 考虑:
const fields = ['email', 'password'];
const objFields = {};
fields.forEach(value => {
objFields[value] = '';
});
console.log(objFields);
// Outputs {email: "", password: ""}
Run Code Online (Sandbox Code Playgroud)
我想获得相同的结果,但不必初始化一个空对象。
实际上,我的情况是我想设置 React 组件的初始状态。
class App extends Component {
fields = ['email', 'password'];
state = {
fields: // The one liner code here that should return the object created from fields array,
};
...
Run Code Online (Sandbox Code Playgroud)
预期结果是
// state = {fields: {email: "", password: ""}}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用money_format
功能.
<?php
$number = 1299.46;
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number); // Outputs 1299.46
Run Code Online (Sandbox Code Playgroud)
虽然它应该打印$ sign或USD?
我在linux主机上.
谢谢
这是我的 docker-compose.yml
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
image: php:7.0-fpm
expose:
- 9000
volumes_from:
- app
links:
- elastic
app:
image: php:7.0-fpm
volumes:
- .:/var/www/html
command: "true"
elastic:
image: elasticsearch:2.3
volumes:
- ./elasticsearch/data:/usr/share/elasticsearch/data
- ./elasticsearch/logs:/usr/share/elasticsearch/logs
expose:
- "9200"
ports:
- "9200:9200"
Run Code Online (Sandbox Code Playgroud)
当我尝试访问Elasticsearch时,localhost:9200
它会起作用.
但是当我尝试使用PHP创建索引时,我收到以下错误:
致命错误:未捕获Elasticsearch\Common\Exceptions\NoNodesAvailableException:未在群集中找到活动节点
这是客户端代码:
<?php
namespace App\Elasticsearch;
use Elasticsearch\ClientBuilder;
class Client
{
public static function getClient()
{
return ClientBuilder::create()
->build();
}
}
Run Code Online (Sandbox Code Playgroud)
用于实例化Elasticsearch对象的代码:
<?php
require 'vendor/autoload.php';
use App\Elasticsearch\Client;
use App\Elasticsearch\Indices\UserIndex; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试查找文档或代码示例,如何在 Material UI 主题中指定附加颜色。
现在我有以下主题配置
const theme = createMuiTheme({
palette: {
primary: {
main: "#B31728"
},
secondary: {
main: "#202833"
}
},
...
Run Code Online (Sandbox Code Playgroud)
现在我有一个案例,我想使用颜色进行成功的操作,例如
import { green } from "@material-ui/core/colors";
<Fragment>
{isVerified ? (
<VerifiedUser style={{ color: green[500] }} />
) : (
<Error color="primary" />
)}
</Fragment>
Run Code Online (Sandbox Code Playgroud)
我想以设置错误图标的相同方式设置VerifiedUser图标的颜色。但是主题调色板配置只有主要和次要目的。如何设置颜色让我说“成功”,这样我就可以像
<VerifiedUser color="success" />
Run Code Online (Sandbox Code Playgroud) 我有这个 docker compose 文件
version: "2"
services:
abc_python_test:
build: "python"
container_name: "abc-python-test"
volumes:
- "../:/abc/"
working_dir: "/abc"
command: "sh -c 'python3 -m unittest tests/calculator.py'"
Run Code Online (Sandbox Code Playgroud)
我有以下 Makefile
test:
cp config/config-$(env).cfg config/config.cfg
docker-compose -f environment/test.yml up --build
Run Code Online (Sandbox Code Playgroud)
Makefile
我在 CI 中的构建步骤之一中运行它。
问题是,测试运行失败,python3
进程得到exit code 1
. 然而,一旦该python3
过程完成,容器就会下降。但我的主机显示status code 0
. 即使测试失败,这也会导致我的构建通过。
如何将此python3
退出代码转发到我的主进程,以便它知道测试失败。
谢谢
PS:我们有旧的 docker compose 版本,没有附带该--exit-code-from
标志
python teamcity continuous-integration docker docker-compose
我非常需要你的帮助guyz,我在我的办公室有一个wordpress项目,客户选择了一个页面的html模板,并要求将其转换为wordpress.我知道如何将html转换为worpdress普通主题,但因为主题只有一个页面,多个div作为页面.我不知道怎么做.
我很抱歉,因为这不是一个如何平台,但我需要一个起点.
主题标记如下
<!--Home Page
=============================-->
<div id="home" class="item">
<!--<img src="assets/img/2.jpg" alt="The Spice Lounge" class="fullBg">-->
<div class="clearfix">
<div class="header_details">
<div class="container">
<div class="header_icons accura-header-block accura-hidden-2xs">
<ul class="accura-social-icons accura-stacked accura-jump accura-full-height accura-bordered accura-small accura-colored-bg clearFix">
<li id="1"><a href="#" class="accura-social-icon-facebook circle"><i class="fa fa-facebook"></i></a></li>
<li id="2"><a href="#" class="accura-social-icon-twitter circle"><i class="fa fa-twitter"></i></a></li>
<li id="3"><a href="#" class="accura-social-icon-gplus circle"><i class="fa fa-google-plus"></i></a></li>
<li id="4"><a href="#" class="accura-social-icon-pinterest circle"><i class="fa fa-pinterest"></i></a></li>
<li id="5"><a href="#" class="accura-social-icon-linkedin circle"><i class="fa fa-linkedin"></i></a></li>
</ul>
</div>
<div class="call">
<div class="home_address">
#12 FIFTH MAIN STREET,<br> NY …
Run Code Online (Sandbox Code Playgroud) 我正在手动获取 woocommerce 产品。
问题是我在产品上有一个自定义字段,即 _locations。一个产品可以属于多个位置,所以我在 wp-admin 的产品添加表单中提供了一个多选列表。
下面是我用来保存 meta_value 的函数
function woo_add_custom_general_fields_save( $post_id ){
// Select
$woocommerce_select = $_POST['_locations'];
if( !empty( $woocommerce_select ) )
update_post_meta( $post_id, '_locations', esc_attr(maybe_serialize($woocommerce_select )) );
}
Run Code Online (Sandbox Code Playgroud)
请注意,我已经序列化了 meta_value 的数据,因此我只有一个唯一键_locations
,所有位置值都与之关联。
现在在我取货时出现问题
$args = array(
'post_type' => 'product',
'product_cat' => $food_category->slug,
'meta_key' => '_locations',
'meta_value' => 'newyork'
);
$loop = new WP_Query($args);
Run Code Online (Sandbox Code Playgroud)
我只想获取产品newyork
但在数据库中它存储为序列化数组
s:69:"a:2:{i:0;s:7:"newyork";i:1;s:13:"massachusetts";}";
Run Code Online (Sandbox Code Playgroud)
我怎样才能让这个查询只获取纽约产品。
谢谢
add_action('woocommerce_checkout_order_processed', 'send_order_fax');
function send_order_fax($order_id) {
print_r($_REQUEST);
die();
}
Run Code Online (Sandbox Code Playgroud)
我希望在此挂钩触发时获取订单ID或订单详细信息,以便我可以生成传真.但它只发送表单数据.我如何获得订单ID,以便我可以通过功能获取其他东西.
谢谢
php ×5
wordpress ×3
docker ×2
laravel ×2
ecmascript-6 ×1
javascript ×1
laravel-5 ×1
material-ui ×1
mongodb ×1
python ×1
reactjs ×1
teamcity ×1
woocommerce ×1