小编Van*_* D.的帖子

CakePHP添加列不会出现在查询中

new_column在MySQLproduction服务器上添加了一个MyISAM表.

我从/ app/tmp/models文件夹中删除了相应的模型缓存文件.

重新加载页面并检查后,新生成的模型缓存文件包含新列.

使用fields => null读取时,新列不会出现在SQL查询或结果中.

debug($this->read(null, $id));
  //Query generates fields: SELECT Model.column_a, Model.column_b, Model.id WHERE ...
  //Results do not include the new column

debug($this->read(array('new_column'), $id));
  //Query generates fields: SELECT Model.new_column, Model.id WHERE ...
  //Results include the new column and id
Run Code Online (Sandbox Code Playgroud)

可能的警告和其他信息:

  • 该表有39列(为什么这会有问题?)
  • 该模型是一个插件的EXTENDED类
  • 新列定义为TEXT DEFAULT null
  • 该表的先前更新给出了预期结果
  • 应用程序的本地开发副本没有此问题
  • 测试控制器操作启用Configure :: write(debug => 2)
  • CakePHP 2.3.6,PHP 5.4.19,MySQL 5.1.70

如何使模型识别新表定义?我应该调查其他缓存系统吗?


编辑#1:

debug($this->ModelName->getDataSource()->describe('table_name'));
// outputs all columns
// ...
'new_column' => array(
    'type' => …
Run Code Online (Sandbox Code Playgroud)

mysql caching cakephp model

5
推荐指数
2
解决办法
2326
查看次数

TypeScript:将对象条目映射到类型

作为打字稿新手用户,我什至在提出问题时都遇到困难,所以请耐心等待。

我试图创建一个 key => [string + valueObject 接口] 字符串和 valueObjects (作为类型)的映射,然后有一个函数,它根据传递的键强制执行 valueObject 接口。

我觉得最好用一个例子来解释:

// This is an pseudo example stub, not actually working

type ReplaceableWith<T> = string;
//                   ^ the type I'd like to enforce as the argument

const templates = {
  // templateId    // template               // define somehow the interface required for this template
  'animal.sound': 'A {animal} goes {sound}' as ReplaceableWith<{ animal: string; sound: string}>
};

function renderTemplate(
  templateId , // must be a key of templates
  params …
Run Code Online (Sandbox Code Playgroud)

generics type-inference typescript typescript-generics

5
推荐指数
1
解决办法
3816
查看次数

自PHP 5.4以来,在CakePHP 2.1中找不到类"X"

我已经将我的机器从PHP 5.3更新到PHP 5.4,我的CakePHP(版本2.1.1)应用程序不断收到这些错误:

致命错误:在.../Behavior.php中找不到类'字符串'在线...

致命错误:在.../Component.php中找不到类'调试器'在线...

等等.

错误实际上没用,因为错误的LINE和FILE总是声明类声明的结束括号.

经过大量的搜索,我设法通过添加适当的公共/私有函数声明和强参数类型来解决一些错误,AKA:

function beforeSave($Model) {}

//becomes
public function beforeSave(Model $Model){}
Run Code Online (Sandbox Code Playgroud)

php cakephp

3
推荐指数
1
解决办法
6102
查看次数

为什么没有记录jQuery.camelCase()函数?

我搜索了jQuery文档中的"camelCase"并没有找到任何内容,这导致我追逐一个不同的方法名称.最终,我在源代码中找到了它,但它耗费了我相当长的时间.

所以我想知道,为什么API中没有记录这种方法?我记得,过去曾经......

api jquery camelcasing

2
推荐指数
1
解决办法
2562
查看次数