获取CakePHP中刚注册用户的用户id
如何检索最近注册的用户的用户id。。在CakePHP2.1IE中 现在,名为获取CakePHP中刚注册用户的用户id,cakephp,cakephp-2.1,Cakephp,Cakephp 2.1,如何检索最近注册的用户的用户id。。在CakePHP2.1IE中 现在,名为poo的用户输入了一些注册凭据 像用户名和密码和 数据库结构如下所示 使用者 现在,一旦用户被创建,我想向用户显示一条消息 您已成功注册,您的id为xxx 这些是整数 register.ctp视图的代码 echo $this->Form->create('User'); echo $this->Form->input('first_name', array('label'=>'First
poo
的用户输入了一些注册凭据
像用户名
和密码
和
数据库结构如下所示
使用者
现在,一旦用户被创建,我想向用户显示一条消息
您已成功注册,您的id为xxx
这些是整数
register.ctp视图的代码
echo $this->Form->create('User');
echo $this->Form->input('first_name', array('label'=>'First Name'));
echo $this->Form->end('Register');
控制器代码
public function register(){
if ($this->request->is('post')){
if ($this->User->save($this->request->data)){
// $this->Session->setFlash('User is created' . $this->YourModel->id);
$this->Session->setFlash(__('You have registered successfully and your ID is %s', $this->YourModel->id));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash('Cannot register a user');
}
}
}
调用模型的save()-函数后,刚添加的ID通过属性可用
$this->YourModel->id代码>
您可以将ID传递给视图,也可以创建一条flash消息:
$this->Session->setFlash(__('You have registered successfully and your ID is %s', $this->YourModel->id));`
请参见您能否在控制器(可能是UserController::add())中发布相应操作的代码?@pixelistik添加更多信息。这可能对您有所帮助@MoyedAnsari我相信,nappo的以下回答很好,而不是从数据库中获取最后一个id。。如果您认为,超过3人
,那么我们在检索时可能会遇到一些问题,同时。@Rafee我同意,我只是展示了所有可能的解决方案
$this->Session->setFlash(__('You have registered successfully and your ID is %s', $this->YourModel->id));`