⚠ In case you've missed it we are migrating 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. ⚠


Member Since 04 Jul 2014
Offline Last Active Aug 19 2021 05:29 AM

#149378 setRelation Where Condition (Input Statement) doesn't work at v.2.7.9

Posted larasmith on 23 September 2019 - 02:19 AM

Hello Everyone!


With @web-johnny's help, I was able to pinpoint where was the error was coming from.

There was no need to use square braces in the where condition of the setRelation. 

Removing square braces made both WHERE IN and  OR condition.



So instead of: 

$crud->setRelation('salesRepEmployeeNumber','employees','lastName', ["employeeNumber IN ('1102', '1702')"]); 

It should be:

$crud->setRelation('salesRepEmployeeNumber','employees','lastName', "employeeNumber IN ('1102', '1702')"); 

and for the OR WHERE:

$crud->setRelation('el_CourseId', 'set_course', '{course_Title} - [{course_RefNo}]', ["(course_Id = '1522' OR course_Id='1688')"]);

it should be:

$crud->setRelation('el_CourseId', 'set_course', '{course_Title} - [{course_RefNo}]', "(course_Id = '1522' OR course_Id='1688')"); 

I hope this helps others too!



#16479 GC x GC Enterprise

Posted larasmith on 09 August 2018 - 12:32 AM

According to:https://www.grocerycrud.com/enterprise


Grocery CRUD Enterprise is a version that was created completely from scratch with the simplicity of Grocery CRUD community in mind. The main differences that you will see straight away are:

  • It is framework agnostic. That simply means that Grocery CRUD Enterprise can work in any PHP framework and of course with native PHP as well. We have also tested that the CRUD is working just fine and smoothly at the below frameworks:
    • Codeigniter
    • Laravel
    • Slim
    • Zend Framework
    • Symfony
    • Native PHP (with just composer installation)
  • Grocery CRUD Enterprise can be used for other databases (not only mySQL) such as: Oracle, MSSQL, PostgreSQL... e.t.c. For more check ZendDb 2 adapter
  • Faster usability. All the requests are now with AJAX calls and you can feel the difference straight away just from the demo.
  • Multiple datagrid functionality at one page.
  • The frontend section is now completely separated from the backend section with API calls. That gives many benefits such as:
    • Ability to cache your initial call in production
    • Ability to cache all of your frontend sections (e.g. with CDN, use memcache,... e.t.c.)
    • You can use YOUR OWN API and still have the same usability for the end user.

We did try very hard to migrate all of the documented functions to Grocery CRUD Enterprise. The most of the functions are migrated to Grocery CRUD Enterprise, however there are some that they aren't! For more see the FAQ question below "I am updating from Grocery CRUD community to enterprise version. What should I need to know?"

#16213 Bugs found in Enterprise Edition Version 2.5.2

Posted larasmith on 11 April 2018 - 01:02 AM

Hello @johnny!


Wow such a fast update... I'll be updating mine now!  :D


Thanks Johnny!

#15729 Creating Custom Header During Printing

Posted larasmith on 09 November 2017 - 06:27 AM

Hello @langithitam!


Sure... This is how I do it:


Prior generating the list the custom header is assigned to the session variable:

$_SESSION['CustomHeader']   = $this->m_Shared->CreateCustomHeader("Security Log List");

and the output is:



Please do take note that CreateCustomHeader there in my code is function that customly formats my header.


You can actually just assign any text to the custom header for example:

$_SESSION['CustomHeader']   = "This is my sample header.";

and the output is:




Happy GCing!  :)  ;)  :D

#15712 How to create DEPENDENT DROP-DOWNS in the enterprise edition?

Posted larasmith on 06 November 2017 - 01:10 AM

After the date issues have been resolved, 

I hope that dependent drop down feature is next in line now...


This is going to be a big leap but indeed a very useful feature.


:)  ^_^

#15686 Creating Custom Header During Printing

Posted larasmith on 28 October 2017 - 08:39 AM



I noticed that upon update the line number may change.


So instead of specifying the line number, just find:

<div class="print-table">
and paste: 
<?php if(isset($_SESSION["CustomHeader"]) && $_SESSION["CustomHeader"]<>'') echo $_SESSION["CustomHeader"]; ?>

before the tag: <table> and:

