⚠ 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 forum is read-only and soon will be archived. ⚠


edramirez

Member Since 29 Sep 2013
Offline Last Active Aug 15 2014 07:47 PM
-----

#11373 How to create multiselect dropdown using an array - no table - no database

Posted edramirez on 12 July 2014 - 05:27 AM

Hi, Dona -

 

First of all, welcome to GroceryCRUD! Hope you have looked at all the exciting features of this add-in software.

 

Okay, now for your question. Is it possible to use GC for arrays only?

 

The answer is NO. GC is designed to provide CRUD capability for tables, not arrays. Also, GC multi-select is used for input to be processed elsewhere.

 

In order to use multi-select for an array where the data selected is processed in that same interface, you would best need a javascript framework with grid-control capability to handle that requirement. 

 

Ed




#11362 GroceryCRUD 1.4.1 compatible with CodeIgniter 2.2.0

Posted edramirez on 08 July 2014 - 12:30 PM

Last June 5, 2014, EllisLab officially released version 2.2.0 of CodeIgniter. Based on the upgrade notes, the changes did not affect the current version of GroceryCRUD. Likewise, if you are also using the HMVC add-on, you will notice that nothing has been affected.

 

Just the same, I took time off to check if the new version of CodeIgniter would impact on two of my ongoing projects. Well, I'm happy to say that I encountered no compatibility problems. GroceryCRUD 1.4.1 is truly and fully compatible with CodeIgniter 2.2.0.

 

 

Are you upgrading to this new version of CodeIgniter? Just click the Like button if you are already using GroceryCRUD with the new version of CodeIgniter or are planning to do so soon.

 

Ed




#10397 Redirect to another site after insert

Posted edramirez on 19 December 2013 - 01:44 PM

Hi, Kenneth -

 

First of all, I welcome you to the GC forum. When you do GroceryCRUD and expand your understanding of this library, it's like standing side by side with the giants of CodeIgniter.

 

Now let's get to your question.

 

GroceryCRUD callbacks were actually designed to perform an operation only and not to take the user anywhere. So, an appropriate use for the callback_after_insert is to perhaps add an audit trail record into another file, as shown in the documentation example. Another possible use for this function is to add or deduct the quantity value of a matching item code in an inventory system. That's the basic philosophy behind those callbacks.

 

In your case, you want to provide a confirmation message after a successful insert. This might not be necessary since GC already provides its own confirmation message which is displayed upon the user's return to the list.

 

I suggest that you try out the examples and learn the capabilities of GroceryCRUD on a deeper level in order to appreciate the power of the library. Perhaps there is no need to add additional code beyond the functionality that GC offers.

 

Regards,

 

Ed

 

P.S.

 

Don't forget to click the Like button.




#10101 Magic vs UltimADE

Posted edramirez on 20 November 2013 - 09:18 AM

Most of us who were already around as systems developers during the old DOS days will probably remember Magic and UltimADE.

 

During the early 90s, when database softwares were starting to spring up like mushrooms, a least-known software called Magic rose from nowhere. Magic was created by a U.S. Company called Magic Software Enterprises.

 

There were a number of international competitions held in different parts of the world. Those competitions featured the best of the best programmers worldwide, using the best tools around. Under competition rules, each team had to complete an entire project starting from 9AM to 7pm. For several years, teams using Magic consistently won competitions year after year. In many cases, a team using Magic was only made up of one person, while most others had two members per team. Not one software could stand up to the wrath of Magic.

 

Until one day UltimADE came along.

 

UltimADE was an xBase language IDE developed by a company in Israel. When UltimADE made its debut in the international competitions, there were already a number of Magic developers present. UltimADE brought Magic down to its knees and won almost every competition where Magic developers were expected to win.

 

Fast forward to the present time. GroceryCRUD is like the UltimADE of the 21st century. You only needed a few functions in order to create a robust system. When I compare UltimADE and GroceryCRUD, I see a great many similarities. Both are giant-killers in the software development world.

 

Regards,

 

Ed Ramirez

 

P.S. Don't forget to click the Like button  B)




#10095 Including two tables in one page

Posted edramirez on 19 November 2013 - 03:17 PM

Let me summarize your two issues:

(1) you want to place two tables (or rather tabular views) in one screen view

(2) you want some kind of synchronization, such that when one table is updated, another is updated.

 

Here are some ideas:

 

First, you can only put one and only one grocerycrud operation into one controller. GroceryCrud uses the URL for its functionality. You will run into problems if you try to put two grocerycrud operations into one controller.

 

Second, when updating a table through grocerycrud, you can subsequently update another table. That's no problem as long as you don't require that an update would synchronize its view into the other view.

 

Hope this helps!

 

Ed Ramirez

 

P.S. Don't forget to click the Like button.




#10007 PDF version of GroceryCRUD 2.1.4 API and Function list

Posted edramirez on 12 November 2013 - 08:16 AM

Johnny -

 

What do you say we actually write a book on this? I'm in. I used to be a magazine writer (but for articles on the technical aspects of Chinese Kungfu) and I think this would be great!

 

