我是symfony的新手.在其他语言如java和其他语言中我可以request.getParameter('parmeter name')
用来获取值.
我们可以用symfony2做类似的事吗.
我见过一些例子,但没有一个对我有用.假设我有一个名称为username的表单字段.在表单操作中,我尝试使用以下内容:
$request = $this->getRequest();
$username= $request->request->get('username');
Run Code Online (Sandbox Code Playgroud)
我也试过了
$username = $request->getParameter('username');
和
$username=$request->request->getParameter('username');
Run Code Online (Sandbox Code Playgroud)
但是没有一个选项可行.但是后续工作正常:
foreach($request->request->all() as $req){
print_r($req['username']);
}
Run Code Online (Sandbox Code Playgroud)
我在哪里使用getParameter()
方法做错了.任何帮助将不胜感激.
我正在尝试使用以下命令运行 Symfony 3.x:
我想与我创建的 PGSQL 数据库进行交互,但出现此错误:
PHP警告:PHP启动:无法加载动态库'/usr/lib/php/20151012/php_pdo_pgsql.dll' - /usr/lib/php/20151012/php_pdo_pgsql.dll:无法打开共享对象文件:没有这样的文件或目录在未知的第 0 行
[Doctrine\DBAL\Exception\DriverException] 驱动程序发生异常:找不到驱动程序
[Doctrine\DBAL\Driver\PDOException] 找不到驱动程序[PDOException] 找不到驱动程序
所以我查看了我的phpinfo()
,似乎启用了 pgsql 驱动程序
谁能帮我解决这个问题?
我有一个架构sql文件(语法错误),包括设置数据库的多个查询
example.sql
CREATE TABLE IF NOT EXISTS `example` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
CREATExxxxxxxxxx TABLE IF NOT EXISTS `example2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
Run Code Online (Sandbox Code Playgroud)
使用example.php
$sqlContent = file_get_contents("example.sql");
$stmt = $conn->prepare($sqlContent);
$result = $stmt->execute();
Run Code Online (Sandbox Code Playgroud)
即使我的sql不正确,execute方法也不会抛出任何异常.它的文档说它false
在失败时返回,但它返回true
.
我该如何处理异常处理?如何检查我的查询是否有错误?
运行我的应用程序时,此连接引发了此错误套接字异常。
INFO 5231 --- [nio-8087-exec-1] org.mongodb.driver.connection: Closed connection [connectionId{localValue:2}] to 192.168.0.2:27017 because there was a socket exception raised by this connection.**
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='admin', source='campbell', password=<hidden>, mechanismProperties={}}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='admin', source='campbell', password=<hidden>, mechanismProperties={}}
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2756)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2666)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2409)
at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.doFind(ExecutableFindOperationSupport.java:214)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) …
Run Code Online (Sandbox Code Playgroud) _id
我正在尝试获取数组中没有的所有文档excluded
。
db.sites.find({ "$expr": { '_id': { "$not": { "$in": "$excluded"} } } });
Run Code Online (Sandbox Code Playgroud)
我没有使用$nin
,因为它是不允许的$expr
。
我收到以下错误消息:
Error: error: {
"ok" : 0,
"errmsg" : "Expression $in takes exactly 2 arguments. 1 were passed in.",
"code" : 16020,
"codeName" : "Location16020"
}
Run Code Online (Sandbox Code Playgroud)
我可以用$where
这个代替吗?
我正在尝试输出20张图像,这些图像都在命名文件1-20.png中编号.而不是按顺序输出它们我想随机化输出.
最初我有这个,但它显然是非常静态的,必须有一种方法可以使用foreach循环,但只输出数字而不是数组.
此外,它不应重复数字.
<?php
foreach (array_rand($numbers, 19) as $key)
echo '<div class="avatar"><img src="' . $numbers[$key] . '.png" /></div>';
?>
Run Code Online (Sandbox Code Playgroud)
然后将数字1-20作为字符串存储在页面上的数组中.
请教我这个代码
<?php
if (!empty($this->product->customfieldsSorted['youtube'])) {
$this->position = 'youtube';
echo '<button class="shop_tablinks tab2" onclick='"openSpecs(event, 'Specs3')"' >';
echo JText::_('Video');
echo '</button>';
} // Product Custom ontop end
?>
Run Code Online (Sandbox Code Playgroud)
好像我没写好
onclick='"openSpecs(event, 'Specs3')"' >'
Run Code Online (Sandbox Code Playgroud)