尝试将此行更改为数组
private $formId = '1';
尝试:
private $formId = array('1', '2');
但它没有用。
在编程时我是新手,任何帮助都非常感激:)
答案 0 :(得分:2)
试
.container-window {
top: 0px;
padding: 0px;
height: 170px;
border: 1px solid red;
position: relative;
width: 300px;
overflow: hidden;
margin: auto;
}
.container {
top: 15px;
margin: 0 auto;
width: 210px;
height: 140px;
position: relative;
perspective: 1000px;
}
#carousel {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 1s;
}
#carousel .item{
margin: 0 auto;
display: block;
position: absolute;
width: 206px;
height: 116px;
left:0px;
top: 10px;
border: 2px solid black;
text-align:center;
background-color:grey;
}
.next, .prev {
color: #444;
position: absolute;
top: 100px;
padding: 1em 2em;
cursor: pointer;
background: #CCC;
border-radius: 5px;
border-top: 1px solid #FFF;
box-shadow: 0 5px 0 #999;
transition: box-shadow 0.1s, top 0.1s;
}
.next:hover, .prev:hover { color: #000; }
.next:active, .prev:active {
top: 100px;
box-shadow: 0 1px 0 #999;
}
.next { right: 5em; }
.prev { left: 5em; }
答案 1 :(得分:0)
您可以在构造函数中初始化任何类属性。想象一下下面的类:
class FormManager{
private $formId;
private $formName;
private $formMethod;
public function __construct() {
// YOU CAN SET ANY VALUES TO ANY OF THE PROPERTIES OF THIS CLASS
// HERE SO THAT EACH OBJECT CREATED FROM THIS CLASS WOULD HAVE
// THE INITIAL VALUES SET HERE WITHIN THE CONSTRUCTOR
$this->formId = array('1', '2');
$this->formMethod = "POST";
$this->formName = "base_form";
}
/**
* @return array|null
*/
public function getFormId() {
return $this->formId;
}
/**
* @param array|null $formId
* @return FormManager
*/
public function setFormId($formId) {
$this->formId = $formId;
return $this;
}
/**
* @return null|string
*/
public function getFormMethod() {
return $this->formMethod;
}
/**
* @param null|string $formMethod
* @return FormManager
*/
public function setFormMethod($formMethod) {
$this->formMethod = $formMethod;
return $this;
}
/**
* @return null|string
*/
public function getFormName() {
return $this->formName;
}
/**
* @param null|string $formName
* @return FormManager
*/
public function setFormName($formName) {
$this->formName = $formName;
return $this;
}
}
这里,下面是另一个Variant,其中构造函数接受3个参数:
class FormManager{
private $formId;
private $formName;
private $formMethod;
/**
* FormManager constructor.
* @param $formId
* @param $formMethod
* @param $formName
*/
public function __construct($formId=null, $formMethod=null, $formName=null) {
// YOU CAN SET ANY VALUES TO ANY OF THE PROPERTIES OF THIS CLASS
// HERE SO THAT EACH OBJECT CREATED FROM THIS CLASS WOULD HAVE
// THE INITIAL VALUES SET HERE WITHIN THE CONSTRUCTOR.
// THE ARGUMENTS HERE ARE OPTIONAL & THEY DEFAULT EACH TO NULL.
// UNLESS AN ARGUMENT IS SUPPLIED, THE VALUES YOU SET HERE FOR
// EACH OF THE PROPERTIES OVERRIDE THE NULLS...
$this->formId = ( isset($formId) && !is_null($formId) ) ? $formId : array('1', '2');
$this->formMethod = ( isset($formMethod) && !is_null($formMethod) ) ? $formMethod : "POST";
$this->formName = ( isset($formName) && !is_null($formName) ) ? $formName : "base_form";
}
/**
* @return array|null
*/
public function getFormId() {
return $this->formId;
}
/**
* @param array|null $formId
* @return FormManager
*/
public function setFormId($formId) {
$this->formId = $formId;
return $this;
}
/**
* @return null|string
*/
public function getFormMethod() {
return $this->formMethod;
}
/**
* @param null|string $formMethod
* @return FormManager
*/
public function setFormMethod($formMethod) {
$this->formMethod = $formMethod;
return $this;
}
/**
* @return null|string
*/
public function getFormName() {
return $this->formName;
}
/**
* @param null|string $formName
* @return FormManager
*/
public function setFormName($formName) {
$this->formName = $formName;
return $this;
}
}
使用构造函数,您可以初始化$formId
,$formMethod
& $formName
。请注意,构造函数中的所有参数都具有默认值NULL
。这是故意的 - 只是为了证明在对象构建期间将成员变量初始化为您可能喜欢的任何值的可能性。