我想我必须在这里做错事,因为我的代码只向桌面上的最后一个订阅者发送了一封电子邮件.当我记录订阅者数组时,很明显它正在尝试发送多个订阅者.我认为这个问题与尝试将它们一起批处理有关......对我来说,最好的方法是什么?我正在尝试使用附件创建一条消息,然后分别发送每个地址,并将它们作为一个批处理进程发送出去.这是我的代码:
$subscribersManager = new DD_Subscribers_Manager();
$subscribers = $subscribersManager->getAllSubscribers();
$subject = $form->getElement('subject')->getValue();
$body = $form->getElement('body')->getValue();
$filename = $form->getElement('bulletin')->getValue();
$filepath = Zend_Registry::get('rootDir') . '/public/downloads/archive/' . $filename;
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'fake@email.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
foreach ($subscribers as $subscriber) {
$message = new Zend_Mail('utf-8');
$message->setFrom('fake@email.com', 'My Fake Mailing List')
->addTo($subscriber->email)
->setSubject($subject)
->setBodyText($body);
$attachment = $message->createAttachment(file_get_contents($filepath));
$attachment->type = 'application/pdf';
$attachment->filename = $filename;
}
$message->send($smtpConnection);
Run Code Online (Sandbox Code Playgroud) 我有一个带有select元素的表单,我需要用数据库中的值填充它.具体来说,是当前用户的名称和ID.该fetchPairs()功能非常适用于此!但是,我需要连接first_name列和last_name列的值,并将其显示为选项标签.有没有办法做到并仍然使用fetchPairs()?如果没有,我怎样才能达到相同的效果?以下是目前正在运行的代码的摘录:
<?php // excerpt
class Default_Form_AddUser extends Zend_Form
{
public function init()
{
$this->addElement('select', 'user', array(
'label' => 'Select user:',
'required' => true,
'multiOptions' => $this->_getSelectOptions()
));
}
protected function _getSelectOptions()
{
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select()->from('users', array('id', 'first_name'));
$roleOptions = $db->fetchPairs($select);
return $roleOptions;
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在使用Zend Framework并有一个上传文件表单.经过身份验证的用户可以上载文件,该文件将存储在应用程序的目录中,以及存储在数据库中的位置.这样它就可以显示为可以下载的文件.
<a href="/upload-location/filename.pdf">Download</a>
Run Code Online (Sandbox Code Playgroud)
但我注意到的是,具有相同名称的文件将覆盖uploads目录中的文件.没有错误消息,文件名也没有增加.所以我认为该文件必须被覆盖(或永远不会上传).
在上传,移动或存储这些文件时,我应该注意哪些最佳做法?我应该始终重命名文件,以便文件名始终是唯一的吗?
我想摆脱我的定义列表格式Zend_Form.这是我要去的布局:
<form>
<p>
<label for="email" class="required">Your email address:</label>
<input type="text" name="email" id="email" value="">
</p>
<p>
<input type="submit" name="submit" id="submit" value="Subscribe">
</p>
<input type="hidden" name="active" value="true" id="active">
<input type="hidden" name="signupDate" value="" id="signupDate">
</form>
Run Code Online (Sandbox Code Playgroud)
为了获得这种布局,我需要对表单做些什么?
class Default_Form_Subscribe extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$this->addElement('text', 'email', array(
'label' => 'Email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress')
));
$this->addElement('submit', 'submit', array(
'label' => 'Subscribe',
'ignore' => true
));
$this->addElement('hidden', 'active', array(
'value'=>'true'
));
$this->addElement('hidden', 'signupDate', array( …Run Code Online (Sandbox Code Playgroud) 我开始使用iPhone应用程序开发,并希望创建一个涉及从Web应用程序中提取数据的应用程序.我将使用PHP和Zend Framework开发API.我之前从未创建过公共API,也没有使用适用于公共数据的iPhone应用程序.
以下是我的一些具体问题:
我需要做的一件事是使用API中的数据创建一个表视图.
假设我的API有一个fetchAll函数可以返回数据库表中的所有记录,我应该如何格式化这些数据,以便在我的iPhone应用程序中轻松使用?
# http://myapp.com/api/people/fetchAll
array(
0 => 'John',
1 => 'Sally',
2 => 'Chris'
)
Run Code Online (Sandbox Code Playgroud)
更新:在做了一些研究后,我决定(在服务器端)我想实现一个返回JSON 的RESTful API.所以我的iPhone应用程序最终将成为一个REST客户端.
我也发现了这篇文章,虽然它现在可能已经过时了:在Cocoa和Cocoa Touch中创建RESTful Web服务客户端
我开始创建一个与公共API交互的iPhone应用程序.
我的问题是,哪个更快和/或更容易使用:XML或JSON?
提交表单时,请求中不会提交已禁用的表单字段.
因此,如果您的表单具有禁用的表单字段,那么它会让您Zend_Form::isValid()感到有点沮丧.
$form->populate($originalData);
$form->my_text_field->disabled = 'disabled';
if (!$form->isValid($_POST)) {
//form is not valid
//since my_text_field is disabled, it doesn't get submitted in the request
//isValid() will clear the disabled field value, so now we have to re-populate the field
$form->my_text_field->value($originalData['my_text_field']);
$this->view->form = $form;
return;
}
// if the form is valid, and we call $form->getValues() to save the data, our disabled field value has been cleared!
Run Code Online (Sandbox Code Playgroud)
无需重新填充表单,并创建重复的代码行,解决此问题的最佳方法是什么?
我找到了一大堆我以前没见过的代码:
declare(ticks = 1);
pcntl_signal(SIGINT, array($this, "catchSignal"));
pcntl_signal(SIGTERM, array($this, "catchSignal"));
Run Code Online (Sandbox Code Playgroud)
我在PHP文档中查找了该函数,但我仍然不明白它的用途.请帮助我理解这个用途以及应该在哪里实现的一些例子.
我之前遇到过这个问题,但我不记得如何解决它.我创建了一个简单的骨头(不能得到任何更简单的)控制器,我只是想回应一些东西到浏览器,我收到这条消息:
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser ...
Run Code Online (Sandbox Code Playgroud)
这是我的整个控制器.它显示"成功",但它也显示错误消息.我怎样才能使该错误消息静音,以便我可以简单地向浏览器回应一些内容?
<?php
class CacheController extends Zend_Controller_Action
{
public function clearAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
try {
$result = Model_Cache::emptyCache(array('foobar'=>1));
if ($result['status'] == true) {
echo 'Success';
} else {
echo 'Error: ' . $result['message'];
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正试图找到解决这个问题的方法.我有一个Ruby脚本需要运行一些PHP代码,但我是Ruby新手,所以我不知道如何去做.
def run_my_code
#execute some PHP code here
# $person = new Person();
# $person->doSomething();
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
php ×5
zend-form ×3
iphone ×2
api ×1
attachment ×1
email ×1
file-upload ×1
gmail ×1
json ×1
ruby ×1
xml ×1
zend-db ×1
zend-file ×1
zend-session ×1