我是新来的.特别是使用bootstrap.我有这个代码:
<div class="row">
<div class="col-lg-3">
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
Run Code Online (Sandbox Code Playgroud)
我需要将此输入字段和按钮放在页面中心..."margin-left:auto; margin-right:auto;" 没有工作......有人有想法吗?
如何处理除一个例外以外的所有例外
try:
something
except <any Exception except for a NoChildException>:
# handling
Run Code Online (Sandbox Code Playgroud)
像这样的东西,除了不破坏原始追溯:
try:
something
except NoChildException:
raise NoChildException
except Exception:
# handling
Run Code Online (Sandbox Code Playgroud) 我在我的网络服务器上安装了流明,但我遇到了路由问题
// http://12.345.678.910/
$app->get('/', function() use ($app) {
return "This works";
});
Run Code Online (Sandbox Code Playgroud)
但在第二种情况下,他无法找到目录
// http://12.345.678.910/api
$app->get('/api', function() use ($app) {
return "This dont work";
});
Run Code Online (Sandbox Code Playgroud)
在第二种情况下,我得到标准的404错误.
The requested URL /api was not found on this server.
Run Code Online (Sandbox Code Playgroud)
我使用Apache,Ubuntu,PHP 5.5和Lumen
我有这样的事情:
class exampleClass(object):
def doSomething(self,number):
return number + 1
class exampleClass2(exampleClass):
def callDefDoSomething(self):
print exampleClass.doSomething(5)
exampleClass2.callDefDoSomething()
Run Code Online (Sandbox Code Playgroud)
-
TypeError: unbound method callDefDoSomething() must be called
with exampleClass2 instance as first argument (got nothing instead)
Run Code Online (Sandbox Code Playgroud)
我开始学习 Python 中的对象,但我找不到解决方案:(
在创建模型之后,当我尝试获取其属性时,我只获得数据库中填充的字段.
----------------------------------------------
DB: | id | shopID | name | bottleID | capacity |
----------------------------------------------
| 1 | 8 | Cola | 3 | |
----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我也需要容量属性,作为空字符串
public function getDrinkData(Request $request)
{
$drink = Drink::where('shopId', $request->session()->get('shopId'))->first();
if($drink) {
$drink = $drink->attributesToArray();
}
else {
$drink = Drink::firstOrNew(['shopId' => $request->session()->get('shopId')]);
$drink = $drink->attributesToArray(); // i want to get even empty fields
}
return view('shop.drink')->(['drink' => $drink])
}
Run Code Online (Sandbox Code Playgroud)
但是为了以后的使用(在视图中),我需要拥有所有属性,包括空属性.我知道这段代码可以正常工作,但我不知道如何更改它以检测所有属性.
在迁移类中,根据逻辑,我需要使用不同类型的数据库连接。如何在迁移类中通过连接名称获取新连接?
目前在doctrine.yaml文件中我有连接名称“default”、“user”、“admin”和“cron”。
我的迁移类:
final class Version20190711123152 extends AbstractMigration
{
public function up(Schema $schema) : void
{
...
if($someCondition) {
$this->setConnection($wantedConnection) // how to set $wantedConnection for example on "admin" connection
}
}
/**
* @param Connection $connection
*/
public function setConnection(Connection $connection): void
{
$this->connection = $connection;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 Symfony 4.3
我需要在每个小写字母上放置*,但我的程序总是阻塞.虽然这似乎是一个简单的问题,但我找不到简单的解决方案.请帮忙.
#include <stdio.h>
void f(char *p)
{
int i = 0;
char c = '*';
while(p[i] != '\0')
{
if(p[i]> 96 && p[i] < 122 )
{
p[i] = c; # here program block
}
i++;
}
printf("%c",p);
}
int main(void)
{
f("tesT");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我在互联网上发现了一些类似的问题但没有成功.:(
我同时运行2个线程,但我有一个关键部分,我需要在MySql数据库中放置一些东西.问题是他们可以同时放入同样的东西.
我做了一些计算,显示对于索引20000个不同的新闻页面,索引从20000到20020.(所以0到20是重复的)
如何在另一个线程访问数据库时暂停一个线程?
-----thread.php
class Process extends Thread {
public function __construct($website_url){
$this->website_url = $website_url;
}
public function run() {
work($this->website_url);
}
}
-------------- work
function work($website_url) {
while(condition) {
some work...
if(something->check){ // if this exist in base
mysqli->query("INSERT something IN db...");
prepare bind exec...
}
// between check and insert, second thread can put that element
// critical section is really small but sometimes occurs ...
}
}
------ main.php
$job1 = new Process($website_url,$trigger);
$job2 = new Process($website_url,$trigger); …Run Code Online (Sandbox Code Playgroud) 我的config/service.yaml包含多个配置庞大的服务。现在,我想将该服务的配置移至单独的文件中。
我尝试这样做:
在......的最后service.yaml:
imports:
- { resource: 'packages/custom_service.yaml' }
Run Code Online (Sandbox Code Playgroud)
config/packages/custom_service.yaml:
services:
App\Service\CustomService:
arguments:
$forms:
- location: 'room1'
id: 43543
- location: 'room2'
id: 6476546
- location: 'room3'
id: 121231
...
Run Code Online (Sandbox Code Playgroud)
src/Service/CustomService.php:
/**
* @var array
*/
protected $forms;
public function __construct(array $forms)
{
$this->forms = $forms;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在某些控制器中自动连接时,我收到此错误:
Cannot resolve argument $customService of "App\Controller\CustomController::customAction()": Cannot autowire service "App\Service\CustomService": argument "$forms" of method "__construct()" is type-hinted "array", you should configure its value explicitly.
Run Code Online (Sandbox Code Playgroud)
但是如果我删除类型提示,那么我会收到此错误:
Cannot …Run Code Online (Sandbox Code Playgroud) class first(object):
def __init__(self, room, speed):
self.position = room
self.speed = 20
direction = random.randint(0,359)
class second(first):
def __init__(self)
self.way = first.direction
self.now = first.self.position
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,如何从__init__另一个类中获取变量?
我正在运行4个同时运行的线程.(work()在这种情况下,线程同时运行功能)
global $i;
$i = 1;
function work($address) {
while($i < 1000) {
$i++;
----
if($i == something) some job...
----
}
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,这不起作用.线程有时会在同一个圆圈中执行,因此我稍后会有一些重复的值.(可能他们有一些关键部分)任何想法如何解决这个问题?
我用于解析文本简单的html dom,但他无法管理这种访问div.
foreach($html->find("div") as $div)
{
if($div->data-zoom-image != false)
// some job
}
Run Code Online (Sandbox Code Playgroud)
错误日志:
Use of undefined constant data - assumed 'data'
Use of undefined constant zoom - assumed 'zoom'
Use of undefined constant image - assumed 'image'
Run Code Online (Sandbox Code Playgroud)
似乎带有破折号( - )的元素需要以其他方式访问
知道为什么这段代码不起作用?我在HTML中定义了一个带有此ID的文本输入字段.
$('document').ready(function()
{
$('#inputUsername').keyup(alert("something"));
}
);
Run Code Online (Sandbox Code Playgroud)