查看无法识别 PHP 中模型的方法

View not Recognizing the methods of the Model in PHP

我能够在视图中成功加载模型,但视图无法识别模型中的方法。谁能指出我哪里出错了。我正在使用 PIP MVC 框架 http://gilbitron.github.io/PIP/

P.S。我是 MVC 的新手。

Model.php

class Model {

private $connection;

public function __construct()
{
    global $config;

    $this->connection = mysql_pconnect($config['db_host'], $config['db_username'], $config['db_password']) or die('MySQL Error: '. mysql_error());
    mysql_select_db($config['db_name'], $this->connection);
}

public function execute($qry)
{
    $exec = mysql_query($qry) or die('MySQL Error: '. mysql_error());
    return $exec;
}

我的模型

class Listing_model extends Model {
  public function createNewJob($by) {       
    $result = $this->execute('INSERT INTO job_listings (by_user_id) VALUES ('.$by.')');
    return $result;     
}
}

控制器:

function create() {     

    $template = $this->loadView('post_jobs_view');
    $model = $this->loadModel('Listing_model'); 
    $template->render();        
}

查看:

if (isset($_POST['savejob'])) {
            $by_user_id = 1111;
            Listing_model::createNewJob($by_user_id);
        }

首先,您还没有创建静态函数,因此您可能不应该静态调用它。看起来 PIP 将模型实例加载到变量中。

$model = $this->loadModel('Listing_model'); 
$model->createNewJob($by_user_id);

这让我想到了第二点,这段代码似乎更适合控制器而不是视图。您可能想了解应如何在 MVC 中处理逻辑以及在视图中使用哪些代码是合适的。