从远程服务器获取图像时如何获取文件名?以及如何保存原始大小和文件名?
// Take remote image
$img = Image::make('http://image.info/demo.jpg');
// how to save in the img/original/demo.jpg
$img->save(????);
Run Code Online (Sandbox Code Playgroud)
我使用Intervention,(http://image.intervention.io/api/make)构建CakePHP 3图像行为,我想从远程服务器上提供一个简单的上传,并保持原始图像作为未来操作的来源.
编辑
我问,是否存在Intervention Image方法,该方法从远程服务器获取文件的名称.我知道php copy(),我也可以使用CakePHP文件实用程序,但它给了我远程文件的重复请求.
关于验证的多个问题可能属于一起,因为它们都是在CakePHP 3中解决新的验证概念.
我已阅读的章节(1,2,3的食谱多次),但老实说,我不明白怎么做的正确方法.我也知道GitHub目前有一个关于CakePHP3验证的问题/讨论可能涉及同一主题.
例如使用patchEntity触发验证错误.所以我认为在执行保存操作之前始终检查/显示错误会更好:
// src/Controller/UsersController.php
public function add() {
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->data, ['validate' => 'default'] );
if ( $user->errors() ) {
$this->Flash->error('There was a Entity validation error.');
} else {
// Optional: Manipulate Entity here, e.g. add some automatic values
// Be aware: Entity content will not be validated again by default
if ( $this->Users->save($user) ) {
$this->Flash->succeed('Saved successfully.');
return $this->redirect(['controller' => …
Run Code Online (Sandbox Code Playgroud) 最近我开始使用cakephp3.1,我得到了下面的错误.
警告(2):session_start():试图销毁未初始化的会话[CORE/src/Network/Session.php,第324行]
警告(2):session_start()[function.session-start]:无法解码会话对象.会话已被破坏[CORE/src/Network/Session.php,第324行]
警告(2):session_start()[function.session-start]:无法发送会话缓存限制器 - 已发送的标头(输出从/home/www/service/vendor/cakephp/cakephp/src/Error/Debugger.php开始: 742)[CORE/src/Network/Session.php,第324行]
当我将多字节字设置到会话中时,例如登录用户的名字是日语或者多字节字设置为闪存,就会发生这种情况.
所以我假设我没有安装mbstring扩展.但是已经安装了.
我昨天刚开始使用CakePHP v3.1.3,而且我一次只能在我的CakePHP 2.4.2网站上迁移一小部分.主要是试图了解变化.我遇到了问题Configure::read()
.
一点背景信息:我的数据库中有SettingsSite,SettingsSiteHeaders和SettingsSitesOptions表,我也为这些表做了相应的表对象.在我的SettingsSiteTable类中,我有一个方法可以检索存储在数据库中的设置.一切都很好,以下代码在我的AppController中工作没问题.
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\Core\Configure;
class AppController extends Controller{
public function beforeFilter(Event $event){
debug(Configure::read('SettingsSite.title'));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在我的视图中正确显示值.
我在主题默认布局中有以下代码,位于plugins/Default/src/Template/Layout/default.ctp中
<title>
<?php
echo $this->fetch('title') . ' | ' .
Configure::read('SettingsSite.title');
?>
</title>
Run Code Online (Sandbox Code Playgroud)
我收到一个" 类'配置'没有找到插件/ Default/src/Template/Layout/default.ctp "错误消息.
然后我转到AppView.php文件并在命名空间声明下添加以下行:
use Cake\Core\Configure;
Run Code Online (Sandbox Code Playgroud)
错误仍然存在.
所以我注意到如果我修补了一个实体(编辑方法),并且如果它具有belongsToMany关联,我是否对记录进行了任何数据更改,它将它们标记为脏.我希望如果我在视图中没有对BTM多次选择进行任何更改,那么数据就不会变脏,只有在多次选择中添加或删除选项时才会在修补后将其标记为脏.
数据确实保存正确,它只是脏,但我需要知道它是否脏或干净,因为我在地图表中有_join数据.映射表名为users_locations,具有id,user_id,location_id和static,其中static是tinyint/bool.
我想要做的是仅为新创建的映射表条目标记静态.
我注意到patchEntity正在剥离_joinData作为编组过程的一部分.
因此,查看下面的调试输出,您可以看到在修补位置和user_occupations后,_joinData被剥离.
我不希望知道相关数据是干净还是脏.也许它打算以这种方式工作,我错过了一些东西.思考?
<?php echo $this->Form->input('locations._ids', ['options' => $locations]) ?>
Run Code Online (Sandbox Code Playgroud)
<?php
public function edit($id = null)
{
$user = $this->Users->get($id, [
'contain' => ['Locations', 'UserOccupations']
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
$securityGroups = $this->Users->SecurityGroups->find('list');
$locations = $this->Users->Locations->find('list', [
'order' => ['Locations.name' => 'ASC'],
'keyField' => …
Run Code Online (Sandbox Code Playgroud) Cakephp 3创建一个带标签的无线电容器 - >输入就像那样
<div class="radio">
<label class="radio-acces-checked" for="condition-access-1">
<input id="condition-access-1" type="radio" value="1" name="condition_access">
Free access
</label>
</div>
...
Run Code Online (Sandbox Code Playgroud)
我想改变结构,但它不起作用,它始终是相同的结构...你有一个关于如何解决我的问题的想法?
$myTemplates = [
'radioWrapper' => '<div class="radio">{{label}}{{input}}</div>'
];
echo $this->Form->radio('condition_access', [
['value' => 1, 'text' => __('Free Access')],
['value' => 2, 'text' => __('Payment Access')],
['value' => 3, 'text' => __('Reduce price')]
]);
Run Code Online (Sandbox Code Playgroud) 我遇到一个会话被无处摧毁的问题:
session_start(): Failed to decode session object. Session has been destroyed
。
由于我已在服务器日志中抛出此问题,因此无法复制该问题。
任何想法可能是该问题的根源和/或从哪里开始,因为我变得非常罕见(几乎从来没有)。
我想实现食谱及其相关成分的搜索功能。用户应该指定他想要从搜索中排除的成分,同时指定他正在寻找的食谱中包含的成分。
这是我的两个发现者:
public function findByContainingIngredients(Query $query, array $params)
{
$ingredients = preg_replace('/\s+/', '', $params['containing_ingredients']);
if($ingredients) {
$ingredients = explode(',', $ingredients);
$query->distinct(['Recipes.id']);
$query->matching('Ingredients', function ($query) use($ingredients) {
return $query->where(function ($exp, $query) use($ingredients) {
return $exp->in('Ingredients.title', $ingredients);
});
});
}
return $query;
}
public function findByExcludingIngredients(Query $query, array $params)
{
$ingredients = preg_replace('/\s+/', '', $params['excluding_ingredients']);
if($ingredients) {
$ingredients = explode(',', $ingredients);
$query->distinct(['Recipes.id']);
$query->notMatching('Ingredients', function ($query) use ($ingredients) {
return $query->where(function ($exp, $query) use ($ingredients) {
return $exp->in('Ingredients.title', $ingredients);
});
});
}
return …
Run Code Online (Sandbox Code Playgroud) 我有两个表products
和product_categories
被通过第三表相关联,products_categories_products
根据CakePHP的BelongsToMany约定(编辑:这些关联建立ProductsTable.php
和ProductCategoriesTable.php
)。我想生成一个产品类别列表,使用最畅销产品的图像来代表每个类别。
我可以使用以下功能实现我想要的结果:
public function findImages(Query $query, array $options) {
$query->select([
'ProductCategories.id',
'ProductCategories.name',
'ProductCategories__image' => '(SELECT Products.image
FROM product_categories_products AS ProductCategoriesProducts
LEFT JOIN products AS Products
ON ProductCategoriesProducts.product_id = Products.id
WHERE ProductCategoriesProducts.product_category_id = ProductCategories.id
ORDER BY Products.turnover DESC
LIMIT 1)'
])->where([
'ProductCategories.name <>' => 'Unsorted'
])->order([
'ProductCategories.name' => 'asc'
]);
return $query;
}
Run Code Online (Sandbox Code Playgroud)
这是可以接受的还是有更简单的方法来实现我的目标?我真的找不到关于在 CakePHP 3 中制作子查询的主题的任何内容。经过几个小时的挫折后,我偶然发现了上述解决方案。任何建议表示赞赏!
有没有人有一个验证方法来配置PhpStorm 10.x在CakePHP 3.x中运行单元测试?
编辑:在@ndm的回答之后我修复了我的PhpStorm配置,将"phpunit.xml.dist"添加到PHPUnit> Test Runner:Checked Default配置文件.
现在我有不同的错误
/Applications/MAMP/bin/php/php5.6.10/bin/php /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/phpunit --configuration /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/phpunit.xml.dist /Applications/MAMP/htdocs/sites/my_app --teamcity
Testing started at 12:29 ...
PHP Warning: require(/Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/../vendor/autoload.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/bootstrap.php on line 3
PHP Fatal error: require(): Failed opening required '/Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/../vendor/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.10/lib/php') in /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/bootstrap.php on line 3
Process finished with exit code 255
Run Code Online (Sandbox Code Playgroud)
在Run Config中,PHPUnit:Test Runner - > Test Scope - > Directory:
/Applications/MAMP/htdocs/sites/my_app/src
Run Code Online (Sandbox Code Playgroud) cakephp-3.1 ×10
cakephp ×8
php ×4
cakephp-3.0 ×2
cakephp-3.x ×2
associations ×1
conventions ×1
forms ×1
helper ×1
intervention ×1
laravel ×1
matching ×1
multibyte ×1
phpstorm ×1
radio ×1
session ×1
subquery ×1
validation ×1