<?php if(isset($_SESSION["CustomFooter"]) && $_SESSION["CustomFooter"]<>'') echo $_SESSION["CustomFooter"]; ?> 

after the tag: </table>


Happy Gcing to all    :)    ;)    :lol:

#15624 Creating Custom Header During Printing

Posted larasmith on 13 October 2017 - 12:57 AM

Updates to this post: If you upgrade to 2.3.5.


The lines to add in: the file: "main.html" located in: "application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Themes\Bootstrap\views\build\" are:

<?php if(isset($_SESSION["CustomHeader"]) && $_SESSION["CustomHeader"]<>'') echo $_SESSION["CustomHeader"]; ?>


<?php if(isset($_SESSION["CustomFooter"]) && $_SESSION["CustomFooter"]<>'') echo $_SESSION["CustomFooter"]; ?>

Happy Gcing to all   :)   ;)   :lol:

#15603 API - How to use - getState

Posted larasmith on 10 October 2017 - 12:08 AM



Hello @darkstalker,


You were very very close to your solution really. Just to make sure that someone else will have the solution right. You don't really need the AddForm and EditForm. You just need to have this code:

$state = $crud->getState();
if ($state == 'Insert') {
} else if ($state == 'Update') {



Hi Johnny,


$user = $this->ion_auth->user()->row();


$state = $crud->getState();
if ($state == 'Insert') {

// How can get the username of the current user and save it to my table?


//i tried this one but all the field of userid got the same username. and inserting two row.

$this->db->insert('my_table', array('userid' => $user->username));



} else if ($state == 'Update') {
// How can get the username of the current user and save it to my table?




Thank you in advance. Have a great day and more power.




Hello there!


Since you are trying to get the current username, you can actually place it in a session variable upon login

so you can use it when you need to place it in your database.


Happy GCing!  :)

#15272 Creating Custom Header During Printing

Posted larasmith on 23 June 2017 - 08:09 AM

In the Community Edition I was able to create a custom header and footer during printing (clicking the print button). 

See image for reference: 



I did it by modifying the file:Grocery_CRUD.php located in 'application\libraries\'

and adding the following line above the code: $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>';

if(isset($_SESSION['CustomHeader']) && $_SESSION['CustomHeader']<>'') $string_to_print .= $_SESSION['CustomHeader'];

Now I was wondering if It can be done in the Enterprise Edition by using a custom model instead of editing the core or library.

This would be useful to fully maximize the printout or report generated by the CRUD.


#15225 How to use setRule / setRules in password validation Enterprise Edition

Posted larasmith on 07 June 2017 - 03:48 AM

I finally figure it out using the links:

1. Valitron: https://github.com/vlucas/valitron

2. API & Function: https://www.groceryc...n-list/setRules


In my case I used a custom regex to achieve what I want:

           'fieldName' => 'u_Pwd',
           'rule' => 'regex',
           'parameters'=> '/^[a-z\d\-_\s]+$/i'
           // Allow A-Z, 0-9, dash, underscore and space
           'fieldName' => 'u_Pwd',
           'rule' => 'lengthMin',
           'parameters'=> '3'
           'fieldName' => 'u_Cpass',
           'rule' => 'equals',
           'parameters'=> 'u_Pwd'


I just hope it helps someone too. Cheers!  :)

#15221 How to Create Fake Fields (a.k.a. Confirm Password) in Enterprise Edition

Posted larasmith on 05 June 2017 - 01:27 AM

In the community edition it is allowed to create fake fields which is used in confirm password forms.

How can I implement it in the enterprise edition? Please refer to the console in the photo below for the error.

I tried adding a field in the table named the same as the confirm password field and the error is gone.

I believe there is a better solution for this. I just can't figure it out yet.





#11516 Dependent Drop Down With Multiselect

Posted larasmith on 31 August 2014 - 07:06 AM

Finally I get this to work! :)  I just hope someone find this solution also useful for them...  :lol:


1. Get dependent items using ajax/jquery:

    Create a CONTROLLER that creates/receives the needed output based on the selected value on the drop down. I placed it on the same file that contains the controller that generates my datagrid. The file name is: "ctrl_gcrud.php"

