有没有办法在Yii2/Codeception ActiveFixture中的夹具数据文件中指定另一个夹具的相关行?考虑这个用户/配置文件关系的示例:
user.php的:
return [
'user1' => [
'email' => 'user1@example.net',
]
];
Run Code Online (Sandbox Code Playgroud)
profile.php:
use common\models\User;
return [
'profile1' => [
'user_id' => User::findOne(['email' => 'user1@example.net'])->id;
'name' => 'My Name',
]
];
Run Code Online (Sandbox Code Playgroud)
该文档指出"您可以为行添加别名,以便在测试后期,您可以通过别名引用该行." 有没有办法在另一个灯具内引用行?例如,在profile.php中使用类似$ this-> user('user1') - > id的内容?关于如何做到,我找不到任何提及.你如何创造这种相关的装置?
我正在尝试上传django admin inlines中的图像文件,并在尝试上传包含非ascii字符的文件名时获取UnicodeEncodeError:
File "/usr/local/lib/python2.6/site-packages/django/db/models/fields/files.py", line 92, in save
self.name = self.storage.save(name, content)
File "/usr/local/lib/python2.6/site-packages/django/core/files/storage.py", line 47, in save
name = self.get_available_name(name)
File "/usr/local/lib/python2.6/site-packages/django/core/files/storage.py", line 73, in get_available_name
while self.exists(name):
File "/usr/local/lib/python2.6/site-packages/django/core/files/storage.py", line 196, in exists
return os.path.exists(self.path(name))
File "/usr/local/lib/python2.6/genericpath.py", line 18, in exists
st = os.stat(path)
Run Code Online (Sandbox Code Playgroud)
在Django文档中有一个关于这个问题的段落:http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror - 他们说我必须定义LANG和LC_ALL env变量,加上使用os.env定义它们将不起作用.所以我在我的.htaccess文件中定义了它们,我确信它们在那里:
META
Variable Value
CONTENT_LENGTH '27289'
...
LANG 'en_US.UTF-8'
LC_ALL 'en_US.UTF-8'
LC_LANG 'en_US.UTF-8'
Run Code Online (Sandbox Code Playgroud)
问题依然存在.Django版本是1.2.3(最新稳定版),sys.getfilesystemencoding()(我认为与该问题相关)返回"ANSI_X3.4-1968".
模型/管理代码没有什么特别之处:带ImageField的ArticleImage模型和包含ArticleImage内联的ArticleAdmin.
更新我无法修复此问题所以我放弃使用apache设置并使用runfcgi + nginx启动应用程序.上传工作正常,但我不是将其作为解决方案添加,因为问题是关于apache.
我有一段代码(让我们命名为Code A)在框架中工作,我想让它在另一个框架中工作.工作代码使用CURL成功发出POST请求(使用CURLOPT_VERBOSE的请求):
* Connected to android.clients.google.com (216.58.209.238) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /Applications/MAMP/Library/OpenSSL/cert.pem
CApath: none
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.google.com
* start date: Jan 18 19:17:59 2017 GMT
* expire date: Apr 12 18:51:00 2017 GMT
* subjectAltName: host "android.clients.google.com" matched cert's "android.clients.google.com"
* issuer: …Run Code Online (Sandbox Code Playgroud) 如何使VIM始终在命令模式下自动完成文件名?当我键入例如":cd/ww [Tab]"时它工作正常,但如果我想打开一个文件并输入":o/ww [Tab]",它会插入"^ I"字符而不是完成.
我正在尝试创建一个简单的搜索表单(它将很快变得更复杂,所以我在这里使用ActiveForm而不是简单地将GET参数传递给action方法).
控制器:
public function actionIndex()
{
$search_form = new UserSearchForm();
$search_form->load(Yii::$app->request->get(), $formName = '');
return $this->render('index', [
'search_form' => $search_form
]);
}
Run Code Online (Sandbox Code Playgroud)
视图:
<?php $form = ActiveForm::begin(['id' => 'search-form', 'method' => 'get']); ?>
<?= $form->field($search_form, 'q')->textInput(['name' => 'q']) ?>
<?= Html::submitButton('Search') ?>
<?php ActiveForm::end(); ?>
Run Code Online (Sandbox Code Playgroud)
我在控制器中使用$ formName =''和'name'=>'q'以使查询字符串更清晰(简单q而不是UserSearchForm [q]).
在第一次提交之前,一切都很好.我在表单中看到隐藏的q字段,在第二次提交后,URL看起来像/ user?q = value1&q = value2,每个提交都会向隐藏字段添加另一个q.有没有一个好方法摆脱那些隐藏的领域?或许整个方法都错了?我想我无论如何都需要隐藏的字段(排序,分页等).