Welcome Guest, Not a member yet? Register   Sign In
model and database
#1

I have a quick question regarding the connection between model in CI and database.  for example:


This is my table:

giondacms (database name)
-------------------------


pages (table name)

pages_name

create_date

pages_order



model/pages_model.php


PHP Code:
public function insert_pages()
        {
                
                $data 
= array(
                    'title' => $this->input->post('title'),
                    'date'  => $this->input->post('date'),
                    'order' => $this->input->post('order'),
                    'content' => $this->input->post('content')                
                
);
            
                
return $this->db->insert('pages'$data);
        


Looking at my database and table, is there anything wrong with my pages_model.php ?

Thanks in advance,
Davy
" If I looks more intelligence please increase my reputation."
Reply
#2

None of the fields you are trying to insert are in your table. If you want to insert "title", there has to be a "title" field in your table. Same goes for date, order, and content. Right now you show your only 3 fields as "pages_name", "create_date", and "pages_order" Why not use those in your insert?
Reply
#3

(This post was last modified: 06-12-2016, 09:39 AM by arma7x.)

(06-12-2016, 08:25 AM)davy_yg Wrote: I have a quick question regarding the connection between model in CI and database.  for example:


This is my table:

giondacms (database name)
-------------------------


pages (table name)

pages_name

create_date

pages_order



model/pages_model.php


PHP Code:
public function insert_pages()
        {
                
                $data 
= array(
                    'title' => $this->input->post('title'),
                    'date'  => $this->input->post('date'),
                    'order' => $this->input->post('order'),
                    'content' => $this->input->post('content')                
                
);
            
                
return $this->db->insert('pages'$data);
        


Looking at my database and table, is there anything wrong with my pages_model.php ?

Thanks in advance,
Davy

Please follow the tutorial guide at here and read other section too. The real problem is you keep ignoring the documentation.
Keep calm.
Reply
#4

Thanks for advice.  I fix some stuff:


controllers/cpages.php


PHP Code:
    public function __construct()
    {
        
        parent
::__construct();
        
        $this
->load->database();
        
        $this
->load->helper('url'); //Just for the examples, this is not required thought for the library
        $this->load->helper('form');
        
        $this
->load->library('form_validation');
        $this->load->library('image_CRUD');
        $this->load->library('session');
        
        $this
->load->database();
        
    
}




    public function addpages() 
     
        
        $this
->load->model('pages_model');
        $this->load->helper('url_helper');    

        $this
->form_validation->set_rules('pages_name''pages_name''required');
        $this->form_validation->set_rules('create_date''create_date''required');
        $this->form_validation->set_rules('pages_order''pages_order''required');
                
            if 
($this->form_validation->run() === FALSE)
            {
            $this->load->view('add_pages');
            }
                
            else
            
{
            $this->pages_model->insert_pages();        
            $this
->load->view('add_pages');                
            
}
                        
          
    
    
}
    


I get this error that I do not know how to fix:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: pages_model::$load
Filename: libraries/Form_validation.php

Line Number: 147
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\models\pages_model.php
Line: 11
Function: __construct

File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\controllers\Cpages.php
Line: 68
Function: model

File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\index.php
Line: 315
Function: require_once


Any idea how to fix the error?
" If I looks more intelligence please increase my reputation."
Reply
#5

(This post was last modified: 06-12-2016, 10:36 AM by arma7x.)

PHP Code:
public function insert_pages()
        {
                
                
$data = array(
                    
'pages_name' => $this->input->post('title'),
                    
'create_date'  => $this->input->post('date'),
                    
'pages_order' => $this->input->post('order')             
                );
            
                return 
$this->db->insert('pages'$data);
        } 
Keep calm.
Reply
#6

(This post was last modified: 06-12-2016, 03:48 PM by davy_yg.)

Hello,

I still receive this error message:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: pages_model::$load
Filename: libraries/Form_validation.php
Line Number: 147
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\models\pages_model.php
Line: 11
Function: __construct
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\controllers\Cpages.php
Line: 68
Function: model
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\index.php
Line: 315
Function: require_once


controllers/cpages.php


PHP Code:
public function addpages() 
    { 
 
        
        $this
->load->model('pages_model');
        
$this->load->helper('url_helper');    

        
$this->form_validation->set_rules('pages_name''pages_name''required');
        
$this->form_validation->set_rules('create_date''create_date''required');
        
$this->form_validation->set_rules('pages_order''pages_order''required');
        
$this->form_validation->set_rules('pages_content''pages_order''required');
        
                
                
            if (
$this->form_validation->run() === FALSE)
            {
            
$this->load->view('add_pages');
            }
                
            else
            {
            
$this->pages_model->insert_pages();        
            
$this->load->view('add_pages');                
            }
                        
         
 
    
    



models/pages_model.php

PHP Code:
public function insert_pages()
 
       {
                
                
$data = array(
                    
'pages_name' => $this->input->post('title'),
                    
'create_date'  => $this->input->post('date'),
                    
'pages_order' => $this->input->post('order'),
                    
'pages_content' => $this->input->post('content')                
                );
            
 
               return $this->db->insert('pages'$data);
 
       


views/add_pages.php

PHP Code:
<form action="submitpages" method="post">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>Pages Name:</td>
                                <
td><input type="input" name="pages_name"></td>
                            </
tr>
                            <
tr>
                                <
td>Create Date:</td>
                                <
td><input type="input" name="create_date" size="2"></td>
                         
   </tr>
                            <
tr>
                                <
td>Order:</td>
                                <
td><input type="input" name="pages_order" size="4"></td>
                         
   </tr>
                            <
tr>
                                <
td>View Content:</td>
                                <
td><textarea cols="150px" rows="5px" name="pages_content"></textarea></td>
                         
   </tr>
                            <
tr>
                                <
td></td>
                                <
td><input type="submit" name="submit" value="Submit" /></td>
                         
   </tr>    
                        </
table>            
                        
                        </
form

giondacms (database)
pages (table)

1 pages_name
2 create_date
3 pages_order


How to fix the error?
" If I looks more intelligence please increase my reputation."
Reply
#7

A Model Class and its filename must have the first letter upper case!
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(This post was last modified: 06-12-2016, 08:20 PM by davy_yg.)

I change the model class name and filename into uppercase.



models/Pages_model.php


PHP Code:
class Pages_model extends CI_Controller 


I still have this error appears:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Pages_model::$load
Filename: libraries/Form_validation.php
Line Number: 147
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\models\Pages_model.php
Line: 11
Function: __construct
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\controllers\Cpages.php
Line: 68
Function: model
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\index.php
Line: 315
Function: require_once
" If I looks more intelligence please increase my reputation."
Reply
#9

Hi,

Model extends the base model CI_Model not the controller!!
Reply
#10

Hello,

I am trying to fix this input form so that it could capture information and store it in the database.  Yet, even after filling this information and press enter it still does not moves to the database I wonder why?


Gionda CMS


Pages

create_date
pages_name
pages_order



Pages Name: Home
Create Date: 552016
Order: 5
Content: Lorem Ipsum

------------------------------------

Thank you for filling the information. It has been successful.

Pages Name: Home
Create Date: 552016
Order: 5
Content: Lorem Ipsum


-------------------------------


views/add_pages.php

PHP Code:
Code:
<form action="submitpages" method="post">
                        
                        <table border="0" style="width: 100%; height: 90px;">
                            <tr>
                                <td>Pages Name:</td>
                                <td><input type="input" name="pages_name"></td>
                            </tr>
                            <tr>
                                <td>Create Date:</td>
                                <td><input type="input" name="create_date" size="2"></td>
                            </tr>
                            <tr>
                                <td>Order:</td>
                                <td><input type="input" name="pages_order" size="4"></td>
                            </tr>
                            <tr>
                                <td>View Content:</td>
                                <td><textarea cols="150px" rows="5px" name="pages_content"></textarea></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" name="submit" value="Submit" /></td>
                            </tr>    
                        </table>            
                        
                        </form> 



controllers/cpages.php

PHP Code:

Code:
    public function addpages() 
    {  
        
        $this->load->model('pages_model');
        $this->load->helper('url_helper');    

        $this->form_validation->set_rules('pages_name', 'pages_name', 'required');
        $this->form_validation->set_rules('create_date', 'create_date', 'required');
        $this->form_validation->set_rules('pages_order', 'pages_order', 'required');
        $this->form_validation->set_rules('pages_content', 'pages_order', 'required');
        
                
                
            if ($this->form_validation->run() === FALSE)
            {
            $this->load->view('add_pages');
            }
                
            else
            {
            $this->pages_model->insert_pages();        
            $this->load->view('add_pages');                
            }
                        
          
    
    }

    public function submitcontent() {                                    
    
    
            $this->load->model('insert_pages()');
            $this->load->model('update_pages()');
            
    
            $this->load->view('submitcontent');
    
    }


models/pages_model.php


PHP Code:

Code:
public function insert_pages()
        {
                
                $data = array(
                    'pages_name' => $this->input->post('title'),
                    'create_date'  => $this->input->post('date'),
                    'pages_order' => $this->input->post('order'),
                    'pages_content' => $this->input->post('content')                
                );
            
                return $this->db->insert('pages', $data);
        }

    public function update_pages()
        {
                $this->title    = $_POST['pages_name']; // please read the below note
                $this->date     = time();
                $this->order    = $_POST['order'];
                $this->content  = $_POST['content'];

                $this->db->update('pages', $this, array('id' => $_POST['id']));
        }
" If I looks more intelligence please increase my reputation."
Reply




Theme © iAndrew 2016 - Forum software by © MyBB