我想让一个变量为 int ,除非该变量为 null 。
这是我修复它的方法,但必须有更好的解决方案。
if ($answer == null) {
$all_questions[] = array (
'object_id' => (int) $stored_question->getObjectId(),
'question_code' => $stored_question->getQuestionCode(),
'answer' => $stored_question->getAnswer()
);
}
else{
$all_questions[] = array (
'object_id' => (int) $stored_question->getObjectId(),
'question_code' => $stored_question->getQuestionCode(),
'answer' => (int) $stored_question->getAnswer()
);
Run Code Online (Sandbox Code Playgroud)
至少我希望有,因为这看起来多余。
我正在使用 simplesaml 制作两个应用程序,一个服务提供者和一个身份提供者。
当我尝试测试它们时,出现以下错误:
SimpleSAML_Error_MetadataNotFound: METADATANOTFOUND('%ENTITYID%' => '\'http://samlsp.dev/module.php/saml/sp/metadata.php/default-sp\'')
Backtrace:
3 /var/www/samlidp/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php:301 (SimpleSAML_Metadata_MetaDataStorageHandler::getMetaData)
2 /var/www/samlidp/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php:318 (SimpleSAML_Metadata_MetaDataStorageHandler::getMetaDataConfig)
1 /var/www/samlidp/modules/saml/lib/IdP/SAML2.php:303 (sspmod_saml_IdP_SAML2::receiveAuthnRequest)
0 /var/www/samlidp/www/saml2/idp/SSOService.php:18 (N/A)
Run Code Online (Sandbox Code Playgroud)
这是 sp 的元数据:
$metadata['http://samlidp.dev/saml2/idp/metadata.php'] = array (
'name' => 'test',
'description' => 'next login test',
'SingleSignOnService' => 'http://samlidp.dev/saml2/idp/SSOService.php',
'SingleLogoutService' => 'samlidp.dev/saml2/idp/SingleLogoutService.php',
'certFingerprint' => '38:EB:B2:DB:6F:45:C2:D6:92:CE:85:29:6B:CE:A6:D0:CE:91:19:7A'
);
Run Code Online (Sandbox Code Playgroud)
这是 IdP 的元数据:
$metadata['http://samlsp.dev'] = array(
'AssertionConsumerService'=> 'http://samlsp.dev/module.php/saml/sp/saml2-acs.php/default-sp',
'SingleLogoutService'=> 'http://samlsp.dev/module.php/saml/sp/saml2-logout.php/default-sp'
);
Run Code Online (Sandbox Code Playgroud) 我一直从我的代码中得到以下错误:
数据库连接失败:PDO :: __ construct():发送12个字节失败,errno = 110连接超时
这个错误持续发生在api上.如果那个api在白天不停地被调用,那么这种情况就不会发生.只有当api不使用一段时间.
我可以通过执行php-fpm restart/reload来解决这个问题,但这不应该是解决方案.
有谁知道如何解决这个问题?
- 编辑 -
这是连接数据库的代码:
public function connectDatabase($allow_persistent = true)
{
$this->db = null;
$this->readINI();
$pdo_attr = [
PDO::ATTR_PERSISTENT => $allow_persistent,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET utf8;",
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true,
];
$this->db = new PDO("mysql:host=" . $this->db_data_dbhost . ";dbname=" . $this->db_data_dbname . ";charset=utf8", $this->db_data_username, $this->db_data_password, $pdo_attr);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
Run Code Online (Sandbox Code Playgroud)
为了更多地进行迭代,目前在两个API上使用它.
我想在后端/ admin中的产品列表的magento中创建一个pdf.我不知道怎么做,我在互联网上找到的东西也没那么有用.希望有人可以帮助我.
GR
编辑
class Wouterkamphuisdotcom_Web_Adminhtml_WebController extends Mage_Adminhtml_Controller_action {
protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('web/items')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
return $this;
}
public function exportPdfAction(){
$fileName = 'customers.pdf';
$content = $this->getLayout()->createBlock('Web/Web_Grid')->getPdfFile();
$this->_prepareDownloadResponse($fileName, $content);
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器
我有这个:
$startdate = date("Y-m-d", strtotime('2015-' . $startmonth . '-01'));
Run Code Online (Sandbox Code Playgroud)
但是,如何填补当年,我如何获得当年?