I believe that we could put a great deal of explanation and provide more examples. Then we could sell this book!  :D

 

I'll do the rest of the writing since you have already written the most important aspects of the software already.

 

Regards,

 

Ed Ramirez




#9991 How do i insert a calculated field in a table?

Posted edramirez on 11 November 2013 - 06:36 PM

Here's an actual example from a program I made. This comes from a master-detail relationship and the code below is from the detail controller. Take note that the calculated field is displayed as a formatted string representing a decimal number with two places.

 

public function assemble($pk)

{
$data['link'] = 'invoices'; // link for "back to invoices"
$data['label'] = 'Invoices'; // label used for "back to invoices"
$gcrud = new grocery_crud();
$gcrud->where('refno',$pk);
$gcrud->order_by('lineno');
$gcrud->set_table('invoicesx');
$gcrud->set_subject('Invoice Details - '.$pk);
$gcrud->columns('lineno','itemcode','qty','price','amount'); 
$gcrud->display_as('lineno','Line #')
->display_as('itemcode','Item Code')
->display_as('qty','Quantity')
->display_as('price','Price')
->display_as('amount','Amount');
$gcrud->callback_column('amount',array($this,'compute_amount'));
$gcrud->fields('refno','lineno','itemcode','qty','price');
$gcrud->field_type('refno','hidden',$pk);
$gcrud->set_rules('lineno','Line #','required|integer');
$gcrud->set_rules('itemcode','Item Code','required'); 
$gcrud->set_rules('qty','Quantity','required|integer'); 
$gcrud->set_rules('price','Price','required|decimal'); 
$gcrud->set_relation('itemcode','items','{itemcode} - {description}',
null,'description'); 
$output = $gcrud->render();
$this->load->view('templates/template3a',$output);
$this->load->view('templates/template3b',$data);
}
 
public function compute_amount($value, $row)
{
return number_format($row->qty*$row->price,2,'.',',');
}
 
 
Regards,
 
Ed Ramirez
 
P.S. Dont forget to click the Like button.  B)



#9972 field_type true_false on read state

Posted edramirez on 10 November 2013 - 03:11 PM

The correct way to do it is like so:

 

$crud->field_type('ativo','dropdown', array('1' => 'Sim', '0' => 'Nao'));

 

Hope this helps.

 

Regards,

 

Ed Ramirez

 

P.S. Don't forget to click the Like button!  :)




#9968 trim rule doesn't work

Posted edramirez on 10 November 2013 - 02:14 PM

From my experience, grocerycrud's set_rules function doesn't operate exactly in the same way as codeigniter's counterpart. That being said, we have to accomplish our desired end in a different way. So, here's how I would do it.

 

Let's say that the login field is of type varchar(10). Make sure that the field is not of type char(10).

 

I would do it this way:

$gcrud->set_rules('login','Usuario','required|alpha_dash|max_length[10]');

 

If the user forces to put any space, the validation rule kicks in.

 

Hope this helps.

 

Ed Ramirez

 

P.S. Don't forget to hit the like button!




#9949 Export button

Posted edramirez on 09 November 2013 - 07:07 PM

Exporting to CSV instead of XLS can be accomplished several ways. The neater way of doing this is to replace the default grocerycrud action for export using the getState function. Always remember that this procedure works only if you use the datatables theme.

 

step 1 - Insert the code to use the datatables theme.

example:

  $gcrud->set_theme('datatables');

 

step 2 - Insert the code to override using getState. The code is placed between the render and the view.

For example, your code might look like this:

  $output = $gcrud->render();

  $this->load->view('report.php',$output); 
 
Insert getState, adjusting the location of your view:

  $output = $gcrud->render();

  // overriding the export action

  $state = $gcrud->getState();
  $state_info = $gcrud->getStateInfo();
  if($state == 'export')
  {
    // this new function replaces grocerycrud's export action
    $this->export_to_csv($state_info);
  }
  else
  {
    // your view is repositioned to this location
    $this->load->view('report.php',$output); 
  }
 

step 3 - Add these 2 new functions to replace grocerycrud's export function. Copy exactly as is:

public function export_to_csv($state_info = null)

{
$data = $this->get_common_data();
 
$data->order_by  = $this->order_by;
$data->types  = $this->get_field_types();
 
$data->list = $this->get_list();
$data->list = $this->change_list($data->list , $data->types);
$data->list = $this->change_list_add_actions($data->list);
 
$data->total_results = $this->get_total_results();
 
$data->columns  = $this->get_columns();
$data->primary_key  = $this->get_primary_key();
 
@ob_end_clean();
$this->_export_to_csv($data);
}
 
 
protected function _export_to_csv($data)
{
$string_to_export = "";
foreach($data->columns as $column){
$string_to_export .= $column->display_as."\t";
}
$string_to_export .= "\n";
 
foreach($data->list as $num_row => $row){
foreach($data->columns as $column){
$string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t";
}
$string_to_export .= "\n";
}
 
// Convert to UTF-16LE and Prepend BOM
$string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8');
 
$filename = "export-".date("Y-m-d_H:i:s").".csv";
 
header('Content-type: application/vnd.ms-excel;charset=UTF-16LE');
header('Content-Disposition: attachment; filename='.$filename);
header("Cache-Control: no-cache");
echo $string_to_export;
die();
}
 

