我有一个功能,这样做:
$order = new WC_Order($order_id);
$customer = new WC_Customer( $order_id );
Run Code Online (Sandbox Code Playgroud)
如何从中获取客户详细信息?我已经尝试了文档中的所有内容,但不知何故,只是存在一些细节,但其余的不是,例如
$data['Address'] = $customer->get_address() . ' ' . $customer->get_address_2();
$data['ZipCode'] = $customer->get_postcode();
Run Code Online (Sandbox Code Playgroud)
是空的.
干
var_dump($customer)
Run Code Online (Sandbox Code Playgroud)
生产:
object(WC_Customer)#654(2){["_ data":protected] => array(14){["country"] => string(2)"IT"> ["state"] => string(0) ""["postcode"] => string(0)""["city"] => string(0)""["address"] = >> string(0)""["address_2"] => string (0)""["shipping_country"] => string(2)"IT"["shipping_state"] => string(2)"BG"["shipping_postcode"] => string(0)""["shipping_city" ] = >> string(0)""["shipping_address"] => string(0)""["shipping_address_2"] => string(0)""["is_vat_exempt"] => bool(false)["calculated_shipping "] => bool(false)}?["_changed":"WC_Customer":private] => bool(false)}
正如你所看到的,这个城市是现在的,但其余的都是空的.我已经检查了客户的WP_usermeta和管理面板,所有数据都在那里.
有什么想法吗?
由于BD设计取决于值,数据存储在不同的单元格中,我必须动态添加表单字段.我在想这个:
class EditFlatForm(BaseModelForm):
on_sale = forms.BooleanField(required=False)
on_rent = forms.BooleanField(required=False)
class Meta:
model = Flat
fields = ('title', 'flat_category', 'description')
...
def __init__(self, *args, **kwargs):
super(EditFlatForm, self).__init__(*args,**kwargs)
flat_properties = FlatProperty.objects.all()
for p in flat_properties:
if p.type_value == 1:
# Text
setattr(self, p.title, forms.CharField(label=p.human_title, required=False))
elif p.type_value == 2:
# Number
setattr(self, p.title, forms.IntegerField(label=p.human_title, required=False))
else:
# Boolean
setattr(self, p.title, forms.BooleanField(label=p.human_title, required=False))
Run Code Online (Sandbox Code Playgroud)
但这些字段没有添加,我错过了什么?
我正在与SlimPHP和Eloquent合作开展一个项目.我试图在Model的方法中运行RAW SQL查询,如下所示:
/models/Form.php
<?php
namespace models;
class Form extends \Illuminate\Database\Eloquent\Model {
protected $table = 'forms';
public function getResponses($form_id)
{
// HERE
$select = \Illuminate\Support\Facades\DB::select('select 1');
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Capsule来引导ORM.
上面的代码给了我:
致命错误:在第208行的/vagrant/vendor/illuminate/support/Illuminate/Support/Facades/Facade.php中调用非对象上的成员函数select()
在这种情况下,文档非常有帮助,您能否对此有所了解?
谢谢
我有一个具有以下目录结构的Slim应用程序:
app/
vendor/
www/
config.php
Run Code Online (Sandbox Code Playgroud)
在app/I中有项目的相关文件,在供应商/由作曲家管理的依赖项和www/web服务器可访问的文件中.
所以我想创建一个Phar文件:
<?php
$full_path = '/home/.../forms/';
$package_name = 'www/package.phar';
try {
$phar = new Phar($full_path . $package_name,
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $full_path . $package_name);
$phar->startBuffering();
$phar->addFile($full_path . 'www/index.php');
$phar->addFile($full_path . 'www/bootstrap.php');
$phar->addFile($full_path . 'www/session_start.php');
// Grab config
$phar->addFile($full_path . 'config.php');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../app', FilesystemIterator::SKIP_DOTS)),'../app');
$phar->buildFromIterator(new RecursiveIteratorIterator (new RecursiveDirectoryIterator('../vendor', FilesystemIterator::SKIP_DOTS)),'../vendor');
$phar->setDefaultStub('bootstrap.php', 'bootstrap.php');
$phar->stopBuffering();
echo "Phar created.";
} catch (Exception $e) {
// handle errors here
echo $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
所以我创建了phar,然后我有:
deploy.php
<?php
require_once 'phar://package.phar/bootstrap.php';
$app->run();
Run Code Online (Sandbox Code Playgroud)
但是在访问/deploy.php时我得到了:
[2015年5月15日星期五20:07:02] …
我有这段代码:
case Timex.Timezone.get(data) do
{:error, _} = error ->
error
data ->
{:ok, data}
end
Run Code Online (Sandbox Code Playgroud)
将保存在数据库中的时区放入结构中。
好吧,当运行通过 Ecto 查询获取一些数据的迁移时,我收到此错误:
** (ArgumentError) argument error
(stdlib) :ets.lookup(:tzdata_current_release, :release_version)
lib/tzdata/release_reader.ex:47: Tzdata.ReleaseReader.current_release_from_table/0
lib/tzdata/release_reader.ex:14: Tzdata.ReleaseReader.simple_lookup/1
lib/tzdata/release_reader.ex:7: Tzdata.ReleaseReader.zone_and_link_list/0
lib/tzdata.ex:40: Tzdata.zone_exists?/1
lib/timezone/timezone.ex:152: Timex.Timezone.name_of/1
lib/timezone/timezone.ex:180: Timex.Timezone.get/2
lib/common/ecto/timezone.ex:27: Common.Ecto.Timezone.load/1
(ecto) lib/ecto/type.ex:661: Ecto.Type.process_loaders/3
(ecto) lib/ecto/schema.ex:1490: Ecto.Schema.load!/5
(ecto) lib/ecto/schema.ex:1442: Ecto.Schema.safe_load_zip/4
(ecto) lib/ecto/schema.ex:1443: Ecto.Schema.safe_load_zip/4
(ecto) lib/ecto/schema.ex:1430: Ecto.Schema.__safe_load__/6
(ecto) lib/ecto/repo/queryable.ex:282: Ecto.Repo.Queryable.process_source/6
(ecto) lib/ecto/repo/queryable.ex:170: Ecto.Repo.Queryable.preprocess/5
(postgrex) lib/postgrex/query.ex:77: DBConnection.Query.Postgrex.Query.decode_map/3
(postgrex) lib/postgrex/query.ex:64: DBConnection.Query.Postgrex.Query.decode/3
(db_connection) lib/db_connection.ex:1019: DBConnection.decode/6
(ecto) lib/ecto/adapters/postgres/connection.ex:73: Ecto.Adapters.Postgres.Connection.prepare_execute/5
(ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
Run Code Online (Sandbox Code Playgroud)
在堆栈跟踪中包含该代码并执行一些检查可以验证这确实是触发错误的调用,尽管这样做:
iex(1)> Timex.Timezone.get("America/Los_Angeles")
#<TimezoneInfo(America/Los_Angeles …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个 Python 脚本,以使用 Python 中的加密技术将 EC 私钥从 PKCS8 PEM 转换为 DER 。
我之前可以使用 openssl 执行此操作,如下所示:
openssl pkcs8 -nocrypt -in pem_key.p8 -out der_key.der -outform der
Run Code Online (Sandbox Code Playgroud)
我通过执行以下操作来验证使用 OpenSSL 生成的 DER 文件是否正确:
from ecdsa import SigningKey
file = open('der_key.der', 'rb')
SigningKey.from_der(file.read())
>>> <ecdsa.keys.SigningKey at 0x112bd3630>
Run Code Online (Sandbox Code Playgroud)
现在我尝试使用 Python 做同样的事情
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
pem_key_bytes = str.encode(pem_key)
key = serialization.load_pem_private_key(
pem_key_bytes, password=None, backend=default_backend()
)
pri_der = key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
)
Run Code Online (Sandbox Code Playgroud)
然而,当使用上面相同的方法在 DER 编码中测试此密钥时,我得到:
UnexpectedDER:DER 私钥开始时预期为“1”,结果为 0
我缺少什么?
我正在通过Ant Colony Optimization实现一个15-puzzle解算器,我正在考虑一种有效地将每个状态散列为一个数字的方法,所以我浪费了最少的字节数.
状态由16个数字的列表表示,从0到15(0是空洞).
喜欢:
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0]
所以我想创建一个唯一的数字来识别该状态.我可以将所有数字转换为基数为16的数字,但我不认为这是非常有效的任何想法?
谢谢
我试图在Slim中使用Twig访问Eloquent属性,并收到错误.
我有一个Field和一个Type对象,关系如下
class Field extends \Illuminate\Database\Eloquent\Model {
protected $table = 'fields';
public function type()
{
return $this->belongsTo('models\Type');
}
Run Code Online (Sandbox Code Playgroud)
在做{{ f }}(作为fa字段)时,输出是这样的:
{"field_id":"1","field_name":"Your name","form_id":"2","type_id":"1","placeholder":"Please give us your name"}
Run Code Online (Sandbox Code Playgroud)
在做的时候{{ f.type }},结果是:
消息:在第97行的"pages/editform.html"中呈现模板("类Illuminate\Database\Eloquent\Relations\BelongsTo的对象无法转换为字符串")期间抛出了异常.
如果我尝试这样做{{ f.type.name }},不会抛出异常,但也不会打印任何东西.
如果我用PHP做的话
$fields = $form->fields;
var_dump($fields[0]->type->name);
Run Code Online (Sandbox Code Playgroud)
该值正确输出.
有什么想法吗?谢谢
我正在通过 Ansible 配置带有 Django Stack 的服务器并从 bitbucket 获取应用程序,我使用的是https://github.com/jcalazan/ansible-django-stack,但我不得不对其进行一些调整才能使它与私人 bitbucket 存储库一起使用。
现在它正确地进行了身份验证,但给了我以下错误
failed: [default] => {"failed": true} msg: youtubeadl: ERROR (not running) youtubeadl: ERROR (异常终止)
执行此任务时:
- name: Restart Supervisor
supervisorctl: name={{ application_name }} state=restarted
Run Code Online (Sandbox Code Playgroud)
阅读gunicorn ERROR (abnormal terminate),我想将项目添加到 PYTHONPATH,任何想法如何通过 Ansible 任务来解决这个问题,或者我错过了什么?
谢谢
我通过Ansible配置'Precise64'Ubuntu机器,在确保数据库实际创建时遇到错误.我使用的大部分是https://github.com/jcalazan/ansible-django-stack
- name: Install PostgreSQL
apt: name={{ item }} update_cache={{ update_apt_cache }} state=installed
with_items:
- postgresql
- postgresql-contrib
- python-psycopg2
tags: packages
- name: Ensure the PostgreSQL service is running
service: name=postgresql state=started enabled=yes
- name: Ensure database is created
sudo_user: postgres
postgresql_db: name={{ db_name }}
encoding='UTF-8'
lc_collate='en_US.UTF-8'
lc_ctype='en_US.UTF-8'
template='template0'
state=present
Run Code Online (Sandbox Code Playgroud)
但是,当到达最后一个任务时,我收到此错误:
失败:[default] => {"failed":true,"playbook":"vagrant.yml","role":"db","task":"确保数据库已创建"} msg:无法连接到数据库:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受Unix域套接字"/var/run/postgresql/.s.PGSQL.5432"上的连接?
致命:所有主机都已经失败 - 中止
php ×4
ansible ×2
django ×2
eloquent ×2
python ×2
slim ×2
algorithm ×1
cryptography ×1
ecdsa ×1
ecto ×1
elixir ×1
forms ×1
hash ×1
phar ×1
postgresql ×1
public-key ×1
supervisord ×1
twig ×1
tzdata ×1
woocommerce ×1
wordpress ×1