我进行了一项研究,但结果与我的问题无关:我有一个模型,其关联表包含下划线。
<?php
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Query;
class TableClient extends Model {
public function getSource()
{
return "table_client";
}
function lireParCritere($critere) {
$sSQL = "
SELECT c.table_code,s.salle_code,s.salle_lib,c.table_lib,c.table_nb_couvert,c.table_comment
FROM table_client as c INNER JOIN salle s ON s.salle_code = c.salle_code
WHERE 1 = 1 ";
if(isset($critere["table_code"]) && $critere["table_code"] != "") {
$sSQL .= "AND c.table_code = '" . $critere["table_code"] . "' ";
}
$query = new Query($sSQL,$this->getDI());
$ret = $query->execute();
return $ret;
}
function ajouter($tab) {
$champs= "";
$value = "";
$separateur ="";
foreach ($tab as $k => $v){
$champs .= $separateur . $k;
$value .= $separateur . "'" . $v . "'";
$separateur = ",";
}
$champs = '('.$champs.')';
$value = '('.$value.')';
$sSQL = "
INSERT INTO table_client $champs
VALUES $value
";
$query = new Query($sSQL,$this->getDI());
$ret = $query->execute();
}
function modifier($tab) {
$setColumns = "";
$separateur = "";
foreach ($tab as $k => $v){
if ($k == 'table_code')
continue;
$setColumns .= $separateur . 'table_client.' . $k . " = '" . $v . "'";
$separateur = ",";
}
$sSQL = "UPDATE table_client SET ".$setColumns." WHERE table_client.table_code = '".$tab['table_code']."'";
$query = new Query($sSQL, $this->getDI());
$ret = $query->execute();
}
function supprimer($tab) {
$sSQL = "DELETE FROM table_client WHERE table_client.table_code = '".$tab['table_code']."'";
$query = new Query($sSQL, $this->getDI());
$ret = $query->execute();
}
}
?>
在controller
内,我想调用此模型的方法:
public function modifierAction($id){
$this->view->action_form = '../modifierExec';
$this->view->titre = 'Modification de table';
$critere = array();
$critere["table_code"] = $id;
$this->view->data = TableClient::lireParCritere($critere); // here is the call of the model's method
return $this->view->pick("table/table");
}
在运行时我得到一个类未找到错误!那么如何解决呢?
答案 0 :(得分:2)
您可以查看constroller的课程可用性:
foreach (spl_autoload_functions() as $function) {
foreach ($function as $object) {
if (!$object instanceof \Phalcon\Loader) {
continue;
}
var_dump($object->getNamespaces());
var_dump($object->getCheckedPath());
var_dump($object->getDirs());
var_dump($object->getClasses());
var_dump($object->getFoundPath());
}
}
die;
修改强>
function lireParCritere($critere)
中使用FROM \Fully\Qualified\Class\Name
代替FROM table_client
$client = new TableClient; $client->lireParCritere($critere);
代替TableClient::lireParCritere($critere);