我想知道,是否有一个函数可以让我立即检查数据库中的记录是否存在?
现在我正在使用以下代码来检测记录是否存在,但我可以想象有一种更简单/更好的方法.
$conditions = array(
'conditions' => array(
'User.id' => $this->Session->read('User.id'),
'User.activation_key' => $this->Session->read('User.key')
)
);
$result = $this->User->find('first', $conditions);
if (isset($result['User'])){
//do something
}
Run Code Online (Sandbox Code Playgroud)
是否有类似的东西:
$conditions = array(
'conditions' => array(
'User.id' => $this->Session->read('User.id'),
'User.security_key' => $this->Session->read('User.key')
)
);
if ($this->User->exists($conditions)){
//do something
}
Run Code Online (Sandbox Code Playgroud)
好的,是的.它被称为exists(),但我需要相同,但有参数,所以我可以添加自己的条件进行检查.
我搜索过谷歌,但我找不到任何关于此的话题.好吧,很多关于php和mysql,但不是关于cakephp.我需要一个蛋糕特定的答案.
谢谢你的时间 :)
我有一个让我疯狂的问题,我不得不承认我在CakePHP中没有经验.正如在这个问题中提到的, 在CakePHP查找函数中使用DISTINCT,这样使用DISTINCT:
$this->Model->find('all', array('fields'=>'DISTINCT field_name'));
Run Code Online (Sandbox Code Playgroud)
不返回DISTINCT值,而是返回所有行.事实上,这里的DISTINCT完全没有意义,因为由于某种原因,CakePHP补充道TableName.id在SQL查询中(为什么??我可以删除id引用??),有效地返回每个DISTINCT主键(= all rows = unhelpful).
所以,我仍然想要返回特定field_name列的DISTINCT值.我不能只使用find('all')或find('list')函数吗?是否真的是使用上面链接中描述的Set :: extract()函数来实现它的正确方法?这似乎是CakePHP过度间接的解决方案,通常Cake会让我的生活更轻松.:-)将find和DISTINCT一起使用的正确方法是什么?也许DISTINCT不适用于find()?
看看CookBook,他们说:"做一个DISTINCT查询的快速例子.你可以用类似的方式使用其他运算符,如MIN(),MAX()等:"
<?php
array(
'fields' => array('DISTINCT (User.name) AS my_column_name'),
'order' = >array('User.id DESC')
)
?>
Run Code Online (Sandbox Code Playgroud)
资料来源:http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
这表明DISTINCT应该可以使用,但是这里有什么用呢?(User.name)对应于我想要DISTINCT的field_name还是my_column_name my field_name?
最后,从CakePHP 1.x迁移到CakePHP 2.x时,是否有任何改变?即在Stackoverflow上看到的CakePHP 1.x的答案仍然相关吗?
提前致谢!
我有两个型号Group_ones和Group_twos.我在ac_config.ctp文件中显示此值.
我的控制器代码如下
public function ac_config($id = null)
{
if (!$id) {
$this->Session->setFlash('Please provide a Site id');
$this->redirect(array('action'=>'dashboard'));
}
$site_id_1 = $this->GroupOne->findById($id);
$site_name = $site_id_1['GroupOne']['site_name'];
$ac_one_time = $site_id_1['GroupOne']['ac_on_time_one'];
$group_one_active = $site_id_1['GroupOne']['active'];
$site_id_2 = $this->GroupTwo->findById($id);
$ac_two_time = $site_id_2['GroupTwo']['ac_on_time_two'];
$group_two_active = $site_id_2['GroupTwo']['active'];
if (!$site_id_1) {
$this->Session->setFlash('Invalid Site ID Provided');
$this->redirect(array('action'=>'dashboard'));
}
if (!$site_id_2) {
$this->Session->setFlash('Invalid Site ID Provided');
$this->redirect(array('action'=>'dashboard'));
}
if ($this->request->is('post') || $this->request->is('put')) {
$this->GroupOne->id = $id;
$this->GroupTwo->id = $id;
if (($this->GroupTwo->save($this->request->data)) || ($this->GroupOne->save($this->request->data))) {
$this->Session->setFlash(__('AC …Run Code Online (Sandbox Code Playgroud) 如何写一个regex匹配空格但没有制表符和换行符?感谢一切
[[:blank:]]{2,} <-- 尽管这对我不利,因为它的空格或制表符而不是换行符。
我正在编写一个基于搜索参数检索图像的机器人。当机器人在命令后返回消息时,我希望机器人用 ping 警告发送命令的用户。(@在不和谐中使用“ ”符号的消息通知)。
这是我到目前为止所得到的:
await Context.Channel.SendMessageAsync("@" + Context.Message.Author + "\n" + imageNode.Attributes["src"].Value);
Run Code Online (Sandbox Code Playgroud)
我能够正确地获取命令的作者并按它应该的方式发送--
通道输出:
然而,它实际上并不是作为标签发送的,只是纯文本。
有没有办法通过通知实际给用户打电话?
我已经在类似于此的Angular组件的构造函数中实现了Visibility API
constructor() {
var hidden, state, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
state = "visibilityState";
}
document.addEventListener(visibilityChange, function() {
if(status == hidden){
console.log("Hidden");
}
else if(status != hidden){
console.log("Visible");
}
}, false);
}
pauseVideo(){
//Video pause code
}
Run Code Online (Sandbox Code Playgroud)
我需要暂停视频,即pauseVideo()在“可见性”更改为“隐藏”时调用该方法,该怎么办?
在我的 react-redux-typescript 应用程序中,我有多个子状态构成应用程序状态。申请状态如下。
interface AppState {
dialogs: DialogState,
messages: MessageState,
notifications: NotificationsState,
errors: ErrorState
loading: LoadingState,
status: StatusState;
}
Run Code Online (Sandbox Code Playgroud)
我使用connect方法将 React 组件中可用的子状态之一作为props. 但是现在我有一个案例,我需要一个组件中的两个子状态属性作为它的props.
具体这些部分:
interface LoadingState {
size: number
available: boolean
}
interface StatusState {
name: string
}
Run Code Online (Sandbox Code Playgroud)
通常,我在组件Loading中使用connect方法如下:
export default connect(
(state: AppState) => state.loading, actionCreators)(Loading);
Run Code Online (Sandbox Code Playgroud)
Loading 组件的头部是:
type LoadingProps = LoadingState & typeof actionCreators;
class Loading extends React.Component<LoadingProps, {}>
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我就有了LoadingState可用作道具的界面属性。但是,如果我还想要StatusState在同一组件中作为 props 使用的属性,我该怎么办?
这是我
使用的英语大写字母 EMNIST 数据库的场景。
我的神经网络如下
现在我500 fixed samples为每个班级做了训练。
简单地说,将500x9图像传递给训练函数,该函数使用backpropagation100 次迭代改变权重learning_rate*derivative_of_loss_wrt_corresponding_weight。
我发现当我在神经元上使用 tanh 激活时,网络学习速度比 relu 学习速度快0.0001。
我得出结论,因为 tanh 在固定测试数据集上的准确率高于 relu 。此外,tanh 在 100 轮之后的损失值略低。
难道 relu 的表现不是更好吗?
使用 webfont,我想使用CSS 中的font-feature-settings:选项以及HTML 中的span 类,以便使用字体集中的特定替代字形。
我需要以正确的语法使用哪些值(GID、Unicode?)才能glyph在glyph替代方案中定位特定值?
我遇到了一个意想不到的问题
<?php
header("Access-Control-Allow-Origin: *");
include_once("Medoo.php");
use Medoo\Medoo;
$db = new Medoo([
'database_type' => 'mysql',
'database_name' => '************',
'server' => 'localhost',
'username' => '************',
'password' => '************'
]);
function getThreads($db, $start, $limit){
$data = $db->select('threads', ['id', 'title', 'content', 'date', 'userid'], ["AND" => ["active" => "1", "limit" => [$start, $limit]]]);
return $data;
}
function utf8ize($d) {
if (is_array($d)) {
foreach ($d as $k => $v) {
$d[$k] = utf8ize($v);
}
}
else if (is_string ($d)) {
return utf8_encode($d);
}
return $d;
} …Run Code Online (Sandbox Code Playgroud) php ×4
cakephp ×3
css ×2
angularjs ×1
bots ×1
c# ×1
cakephp-2.0 ×1
connect ×1
database ×1
discord ×1
discord.net ×1
distinct ×1
extract ×1
find ×1
fonts ×1
html ×1
javascript ×1
medoo ×1
react-redux ×1
reactjs ×1
redux ×1
regex ×1
tags ×1
toggleswitch ×1
webfonts ×1
whitespace ×1