找不到课程

时间:2015-07-30 09:33:57

标签: php phalcon

我进行了一项研究,但结果与我的问题无关:我有一个模型,其关联表包含下划线。

<?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");
    }

在运行时我得到一个类未找到错误!那么如何解决呢?

1 个答案:

答案 0 :(得分:2)

  1. class_exists()功能
  2. 检查课程
  3. 检查Phalcon自动加载器配置。确保你真的放入了autoloader配置类/目录/命名空间/
  4. 您可以查看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;
    
  5. 修改

    1. \ Phalcon \ Mvc \ Model \ Query使用PHQL,而不是SQL。在function lireParCritere($critere)中使用FROM \Fully\Qualified\Class\Name代替FROM table_client
    2. 对于测试,请使用$client = new TableClient; $client->lireParCritere($critere);代替TableClient::lireParCritere($critere);