2011-05-05 70 views
0

我有一个非常奇怪的输入问题,其中似乎我的SEO描述框和主要内容框链接,因为如果我输入任何数据到seo输入框它在内容中的数据库中更改区域,但不是其他地方。非常奇怪的输入问题

检视:

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

<?php print_r($page);?> 

<div id ="formLayout" class="editPage"> 
<?php echo form_open('admin/editpage/index/'.$page[0]['id'].'/'.url_title($page[0]['name'],'dash', TRUE),$formpageEdit); ?> 
<?php echo form_fieldset(); ?> 
<h4>You are editing: <?= $page[0]['name']; ?> </h4> 
<section id = "validation"><?php echo validation_errors();?></section> 
<?php 
if($success == TRUE) { 
echo '<section id = "validation">Page Updated</section>'; 
} 
?> 
<label><?php echo form_label ('SEO Description:', 'description');?><span class="small">Required Field</span></label> 
<?php echo form_input($formSEODescription, $page[0]['description']); ?> 
<label><?php echo form_label ('Content:', 'content');?><span class="small">Required Field</span></label> 
<?php echo form_textarea($formTextareaContent, $page[0]['content']); ?> 
<script type="text/javascript">CKEDITOR.replace('textContent');</script> 
<?php echo form_submit('submit','Submit'); ?> 
<?php echo form_fieldset_close(); 
     echo form_close(); ?> 
</div> 

模型

<?php 
/** 
* This model handles the sql for the checking of the username in the database 
*/ 
class Page_model extends CI_Model 
{ 

    function __construct() 
    { 
    parent::__construct(); 
    } 

    function Page_model(){ 
     parent::Model(); 
    } 

    function getCMSContent($id = NULL) { 
     $this->db->where('id', $id); 
     $query = $this->db->get('pages', 1); 

     if($query->num_rows() > 0) { 
      $row = $query->result_array(); 
      return $row; 
     }else{ 
      return FALSE; 
     } 
    } 

    function updatePage($id = NULL, $data = NULL){ 
     #set the $data passed to the function into an array, content being the column name. 
     $data = array('content' => $data, 'description' => $data); 

     $this ->db->where('id',$id); 
     $this->db->update('pages', $data); 

     return TRUE; 
    } 
} 


?> 

控制器

<?php 
if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Editpage extends CI_Controller { 

    function __construct(){ 
    parent::__construct(); 
    } 

    function index($id){ 

     if(!$this->session->userdata('logged_in'))redirect('admin/home'); 

     if ($this->input->post('submit')){ 

      #The User has submitted updates, lets begin! 

      #Set The validation Rules 
      $this->form_validation->set_rules('textContent', 'Content', 'trim|required|xss_clean'); 
      $this->form_validation->set_rules('seoDescription', 'SEO Description', 'trim|required|xss_clean'); 

      #if the form_validation rules fail then load the login page with the errors. Otherwise continue validating the user/pass 
      if ($this->form_validation->run() == FALSE){ 

       $data['cms_pages'] = $this->navigation_model->getCMSPages($id); 
       #connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL. 
       $data['page'] = $this->page_model->getCMSContent($id); 
       $data['sales_pages'] = $this->sales_model->getSalesPages(); 

       $data['content'] = $this->load->view('admin/editpage', $data, TRUE); 
       $this->load->view('admintemplate', $data); 

      }    
      #Form Validation passed, so lets continue updating. 
       #lets set some variables. 
       $content = $this->input->post('textContent', TRUE); 
       $content = $this->input->post('seoDescription', TRUE); 
       $this->db->escape($content); 
       #Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself 
       if($this->page_model->updatePage($id, $content)) { 
        $data['cms_pages'] = $this->navigation_model->getCMSPages($id); 
        #connect to getCMSContent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL. 
        $data['page'] = $this->page_model->getCMSContent($id); 
        $data['success'] = TRUE; 
        $data['content'] = $this->load->view('admin/editpage', $data, TRUE); 
        $this->load->view('admintemplate', $data); 
       }//END if updatePage 
      }else{ 
      $data['cms_pages'] = $this->navigation_model->getCMSPages($id); 
      $data['sales_pages'] = $this->sales_model->getSalesPages(); 
      #connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL. 
      $data['page'] = $this->page_model->getCMSContent($id); 
      $data['content'] = $this->load->view('admin/editpage', $data, TRUE); 
      $this->load->view('admintemplate', $data); 
     }//END if post submitted 
    } //END function index() 

} 
+0

什么是所需的行为? – Eineki 2011-05-05 10:58:12

+0

内容进入内容和描述进入说明 – 2011-05-05 11:00:26

回答

0

发现:

$content = $this->input->post('textContent', TRUE); 
    $content = $this->input->post('seoDescription', TRUE); 

[以下更新]

您将要覆盖与seoDescription内容的$content变量,以便textContent永远达不到你的数据库。

你需要更新你的updatePage功能:

function updatePage($id = NULL, $content = NULL, $description = NULL){ 
    #set the $data passed to the function into an array, content being the column name. 
    $data = array('content' => $content, 'description' => $description); 

    $this ->db->where('id',$id); 
    $this->db->update('pages', $data); 

    return TRUE; 
} 

,并适当地调用它:

[...] 
    #Form Validation passed, so lets continue updating. 
     #lets set some variables. 
     $content  = $this->input->post('textContent', TRUE); 
     $description = $this->input->post('seoDescription', TRUE); 
     $this->db->escape($content); 
     $this->db->escape($description); 
     #Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself 
     if($this->page_model->updatePage($id, $content, $description)) { 
[...] 

顺便说一句,你一定要正确使用db->escape?如果escape函数通过引用接受参数(例如,在参数名称前面使用&,并将该值设置为转义值),则只能调用它。我希望这个代码是正确的版本,但我不知道你的db类,所以我可能是错的:

 $content  = $this->db->escape($this->input->post('textContent', TRUE)); 
     $description = $this->db->escape($this->input->post('seoDescription', TRUE)); 
+0

巴特,我会如何解决这个问题?我应该可以设置$内容,然后将其放入db – 2011-05-05 11:03:04

+0

更新'updatePage'函数: – Bart 2011-05-05 11:26:59