⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to use forms?



eirotuf

eirotuf
  • profile picture
  • Member

Posted 11 November 2013 - 19:01 PM

Hi guys,

 

I am beginner in Grocery CRUD and code igniter too and even following precisely the instruction to install and use it I have met the following issue:

 

when I add to my controller one of the following functions:

 

  • edit_fields()
  • add_fields()
  • delete()

 

Well, when I click in Add Client or Edit it happens;

404 Page Not Found

and my URL change too http://localhost/CodeIgniter_2.1.4/index.php/add

 

I try the following: create a paste "add" and create index inside with " $crud->add_field('name','age'); " the form appears, but when i try save appears that it is not possible..

And with Edit the URL change " http://localhost/CodeIgniter_2.1.4/index.php/edit/1 " this 1 is a ID, So, will not work..

 

Well, As you saw, I am not able to use the forms of GroceryCRUD

 

Can anyone help me?

 

Sorry for my bad english.

 

Thank you.

 

 

 

 


edramirez

edramirez
  • profile picture
  • Member

Posted 12 November 2013 - 07:44 AM

You need to work on learning codeigniter well first. I suggest you check out the youtube videos on CodeIgniter HMVC. You need to know what controllers, models, and views are and where to place them within your application. Pay attention to foundation first and foremost. 

 

Regards,

 

Ed Ramirez


eirotuf

eirotuf
  • profile picture
  • Member

Posted 12 November 2013 - 19: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/CodeIgniter_2.1.4/cliente

http://localhost/CodeIgniter_2.1.4/index.php/cliente

http://localhost/cliente

 

everybody appears page not found....

 

 

 

 


edramirez

edramirez
  • profile picture
  • Member

Posted 13 November 2013 - 14:21 PM

Here's how I would do it.

 

1. Change the folder from CodeIgniter_2.14 to something like sales or something that refers to the kind of application you have.

2. Set the configuration files - base url, automatic loading of database, url, and grocery_crud libraries

3. Delete the constructor.

4. Revise your system so that your cliente grocerycrud php is inside the controllers folder. The controller class name should be the same as the filename.

5. The index function is the first function that should call the second function in your controller, which contains the grocerycrud function calls. You named your second function as cliente. Maybe cliente should be the name of the file and the name of the class. Then name the second function as "processing". 

6. Revise the report script so that it is in the views folder.

7. Remove the functions add and edit and corresponding GC calls on those functions.

 

Based on your code, it shows that you need to bring yourself up to speed first with codeigniter because you don't have a good foundational understanding on models, views, and controllers yet. If you start off with the wrong foot and rush yourself to create grocerycrud applications even before you could grasp MVC, you won't be able to create even the most simple grocerycrud applications with base functionality. Take this advice for your own benefit and growth. Only you can do the personal work and self-training to advance your level of skills in frameworks, as well as in grocerycrud.

 

Regards,

 

Ed Ramirez


eirotuf

eirotuf
  • profile picture
  • Member

Posted 13 November 2013 - 16: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 ?


eirotuf

eirotuf
  • profile picture
  • Member

Posted 13 November 2013 - 19: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/CodeIgniter_2.1.4/index.php/cliente

 

Is correct?!

 

Thank you so much edramirez