我是Cake的新手,并试图找到最佳解决方案来检索属于$ id的特定字段:
这是我的Post控制器中的视图功能
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid post', true));
$this->redirect(array('action' => 'index'));
}
$this->set('post', $this->Post->read(null, $id));
}
Run Code Online (Sandbox Code Playgroud)
在post表中,有一个user_id外键.我需要检索属于此Post $ id的特定字段.
我将函数读作find('All),read()或者只是通过以下方式删除视图中的非常规会话:
$session->write('example') = $post['Post']['user_id];
Run Code Online (Sandbox Code Playgroud)
执行此操作的最佳方法是什么,我的首选是检索控制器中的字段.谢谢!
在Cake 1.3中,EmailComponent做了它应该做的事情.2.0中的新蛋糕电子邮件课程结果令人沮丧....没有发送电子邮件,没有错误......模糊的文档......
我尝试了所有可能的变种,尝试使用我的SMTP,Mail()和Gmail,没有任何反应.我的最新尝试:
控制器片段:
//on top of page
App::uses('CakeEmail', 'Network/Email');
//in method
$email = new CakeEmail();
$email->template('contact_email')
->emailFormat('text')
->to('my@gmail.com')
->from('other@gmail.com')
->send();
Run Code Online (Sandbox Code Playgroud)
Email.php配置文件:
class EmailConfig {
//It also does not work with a constructor
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'my@gmail.com',
'password' => '***',
'transport' => 'Smtp'
);
Run Code Online (Sandbox Code Playgroud)
有人可以发布电子邮件类的工作代码.非常感谢
如何通过CakePHP中的Html Helper截断链接?
这本书只截断文本字符串,但如何截断这样的链接?
$this->Html->link('This is a very long link that needs to be truncated', '/pages/home', array('class' => 'button', 'target' => '_blank'));
Run Code Online (Sandbox Code Playgroud)
谢谢