ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

v 1.3.3 grocery CRUD - an automatic Codeigniter CRUD

April 11, 2011 3:24am

Subscribe [77]
  • #166 / Sep 04, 2011 8:05am

    web-johnny

    235 posts

    @web-johnny

    Can you give me example how to make distinct field?

    You will do it with the exactly same way as the function username_check that you created. With set_rules and callbacks. The example is like yours at [ # 163 ]

  • #167 / Sep 04, 2011 11:00am

    Sinapit

    10 posts

    @web-johnny

    Can you give me example how to make distinct field?

    You will do it with the exactly same way as the function username_check that you created. With set_rules and callbacks. The example is like yours at [ # 163 ]

    I mean like this:

    SELECT DISTINCT * FROM tbl_order;
  • #168 / Sep 04, 2011 11:20am

    web-johnny

    235 posts

    @web-johnny

    Can you give me example how to make distinct field?

    You will do it with the exactly same way as the function username_check that you created. With set_rules and callbacks. The example is like yours at [ # 163 ]

    I mean like this:

    SELECT DISTINCT * FROM tbl_order;

    This is something specific so you can add your own model and just have ONE function with a different select.
    Go to set model function on my website and see the examples of how to use the set_model function .Then create your own model and it will be something like this:

    class distinct_Model  extends grocery_Model  {
        function get_list()
        {
            if($this->table_name === null)
                return false;
            
            $select = "{$this->table_name}.*";
            
            if(!empty($this->relation))
                foreach($this->relation as $relation)
                {
                    list($field_name , $related_table , $related_field_title) = $relation;
                    $select .= ", $related_table.$related_field_title as '$related_table.$related_field_title'";
                    
                    if($this->field_exists($related_field_title))
                    {
                        $select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";    
                    }
                }
                
            $this->db->distinct(); // <--- HERE IS THE NEW LINE THAT YOU WILL ADD
            
            $this->db->select($select, false);
            
            $results = $this->db->get($this->table_name)->result();
            
            return $results;
        }
    }

    The new line is the $this->db->distinct();. I didn’t test the code above, but you get the point 😉 . You can add as many custom models you want without changing the core grocery_model.

  • #169 / Sep 04, 2011 11:56am

    Sinapit

    10 posts

    @web-johnny

    Can you give me example how to make distinct field?

    You will do it with the exactly same way as the function username_check that you created. With set_rules and callbacks. The example is like yours at [ # 163 ]

    I mean like this:

    SELECT DISTINCT * FROM tbl_order;

    This is something specific so you can add your own model and just have ONE function with a different select.
    Go to set model function on my website and see the examples of how to use the set_model function .Then create your own model and it will be something like this:

    class distinct_Model  extends grocery_Model  {
        function get_list()
        {
            if($this->table_name === null)
                return false;
            
            $select = "{$this->table_name}.*";
            
            if(!empty($this->relation))
                foreach($this->relation as $relation)
                {
                    list($field_name , $related_table , $related_field_title) = $relation;
                    $select .= ", $related_table.$related_field_title as '$related_table.$related_field_title'";
                    
                    if($this->field_exists($related_field_title))
                    {
                        $select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";    
                    }
                }
                
            $this->db->distinct(); // <--- HERE IS THE NEW LINE THAT YOU WILL ADD
            
            $this->db->select($select, false);
            
            $results = $this->db->get($this->table_name)->result();
            
            return $results;
        }
    }
    The new line is the $this->db->distinct();. I didn’t test the code above, but you get the point 😉 . You can add as many custom models you want without changing the core grocery_model.

    It’s not worked :(

    It’s worked if i using this syntax:

    public function order_customer($limit, $offset)
        {
            $this->db->distinct();
            $this->db->select('*');
            $this->db->from('tbl_order');
            $this->db->limit($limit, $offset);
            return $this->db->get();
        }

    This is my sql table:

    CREATE TABLE IF NOT EXISTS `tbl_order` (
      `id_order` int(5) NOT NULL AUTO_INCREMENT,
      `id_status` int(5) DEFAULT NULL,
      `id_customer` int(5) DEFAULT NULL,
      `order_number` int(5) DEFAULT NULL,
      `order_date` date DEFAULT NULL,
      `id_product` int(5) DEFAULT NULL,
      `qty_product` varchar(20) DEFAULT NULL,
      `price_product` varchar(50) DEFAULT NULL,
      `total_price` varchar(50) DEFAULT NULL,
      PRIMARY KEY (`id_order`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

    i’ve attach data of my table

  • #170 / Sep 04, 2011 12:54pm

    Sinapit

    10 posts

    hahahha…i’m happy now because it’s solved

    this is my syntax

    class distinct_Model  extends grocery_Model  {
        function get_list()
        {
            if($this->table_name === null)
                return false;
            
            $select = "{$this->table_name}.*";
            
            if(!empty($this->relation))
                foreach($this->relation as $relation)
                {
                    list($field_name , $related_table , $related_field_title) = $relation;
                    $select .= ", $related_table.$related_field_title as '$related_table.$related_field_title'";
                    
                    if($this->field_exists($related_field_title))
                    {
                        $select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";    
                    }
                }
                
            $this->db->distinct(); // <--- HERE IS THE NEW LINE THAT YOU WILL ADD
            
            $this->db->select($select, false);
            $this->db->group_by('order_number');
            $results = $this->db->get($this->table_name)->result();
            
            return $results;
        }
    }

    Thank you @web-johnny 😉

  • #171 / Sep 06, 2011 7:07am

    using tinyint in tables causing errors.

    http://s4.postimage.org/7tv2rg6ih/Ads_z.jpg

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 2

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 20

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 70

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 60

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 10

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 30

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 40

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 50

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 24

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 8

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 2

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 2

    Filename: libraries/grocery_crud.php

    Line Number: 206

    Fatal error: ob_start() [ref.outcontrol]: Cannot use output buffering in output buffering display handlers in /system/core/Exceptions.php on line 166

  • #172 / Sep 07, 2011 4:45pm

    web-johnny

    235 posts

    using tinyint in tables causing errors.

    http://s4.postimage.org/7tv2rg6ih/Ads_z.jpg

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 2

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 20

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 70

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 60

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 10

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 30

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 40

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 50

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 24

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 8

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 2

    Filename: libraries/grocery_crud.php

    Line Number: 206
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined index: 2

    Filename: libraries/grocery_crud.php

    Line Number: 206

    Fatal error: ob_start() [ref.outcontrol]: Cannot use output buffering in output buffering display handlers in /system/core/Exceptions.php on line 166

    There is no such a problem. You can add as many tinyint, int etc you like.Can you be more specific? Give the example function that you had the problem. for example:

    function example_code()
    {
    .....
        $this->grocery_crud->set_table(....);
        $this->grocery_crud->render();
    ......
    }

    What version of grocery CRUD did you use and what version of codeigniter? Did you use mySQL?

  • #173 / Sep 08, 2011 1:31am

    I’m using latest versions of grocery crud and ci 2.0.3.

    There is that problem, i’m not fabricating.

    i tested it by converting tinyint to int. in that case it is working.
    code:

    function sayfalar()
    {
        $output = $this->grocery_crud->render();
     
        $this->_example_output($output);
    }
    
    sql:
    
    <a href="http://pastebin.com/LWpjq29L">http://pastebin.com/LWpjq29L</a>

    http://www.megayapinsaat.com/examples/sayfalar not working

    working version: (it’s exactly same data, except i used int tables instead of tinyint.)

    function sayfalar2()
    {
        $output = $this->grocery_crud->render();
     
        $this->_example_output($output);
    }
    
    sql:
    <a href="http://pastebin.com/PChGgyVz">http://pastebin.com/PChGgyVz</a>

    http://www.megayapinsaat.com/examples/sayfalar2 working

    btw: will be there multi-language support too ?

  • #174 / Sep 08, 2011 2:44am

    web-johnny

    235 posts

    I’m using latest versions of grocery crud and ci 2.0.3.

    There is that problem, i’m not fabricating.

    i tested it by converting tinyint to int. in that case it is working.
    code:

    function sayfalar()
    {
        $output = $this->grocery_crud->render();
     
        $this->_example_output($output);
    }
    
    sql:
    
    <a href="http://pastebin.com/LWpjq29L">http://pastebin.com/LWpjq29L</a>

     

    working version: (it’s exactly same data, except i used int tables instead of tinyint.)

    function sayfalar2()
    {
        $output = $this->grocery_crud->render();
     
        $this->_example_output($output);
    }
    
    sql:
    <a href="http://pastebin.com/PChGgyVz">http://pastebin.com/PChGgyVz</a>

    http://www.megayapinsaat.com/examples/sayfalar2 working

    btw: will be there multi-language support too ?

    Can you please write the structure of your table ? Just to test it local . for example:

    CREATE TABLE IF NOT EXISTS `category` (
      `category_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(25) NOT NULL,
      PRIMARY KEY (`category_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;

    .
    I know you are not fabricating it. I just try to understand.
    P.S. The multilingual support is on my mind , but still it is not included to new next release 1.1.1

  • #175 / Sep 08, 2011 3:53am

    i have already wrote the table structures.

    check the paste bin links.

  • #176 / Sep 08, 2011 4:12pm

    web-johnny

    235 posts

    i have already wrote the table structures.

    check the paste bin links.

    I understand what the problem is. Grocery crud when reads tinyint automaticaly makes the field type to true_false . This means that there is only the field active and inactive (0,1). So the “undefined” index is the numbers > 1 for example 2, 18 etc.
    The solution for this is to change the automatic field to integer with the function. change_field_type (http://www.grocerycrud.com/crud/function_name/change_field_type).
    In your case it will be:

    function sayfalar()
        {
            $this->grocery_crud->change_field_type('goster','integer');
            $this->grocery_crud->change_field_type('navigasyon','integer');
            $output = $this->grocery_crud->render();
            
            $this->_example_output($output);        
        }
  • #177 / Sep 08, 2011 11:22pm

    chule143

    5 posts

    I need help plz,

    When i try to upload a file from Opera, IE, Firefox or any other borwser i get this message in the web console in Opera:

    A PHP Error was encountered
    Severity: Warning Message: fclose() expects parameter 1 to be resource, boolean given
    Filename: libraries/grocery_crud.php
    Line Number: 764
    {"success":true,"file_name":null,"full_url":"http://localhost/joya/public/uploads/products/"}

    This is the code from grocerycrud.php:

    line 762:  fseek($temp, 0, SEEK_SET);
    line 763:  stream_copy_to_stream($temp, $target);
    line 764:  fclose($target);

    And this is my controller:

    $crud->set_field_upload(‘image’, ‘public/uploads/products/’);

    What i’m doing wrong?

    PD: Excuse me for my poor english

    Thanks

  • #178 / Sep 09, 2011 2:31am

    web-johnny

    235 posts

    I need help plz,

    When i try to upload a file from Opera, IE, Firefox or any other borwser i get this message in the web console in Opera:

    A PHP Error was encountered
    Severity: Warning Message: fclose() expects parameter 1 to be resource, boolean given
    Filename: libraries/grocery_crud.php
    Line Number: 764
    {"success":true,"file_name":null,"full_url":"http://localhost/joya/public/uploads/products/"}

    This is the code from grocerycrud.php:

    line 762:  fseek($temp, 0, SEEK_SET);
    line 763:  stream_copy_to_stream($temp, $target);
    line 764:  fclose($target);

    And this is my controller:

    $crud->set_field_upload(‘image’, ‘public/uploads/products/’);

    What i’m doing wrong?

    PD: Excuse me for my poor english

    Thanks

    Check your config file if there is

    $config['enable_query_strings'] = true;

    or

    $config['allow_get_array'] = TRUE;

    .
    The problem is that uploader works with $_GET and to your project is disabled. So perhaps this is the problem. What codeigniter version do you use? and what grocery CRUD?

  • #179 / Sep 09, 2011 2:52am

    Sinapit

    10 posts

    @web-johnny

    How about validation for upload file, example: i want to validate image with max_width = ‘1024’and max_height = ‘768’ only can upload on server. Can you give example?

  • #180 / Sep 09, 2011 2:56am

    web-johnny

    235 posts

    @web-johnny

    How about validation for upload file, example: i want to validate image with max_width = ‘1024’and max_height = ‘768’ only can upload on server. Can you give example?

    This is not included on grocery CRUD yet. The upload field is just a simple HTML5 upload field for now on.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases