gpt4 book ai didi

javascript - 从数据库下载形成PHP

转载 作者:行者123 更新时间:2023-11-29 03:31:12 24 4
gpt4 key购买 nike

我希望在我的应用程序中添加“发票”时可以在数据库中查看客户,这样我就不必输入完整的名称,而只需输入一个选择输入,我会在其中即时接收客户,我不知道如何按照 MVC 解决。

Controller/invoice.php

<?php

include 'Controller/controller.php';

class InvoicesController extends Controller{
public function index() {
$view=$this->loadView('invoices');
$view->index();
}
public function add() {
$view=$this->loadView('invoices');
$view->add();
}
public function insert() {
$model=$this->loadModel('invoices');
$model->insert($_POST);
$this->redirect('?task=invoices&action=index');
}
public function delete() {
$model=$this->loadModel('invoices');
$model->delete($_GET['id']);;
$this->redirect('?task=invoices&action=index');
}
public function edit() {
$model=$this->loadView('invoices');
$model->edit($_GET['id']);
}
public function getClients(){
$model = $this->loadModel('clients');
$model->getAll();
}
public function editInvoice(){
$model = $this->loadModel('invoices');
$model->editInvoice($_POST);
$this->redirect('?task=invoices&action=index');

}

}

模型/invoices.php

<?php

include 'Model/model.php';


class InvoicesModel extends Model{


public function insert($data) {

$ins=$this->pdo->prepare("INSERT INTO invoices (id,Number,Name,Service,Symbol,Unit, Tax, Value)"
. " VALUES ('',:number,:name,:service,'szt','2',:tax,:value)");
$ins->bindValue(':name', $data['name'], PDO::PARAM_STR);
$ins->bindValue(':number', $data['number'], PDO::PARAM_STR);
$ins->bindValue(':service', $data['service'], PDO::PARAM_STR);
$ins->bindValue(':tax', $data['tax'], PDO::PARAM_STR);
$ins->bindValue(':value', $data['value'], PDO::PARAM_STR);
$ins->execute();
}
public function getAll() {
return $this->select('invoices');
}
public function getId() {
return $this->getLastId('invoices');
}
public function edit($id) {
return $this->select('invoices',' * ',' id = '.$id.' ');
}
public function editInvoice($data){
$edit=$this->pdo->prepare("UPDATE invoices SET Name = :name WHERE id = :id");
$edit->bindValue(':name', $data['name']);
$edit->bindValue(':id', $data['id']);
$edit->execute();
}
public function delete($id) {
$del=$this->pdo->prepare('DELETE FROM invoices where id=:id');
$del->bindValue(':id', $id, PDO::PARAM_INT);
$del->execute();
}

}

查看/invoice.php

<?php

include 'View/view.php';

class InvoicesView extends View{
public function index() {
$cat=$this->loadModel('invoices');
$this->set('catsData', $cat->getAll());
$this->render('indexCategory');
}
public function add() {
$inv=$this->loadModel('invoices');
$this->set('invoicesData', $inv->getLastId('invoices'));

$this->render('addCategory');
}
public function getClients(){
$get = $this->loadModel('clients');
$this->set('clientsData', $get->getClients());
$this->render('addCategory');
}
public function edit($id){
$edit = $this->loadModel('invoices');
$this->set('invoicesData', $edit->edit($_GET['id']));
$this->render('editInvoice');
}
}

和模板/AddCategory.html.php

<?php include 'templates/header.html.php'; ?></pre>
<h1>Dodaj kontrahenta</h1>
<?php

?>
<form action="?task=invoices&action=insert" method="post">
Nazwa kontrahenta: <input type="text" name="name" /><br>
NIP: <input type="text" name="nip" /><br>
Adres: <input type="text" name="adress" /><br>
Kod Pocztowy: <input type="text" name="postcode" /><br>
Miasto: <input type="text" name="city" /><br>
Telefon: <input type="text" name="phone" /><br>
Email: <input type="text" name="email" /><br>
<input type="submit" value="Dodaj" /></form>
<pre>
<?php include 'templates/footer.html.php'; ?>

如果我这样做

<?php include 'templates/header.html.php'; ?></pre>
<h1>Dodaj kontrahenta</h1>
<?php
$data = $this->set('clientsData', $get->getClients());
var_dump($data);
?>
<form action="?task=invoices&action=insert" method="post">
Nazwa kontrahenta: <input type="text" name="name" /><br>
NIP: <input type="text" name="nip" /><br>
Adres: <input type="text" name="adress" /><br>
Kod Pocztowy: <input type="text" name="postcode" /><br>
Miasto: <input type="text" name="city" /><br>
Telefon: <input type="text" name="phone" /><br>
Email: <input type="text" name="email" /><br>

<input type="submit" value="Dodaj" /></form>
<pre>
<?php include 'templates/footer.html.php'; ?>

我收到错误

Notice: Undefined variable: get in /home/krytykak/domains/jozwiak.edu.pl/public_html/templates/addCategory.html.php on line 4

Fatal error: Call to a member function getClients() on a non-object in /home/krytykak/domains/jozwiak.edu.pl/public_html/templates/addCategory.html.php on line 4

最佳答案

$get->getClients()

$get 没有在任何地方定义。您正在调用 getClients(),它是 InvoicesController 对象的成员。所以我在想 $get = new InvoicesController(); 应该在执行之前初始化 $data = $this->set('clientsData', $get->getClients() );

关于javascript - 从数据库下载形成PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30357308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com