Then you're done!

 

Don't forget to click the Like button!

 

Ed Ramirez




#9948 Export to CSV (Excel)?

Posted edramirez on 09 November 2013 - 07:05 PM

Exporting to CSV instead of XLS can be accomplished several ways. The neater way of doing this is to replace the default grocerycrud action for export using the getState function. Always remember that this procedure works only if you use the datatables theme.

 

step 1 - Insert the code to use the datatables theme.

example:

  $gcrud->set_theme('datatables');

 

step 2 - Insert the code to override using getState. The code is placed between the render and the view.

For example, your code might look like this:

  $output = $gcrud->render();

  $this->load->view('report.php',$output); 
 
Insert getState, adjusting the location of your view:

  $output = $gcrud->render();

  // overriding the export action

  $state = $gcrud->getState();
  $state_info = $gcrud->getStateInfo();
  if($state == 'export')
  {
    // this new function replaces grocerycrud's export action
    $this->export_to_csv($state_info);
  }
  else
  {
    // your view is repositioned to this location
    $this->load->view('report.php',$output); 
  }
 

step 3 - Add these 2 new functions to replace grocerycrud's export function. Copy exactly as is:

public function export_to_csv($state_info = null)

{
$data = $this->get_common_data();
 
$data->order_by = $this->order_by;
$data->types = $this->get_field_types();
 
$data->list = $this->get_list();
$data->list = $this->change_list($data->list , $data->types);
$data->list = $this->change_list_add_actions($data->list);
 
$data->total_results = $this->get_total_results();
 
$data->columns = $this->get_columns();
$data->primary_key = $this->get_primary_key();
 
@ob_end_clean();
$this->_export_to_csv($data);
}
 
 
protected function _export_to_csv($data)
{
$string_to_export = "";
foreach($data->columns as $column){
$string_to_export .= $column->display_as."\t";
}
$string_to_export .= "\n";
 
foreach($data->list as $num_row => $row){
foreach($data->columns as $column){
$string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t";
}
$string_to_export .= "\n";
}
 
// Convert to UTF-16LE and Prepend BOM
$string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8');
 
$filename = "export-".date("Y-m-d_H:i:s").".csv";
 
header('Content-type: application/vnd.ms-excel;charset=UTF-16LE');
header('Content-Disposition: attachment; filename='.$filename);
header("Cache-Control: no-cache");
echo $string_to_export;
die();
}
 

Then you're done!

 

Don't forget to click the Like button!

 

Ed Ramirez




#9942 Export button

Posted edramirez on 09 November 2013 - 11:54 AM

Here's a cheesy way of doing it:

 

In your editor, open Grocery_CRUD.php inside the libraries folder under the applications folder.

 

Proceed to line# 1602. 

 

You will find these last few characters in that line: ".xls";

 

Replace the xls with csv.

 

Save the file and you're good to go.

 

That's it!

 

Regards,

 

Ed

 

P.S. Don't forget to click the LIKE button!




#9905 Grocery Crud in laravel

Posted edramirez on 03 November 2013 - 04:16 PM

If grocerycrud would be incorporated into Laravel, may I make a suggestion? As it is, we only need to copy the grocerycrud files into the correct codeigniter folders. That's why both grocerycrud and codeigniter can work together in a single-user or LAN-based system without the need for internet access whatsoever.

 

The problem with Laravel, Symfony, and some other PHP frameworks is that they need Composer to work. Personally this drives me bananas because most of my applications are accounting-based and operate in a non-internet setting. My applications are data intensive with a lot of complex data relationships.

 

My wish is that grocerycrud will eliminate the need for composer and allow easy and complete installation in a non-internet environment. That being said, GC will create a setup of Laravel without other third-party softwares like doctrine and simplify the installation process.

 

Ed




#9899 Uppercase, Lowercase or Capitalized text on input

Posted edramirez on 02 November 2013 - 05:36 PM

Doing it that way would make the data appear to be in uppercase or lowercase or capitalized. But the actual data stored would not be affected. Hence, if the code were included as above to make the data uppercase but the keyboard was in lowercase, the display would be in uppercase but the data stored into the table would be in lowercase. To store the data in uppercase, we would need to add the following:

 

1. before the render:

$crud->callback_before_insert(array($this,'prepare'));
$crud->callback_before_update(array($this,'prepare'));
 

 

2. as a separate function to save as uppercase:

public function prepare($post_array)
{
$post_array['fieldname'] = strtoupper(trim($post_array['fieldname']));
return $post_array;
}
 
 
Ed



#9878 CI Modular Extensions - HMVC & Grocery_CRUD

Posted edramirez on 29 October 2013 - 05:56 PM

From the beginning, I developed applications with CI, HMVC, and GC. Since GroceryCRUD already incorporates JQuery and Twitter Bootstrap, I was able to access these libraries without having to add them separately.