我正在建立一个订单,我提前警告你,我是一个后端开发的菜鸟:)
所以我的第一个组件从订单表中获取所有数据并将其保存到数据库,然后我使用相同的数据生成报价。在此之后,如果引用被接受,我有一个生成发票的第四部分,到目前为止我的代码看起来像这样:
// this runs when order is submitted on front end (runs from same component)
public function onAddOrder() {
$this->submitOrder();
$this->submitQuote();
Flash::success('Order successfully submitted!');
return Redirect::to('/home');
}
public function submitOrder() {
// Add it to the database
$order = new Order();
$order ->quote_no = $this->generateQuoteNo();
$order ->company_name = Input::get('company_name');
$order ->client_name = Input::get('client_name');
$order ->client_email = Input::get('client_email');
$order ->emergency_contact = Input::get('emergency_contact');
$order ->due_date = Input::get('due_date');
$order ->project_name = Input::get('project_name');
$order ->quote_query = Input::get('quote_query');
$order ->order_no = Input::get('order_no');
$order ->order_type = Input::get('order_type');
$order ->save();
}
}
public function submitQuote() {
$quote = new Quote();
$quote->quote_no = $this->generateQuoteNo();
$quote->customer = Input::get('company_name');
$quote->job_name = Input::get('project_name');
$quote->order_no = Input::get('order_no');
$quote->proof_price = $this->calculateProofPrice();
$quote->sub_total = $this->calculateSubTotal();
$quote->vat = $this->calculateVat();
$quote->total = $this->calculateTotal();
$quote->save();
}
这样可以正常工作,但是如果我做了一个选择,我想运行另一个函数,但是这个组件属于不同的类,我不知道如何引用它。
if (Input::get('quote_query') === 'Order') {
$this->AcmeInvoice->onSubmitInvoice();
}
如果有人可以帮助我在子发票()上点击公共功能,我将非常感激。
答案 0 :(得分:4)
您可以在类和实例中实例化对象。把它关掉?例如:$ invoice = new AcmeInvoice(); //如果不在名称空间中添加命名空间; $ invoice-> onSubmitInvoice();
if (Input::get('query') === 'Invoice') {
$invoice = new AcmeInvoice();
$invoice->onSubmitInvoice('quote_no');
}