Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 编码点火器->;编辑页面_Php_Forms_Codeigniter - Fatal编程技术网

Php 编码点火器->;编辑页面

Php 编码点火器->;编辑页面,php,forms,codeigniter,Php,Forms,Codeigniter,我尝试访问时出现以下错误: domain.co.nz/admin/editpage/home/ 我得到以下错误: PHP Fatal error: Call to a member function getCMSPage() on a non-object in controllers/home.php on line 22 问题是,我无法理解为什么会将其传回主控制器“主”控制器 默认情况下,将加载我的所有模型- 理想情况 我正试图这样做是加载到一个文本区域的内容进行编辑,当提交被点击时,

我尝试访问时出现以下错误:

domain.co.nz/admin/editpage/home/

我得到以下错误:

PHP Fatal error:  Call to a member function getCMSPage() on a non-object in controllers/home.php on line 22 
问题是,我无法理解为什么会将其传回主控制器“主”控制器

默认情况下,将加载我的所有模型-

理想情况

我正试图这样做是加载到一个文本区域的内容进行编辑,当提交被点击时,我希望它返回到同一页的消息说,内容更新

管理模板

<li><?php echo anchor('#','Edit Pages');?>
            <?php if(is_array($cms_pages)): ?>
                    <ul>
                        <?php foreach($cms_pages as $page): ?>
                        <li><a >permalink?>"><?=$page->name?></a></li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
                </li> 
查看:

<?php
//Setting form attributes
$formpageEdit = array('id' => 'pageEdit', 'name' => 'pageEdit');
$formInputTitle = array('id' => 'title', 'name' => 'title');
$formTextareaContent = array('id' => 'content', 'name' => 'content');
?>

<section id = "validation"><?php echo validation_errors();?></section>

<h4><?= $title ?> </h4>
<?php
echo form_open('admin/editpage/'.$page->permalink, $formpageEdit);
echo form_fieldset();
echo form_label ('Content', 'content');
echo form_textarea("content", $page['content']);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?> 
function index(){
        if($this->session->userdata('logged_in')){

        }else{
            redirect('admin/home');
        }
       $page = $this->navigation_model->getCMSPage($this->uri->segment(3));
        $data['cms_pages'] = $this->navigation_model->getCMSPages();
        $data['title'] = $page->name;
        $data['content'] = $this->load->view('admin/editpage', array('page' => $page, TRUE));

        $this->load->view('admintemplate', $data);

    } 

我还没有真正测试过这个,但它应该给你一个好的开始。您所要求的是快速完全编码的相当多的工作

这是页面模型,本质上是你发布的,只是做了一些小的调整。最好使用id而不是字符串。在将它们传递给数据库之前,您可能还需要执行一些htmlspecialchars或mysql劫持验证

<?php
/**
 * This is the Page_model model, this model handles the retrieval and modification of all pages.
 *
 **/
class Page_model extends CI_Model {
/**
 * the getCMSPage function retrieves the data from the db given the ID that was passed via $id.
 **/
    function getCMSPage($id = NULL) {
        $this->db->where('permalink', $permalink);
        $query = $this->db->get('pages', 1);

        #check to make sure row's were returned, if so continue, otherwise return false.
        if ($query->num_rows() > 0){
            #set the results into an array and return $row, should return $row['content'], and $row['id'];
            #if you were editing more than one page this is where you would use a foreach($query)
            $row = $query->result_array();
            return $row;
        }else{
            return false;
        }// END if ($query->num_rows() > 0)
    }// END function getCMSPage()
}// END Page_model class
?>

需要整个控制器功能请发布导航_模型中的getCMSPage()方法。Mike,我已经完成了上面所说的,但是每次我访问“permalink”页面时,似乎都认为它是我访问时的主“主控制器”:我得到了对成员函数getCMSPage()的调用在第22行的/House/application/controllers/home.php中的非对象上
<?php
/**
 * This is the Page_model model, this model handles the retrieval and modification of all pages.
 *
 **/
class Page_model extends CI_Model {
/**
 * the getCMSPage function retrieves the data from the db given the ID that was passed via $id.
 **/
    function getCMSPage($id = NULL) {
        $this->db->where('permalink', $permalink);
        $query = $this->db->get('pages', 1);

        #check to make sure row's were returned, if so continue, otherwise return false.
        if ($query->num_rows() > 0){
            #set the results into an array and return $row, should return $row['content'], and $row['id'];
            #if you were editing more than one page this is where you would use a foreach($query)
            $row = $query->result_array();
            return $row;
        }else{
            return false;
        }// END if ($query->num_rows() > 0)
    }// END function getCMSPage()
}// END Page_model class
?>
<?php
/**
 * This is the Site controller, primary controller for your site.
 *
 **/
class Site extends CI_Controller {
/**
 * construct function, in our case we are going to load the Posts_model , you may not want to do this.
 * 
 **/
    function __construct()
    {
        parent::__construct();
        #load Page_model, should be located in app/models/page_model.php
        $this->load->model('Page_model');
    }//END function __construct();

/**
 * edit function, this function handles retrieval of the page from the URI, and the page's content for editing.
 *
 * This function uses $id which auto retrieves the page's ID from the uri. Your URL should look similiar to:
 * http://yourdomain.com/site/edit/3/yourunecessaryinformationhere
 * everything after the id is not really required but could help with SEO.
 * 
 **/
    function edit($id){
        #retrieve the page's content in array form.
        $page = $this->Page_model->getCMSPage($id);
        echo form_textarea("content", $page['content']);
    }
}//END Site Class
// this line
$data['content'] = $this->load->view('admin/editpage', $data);
// needs to be
$data['content'] = $this->load->view('admin/editpage', array('page' => $page, TRUE);