Jump to content


eirotuf

Member Since 11 Nov 2013
Offline Last Active Nov 22 2013 06:06 PM
-----

Posts I've Made

In Topic: How to use forms?

13 November 2013 - 07:39 PM

I got it now!

 

 

I had misunderstood the functions of add_field and edit_field..

 

 

cliente.php (controller):

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Cliente extends CI_Controller {
 
    public function index()
    {
        echo "<h1>Welcome to home Form!</h1>";//Just an example to ensure that we get into the function
	$this->home();  
    }

    public function home () 
    {

	$this->load->database();
        $this->load->helper('url');
        $this->load->library('grocery_CRUD');
	$crud = new grocery_CRUD();
        $crud->set_table('cliente'); 
        
	$crud->set_subject('Cliente');
	$crud->add_fields('id','nome','idade');

	$output = $crud->render();
 
        $this->_example_output($output);  
     }	
	
 
    function _example_output($output = null)
 
    {
        $this->load->view('home_view.php',$output);    
    }
}

$routes

$route['default_controller'] = "welcome";
$route['404_override'] = '';

http://localhost/Cod...dex.php/cliente

 

Is correct?!

 

Thank you so much edramirez


In Topic: How to use forms?

13 November 2013 - 04:57 PM

I read about it, but I can better absorb seeing the code working, I see how it works step by step.

Well, your tips helped a lot!

Now I can see the table, but the forms does not work (page not found)

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Home extends CI_Controller {
 
    public function index()
    {
        echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
	$this->cliente();  
    }

    public function cliente () 
    {
	$this->load->database();
        $this->load->helper('url');
        $this->load->library('grocery_CRUD');
	$crud = new grocery_CRUD();
        $crud->set_table('cliente');

	$output = $crud->render();
 
        $this->_example_output($output);  
     }		
 
    function _example_output($output = null)
 
    {
        $this->load->view('home_view.php',$output);    
    }
}


But there were some doubts where I insert my add_field, edit_field? I create a controller for them? Or create a new view for them?!

With respect to the config libraries grocerycrud, I must change something in \ libraries \ grocery_crud.php ?


In Topic: How to use forms?

12 November 2013 - 07:52 PM

Well, I had read previously, but nothing worked, I will show my previous code.
 
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Home extends CI_Controller {
 
    function __construct()
    {
        parent::__construct();
 
        /* Standard Libraries of codeigniter are required */
        $this->load->database();
        $this->load->helper('url');
        /* ------------------ */ 
 
        $this->load->library('grocery_CRUD');
 
    }
 
    public function index()
    {
        echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
	die();
    }

    public function cliente () 
    {
	$crud = new grocery_CRUD();
        $crud->set_table('cliente');
        //$crud->set_primary_key('id');
	$crud->set_subject('Cliente');
	$crud->columns('id','nome','idade');
        $crud->fields('nome','idade');
	//$crud->add_fields('nome','idade');
	//$crud->edit_fields('nome','idade');
	//$crud->require_fields('id','nome','idade');
 	//$crud->unset_edit();
        $crud->display_as('nome','Cliente');
        //$crud->display_as('idade','Idade');

	$output = $crud->render();
 
        $this->_example_output($output);  
     }
 
    public function add(){
	$crud->add_fields('nome','idade');
    }

    public function edit($id) {
	 $crud->edit_fields('nome','idade');
    }

function _example_output($output = null)
 
    {
        $this->load->view('home_view.php',$output);    
    }

?>
 
The only thing that appears is the message in the index()
 

when I change the URL to:

 

http://localhost/Cod...r_2.1.4/cliente

http://localhost/Cod...dex.php/cliente

http://localhost/cliente

 

everybody appears page not found....