稱爲具有dangdest時間調用從控制器功能的模型方法時。許多小時,並在「調用一個成員函數...非對象開」和「未定義的屬性:主要:: $ form_model」讀很多很多的文章等處理後,我還沒有發現任何解決方案(顯然,或者我不會在這裏伸出)。只是讓你知道我並沒有試圖將這個問題帶到Easy Pass車道。調用模型方法「調用一個成員函數...無對象」,但工程從視圖
我的模型文件夾中包含該型號:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Form_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function update_profile(){
$data = array();
$formValues = $this->input->post();
$this->db->where('member_id', $data['member_id']);
$this->db->update('members', $data);
}
}
在我的主類控制器,我加載傭工/庫/模型是這樣的:
class Main extends CI_Controller {
public function __construct(){
parent::__construct();
// Your own constructor code
$this->load->helper(array('cookie','form','url'));
$this->load->library('../controllers/accessories');
$this->load->model(array('registration_model','form_model'));
}
這些負載正常。我知道他們正確加載,因爲如果我改變任何模式中的任何字母,笨拋出了它不能加載模型中的錯誤。
在我的主類中的最後一個功能與形式的操作頁面相關聯。表單頁面是外視圖(在「意見」文件夾中),這也要求具有相同名稱的內視圖,但它駐留在一個「視圖/內容」文件夾中,像這樣:
<?php $this->load->view("top"); ?>
<!-- CONTENT BEGIN -->
<?php $this->load->view("content/profile_management"); ?>
<!-- CONTENT END -->
<?php $this->load->view("bottom"); ?>
您可以看到這個模板三明治的「內容」中調用第三級視圖,並在情況下$role == 1
,那將是「表格/ profile_manager_form」:
<?php
if ($this->uri->segment(3) === FALSE){
if($this->input->cookie('member')){
$member_id = $this->input->cookie('member');
}
else{
$member_id = 0;
}
}
else{
$member_id = $this->uri->segment(3);
}
$query = $this->db->get_where('members', array('member_id' => $member_id));
foreach ($query->result() as $row){
$role = $row->role;
}
switch($role){
case "1" :
$this->load->view('forms/profile_manager_form');
break;
case "2" :
$this->load->view('forms/portfolio_manager_analyst');
break;
}
?>
當配置文件更新表單提交,行動頁是 「profile_form」:
<?php $this->load->view("top"); ?>
<!-- CONTENT BEGIN -->
<?php $this->load->view("content/profile_form"); ?>
<!-- CONTENT END -->
<?php $this->load->view("bottom"); ?>
此頁面,在「意見」的文件夾,自己在「視圖/內容」文件夾中調用第二個層次來看,所謂的「profile_form」:
<?php
foreach($_POST as $k => $v){
echo "$k = $v <br>";
}
$this->form_model->update_profile();
?>
...你可以看到,我放置了呼叫update_profile
這裏,和它的作品。但我不認爲我想用我的控制器Main類調用一些模型函數的混搭來構建這個網站,而其他模型函數是從視圖頁面中調用的,因爲這是他們似乎工作的唯一地方。
在我的控制器的主類,我的最後一個功能是我覺得函數調用應放在:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
public function __construct(){
parent::__construct();
// Your own constructor code
$this->load->helper(array('cookie','form','url'));
$this->load->library('../controllers/accessories');
$this->load->model(array('registration_model','form_model'));
}
public function index()
{
$config = array();
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
$data = array();
$data['scripts'] = $this->accessories->getScripts($config);
$this->load->view('home',$data);
}
public function profile_form(){
$config = array();
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
$data = array();
$data['states'] = $this->accessories->states();
$data['scripts'] = $this->accessories->getScripts($config);
$this->form_model->update_profile(); //I want to put my model function call here, but CI gives me the "not an object" error.
$this->load->view('profile_form',$data);
}
}
UPDATE: 見我的答案,以下。
哇,有些故事...也許嘗試縮短你的答案,只顯示必要的部分,沒有它我們將無法幫助,很多人不會讀這麼長的問題 –
我給了適量的信息那個「特殊」的人實際上可以幫忙;) – TARKUS