public function get_funct_by_prog($progID)
	$mysqli = new mysqli("localhost", "USERNAME", "PASSWORD ", "DBNAME");
	$result = $mysqli->query("SELECT * FROM tblfunction WHERE funct_prog_id ='".$progID."'");		

	while($row_funct = mysqli_fetch_array($result))
             echo "<option value='".$row_funct['funct_id']."'>".$row_funct['funct_Name']."</option>";

2. Create a callback inside the same controller: "ctrl_gcrud.php". This call back is responsible for the following:

    a. Delete all elements from the multi-select: $("#field-Functions").find("option").remove();

    b. Add new elements in the multi-select: $("#field-Functions").html($response.responseText);

    c. Refresh "choosen select" plugin: $("#field-Functions").trigger("liszt:updated"); and $(".remove-all").trigger("click");

   Here is the code for the working callback:

	function tos_CBae_selFunc()
		return '
			<script type="text/javascript">
					$("#field-tos_prog_id").change(function() {
						var progID = $("#field-tos_prog_id").val();  
							         "url" :  "http://localhost/OCGA/ctrl_gcrud/get_funct_by_prog/"+ progID,      
							         "cache" : true,
							         "beforeSend" : function (){
							              //Show a message
							         "complete" : function($response, $status){
							             if ($status != "error" && $status != "timeout") {
							         "error" : function ($responseObj){
							             alert("Something went wrong while processing your request.\n\nError => "
							                 + $responseObj.responseText);
			' ;				

3. This is the controller that generates my datagrid: Notice the lines of code that is used to make our callback work.And here is the successful desired output:

	public function tos()
 		/*Create ajax_grocery_CRUD instead of grocery_CRUD. This extends the functionality with the
 		 field_set_defaults keeping all functionality as well (I extended this to grocery_CRUD)*/
		$crud = new ajax_grocery_CRUD();
		// Set theme

		// Set table name
		// Set this name instead of 'Record' in prompt
		$crud->set_subject('Table of Specification');
		//* These displays custom name instead of field name in columns						
		$crud->display_as('tos_course_DescTitle_id','Descriptive Title');
		$crud->display_as('tos_course_RefNo_id','Reference No.');			
		$crud->display_as('tos_lo_name_id','Learning Objective');
		$crud->display_as('tos_qtype_id','Question Type');
		$crud->display_as('tos_coglvl_id','Cognitive Level');
		$crud->display_as('tos_diffindex_id','Difficulty Index');
		$crud->display_as('tos_PilotTest_id','Pilot Tested');		

                // Sets relation with dependent dropdown list (Program->Function)

   		// Sets function (this must be dependent on the program)
         	$crud->set_relation_n_n('Functions', 'tbltos_funct', 'tblfunction', 'tos_id', 'funct_id', "{funct_Name}", 'priority');

		// This is the set of code for using the callback -*begin ppp
		$f=array'secret','tos_id','tos_assmntype_id','tos_prog_id','Functions','tos_sem_id','tos_qtype_id','tos_remarks_id','tos_reviewed_id','tos_status_id','tos_published_id','tos_PilotTest_id','tos_qry','tos_ctr','tos_need'); $crud->add_fields($f); $crud->edit_fields($f); $crud->callback_add_field('secret',array($this,'tos_CBae_selFunc')); $crud->callback_edit_field('secret',array($this,'tos_CBae_selFunc')); // -*end        

		// Sets dropdown list (Semester)

		// Sets dropdown list (QType)

		// Sets dropdown list (Remarks)

		// Sets dropdown list (Status)

		// Sets dropdown list (Reviewed bool)

		// Sets dropdown list (Published bool) then turn it as default value as text

		// Sets dropdown list (PilotTest bool) then turn it as default value as text

		//Removes the print feature $crud->unset_print();

		//**** These displays the output in the page
		$output = $crud->render();



Special thanks to the hints provided by none other than the grocery CRUD Hero himself: Sir Victor... It took me almost a month to get it though... I just hope this helps someone too.... This method is also tested working in multiselect created by using this code:

   	$this->db->select('funct_id, funct_Name');
	$results = $this->db->get('tblfunction')->result();
	$funct_multiselect = array();
	foreach ($results as $result) {
    	$funct_multiselect[$result->funct_id] = $result->funct_Name;
	$crud->field_type('tos_qry', 'multiselect', $funct_multiselect); 

Here is what it looks like:



Happy GCng!  :D