我想覆盖 FOSUserBundle 的 RegistrationType 的形式,但是在 registration_content.html.twig 模板中我得到了这个错误:
属性“firstname”和方法“firstname()”、“getfirstname()”/“isfirstname()”/“hasfirstname()”或“__call()”都不存在并且在类“Symfony\”中具有公共访问权限组件\表单\表单视图”。
这是我的RegistrationType表格:
class RegistrationType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('firstname');
}
public function getParent() {
return 'fos_user_registration';
}
public function getName() {
return 'app_user_registration';
}
}
Run Code Online (Sandbox Code Playgroud)
fos_user.yaml:
fos_user:
registration:
confirmation:
enabled: true
form:
name: app_user_registration
db_driver: orm
user_class: App\Entity\User
firewall_name: main
from_email:
address: foo@example.com
sender_name: bar@example.com
Run Code Online (Sandbox Code Playgroud)
用户实体:
class User extends BaseUser {
//
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
protected $firstname;
}
Run Code Online (Sandbox Code Playgroud)
registration_content.html.twig:
{{ form_start(form, {'method': 'post', 'action': …Run Code Online (Sandbox Code Playgroud) 当我尝试以 JSON 返回模型关系时,我看不到关系字段。这是我的查询:
$customer_subscriptions = CustomerSubscription::has("customer")
->has("subscription")
->has("federationDiscipline")
->where("customer_id", "=", $customer_id)
->whereHas("subscription", function($query) use($company_id) {
$query->where("company_id", "=", $company_id);
})
->orderBy("start_date", "asc");
return $customer_subscriptions;
Run Code Online (Sandbox Code Playgroud)
这是我的结果:
[0]=>
array(14) {
["id"]=>
int(2)
["customer_id"]=>
int(1)
["subscription_id"]=>
int(1)
["federation_discipline_id"]=>
int(1)
["start_date"]=>
string(10) "2017-04-01"
["end_date"]=>
string(10) "2017-05-31"
["external_id"]=>
NULL
["notes"]=>
NULL
["created_user_id"]=>
int(1)
["updated_user_id"]=>
NULL
["deleted_user_id"]=>
NULL
["created_at"]=>
string(19) "2017-06-05 07:28:00"
["updated_at"]=>
string(19) "2017-06-05 07:28:00"
["deleted_at"]=>
NULL
}
Run Code Online (Sandbox Code Playgroud)
我没有看到订阅和客户的关系字段。查询结果应返回 JSON 到 AJAX
Laravel是否可以将条件应用于某个集合,并将其结果放入另一个集合而无需更改第一个集合?
例如:
$documenti = DB::table("RVW_DocumentiDettaglio")
->select("*")
->where("IDAzienda", "=", $request->session()->get("operatore.IDAzienda"))
->whereIn("CodiceStato", [Documento::E_DOC, Documento::W_DOC, Documento::OK_DOC])
->orderBy("IDDocumentoTestata", "asc");
// Ciclo le voci spesa
foreach ($voci_spesa as $voce_spesa) {
Log_Controller::debug("Documenti:" . $documenti->get());
if ($voce_spesa["Manuale"]) {
$dettaglio = $documenti->where("Descrizione", "like", "%" . $voce_spesa["Descrizione"] . "%");
} else {
$dettaglio = $documenti->where("Descrizione", "=", $voce_spesa["Descrizione"]);
}
Log_Controller::debug("Dettaglio:" . $dettaglio->get());
}
die;
Run Code Online (Sandbox Code Playgroud)
随着$documenti我得到的第一个系列,在foreach我适用where语句,并把结果$dettaglio集,但第一个($documenti)也被改变了。为什么?就像共享对象