php - Class not found -
i made research results not related problem : have model associated table contains underscore.
<?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 table_client c inner join salle s on s.salle_code = c.salle_code 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 $k => $v){ $champs .= $separateur . $k; $value .= $separateur . "'" . $v . "'"; $separateur = ","; } $champs = '('.$champs.')'; $value = '('.$value.')'; $ssql = " insert table_client $champs values $value "; $query = new query($ssql,$this->getdi()); $ret = $query->execute(); } function modifier($tab) { $setcolumns = ""; $separateur = ""; foreach ($tab $k => $v){ if ($k == 'table_code') continue; $setcolumns .= $separateur . 'table_client.' . $k . " = '" . $v . "'"; $separateur = ","; } $ssql = "update table_client set ".$setcolumns." table_client.table_code = '".$tab['table_code']."'"; $query = new query($ssql, $this->getdi()); $ret = $query->execute(); } function supprimer($tab) { $ssql = "delete table_client table_client.table_code = '".$tab['table_code']."'"; $query = new query($ssql, $this->getdi()); $ret = $query->execute(); } } ?>
inside controller
want call method of model :
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 call of model's method return $this->view->pick("table/table"); }
at runtime class not found error ! how fix ?
- check class class_exists() function
- check phalcon autoloader config. make sure put in autoloader config class/directory/namespace/
you can check class availability in constroller:
foreach (spl_autoload_functions() $function) { foreach ($function $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;
edit
- \phalcon\mvc\model\query uses phql, not sql. in
function lireparcritere($critere)
usefrom \fully\qualified\class\name
insteadfrom table_client
- for tests use
$client = new tableclient; $client->lireparcritere($critere);
insteadtableclient::lireparcritere($critere);
Comments
Post a Comment