cakephp 3 commonly used code snippets

Find conditions $data = $this->ProductComponents->find('all') ->contain(['ProductComponentGroups','ProductGroups']) ->select([ 'id', 'name', 'created', 'modified', 'product_component_group_id', 'product_group_id', 'ProductComponentGroups.id', 'ProductComponentGroups.name','ProductGroups.name' ]) ->where([$conditions]) ->order($order) ->limit($limit) ->p...

Codeignitor common model codes to use in site wide controllers

Following reusable model codes are mentioned for codeignitor framework function findByField($field, $value, $tbl){ $this->db->from($tbl); $this->db->where($field, $value); $query = $this->db->get(); $result = ( $query->num_rows() >= 1 ) ? $query->row() : NULL; return $result; } function findRow...

Jquery commonly used code and snippets

Click event on both static and dynamically created elements $(document).off("click",'.invest-models').on('click', '.invest-models', function (e) { $(this).toggleClass('red-bg'); if($(this).hasClass('red-bg')){ $(this).html('Hide Models'); }else{ $(this).html('Display Models'); } }); How to close BS modal clicking outside modal $("body").on("click", ".modal-dialog", fu...

Laravel most commonly used commands and code references

To create a projectcomposer create-project --prefer-dist laravel/laravel blog Databse Initial table setupphp artisan migrate To avoid key long error ( AppServiceProvider )use Illuminate\Support\Facades\Schema;Schema::defaultStringLength(191);Authentication Scaffoldingcomposer require laravel/ui To create necessary controllers, routes and views for authphp artisan ui bootstrap --auth To compile...

Helpful Css code snippet references for my project

Custom styled dropdown Html and Css <div class="select-dropdown"> <select name="my-review-status" id="my-review-status"> <option value="1">Given</option> <option value="2">Not Given</option> </select> </div> .select-dropdown { position: relative; background-color: #e6e6e6; width: auto; float: left; max...

Finding and deleting duplicate rows in parent and child tables

In one of my projects, I had to find and delete duplicate rows in parent and child tables. So, I came up with following rough queries and kept here for my future references. SELECT id, NAME, COUNT(role_id) AS numofroles FROM users GROUP BY NAME HAVING numofroles > 2 SELECT * FROM users WHERE NAME LIKE 'DANIEL HEILIG' SELECT COUNT(id) FROM users WHERE NAME LIKE 'DANIEL' SELECT * F...

Exporting php array to csv

public function export($results){ $file_name = 'fusion_search_on_'.date('Ymd').'.csv'; header("Content-Description: File Transfer"); header("Content-Type: application/csv;"); header("Content-Disposition: attachment; filename=$file_name"); // file creation $file = fopen('php://output', 'w'); $header = ['Incoming Date','WWNDT Job #', 'Operator', 'Division', 'Job Number',...

Cron Job curl with url

<p>Sometimes it is necessary to automate tasks with cron job in a project. In order to do that cpanel gives some default syntax. Along with that you need to curl the url to setup the cron job correctly.</p><p>Following is one example way of doing it.</p><p>curl --silent https://some-url.com & >/dev/null<br /><br />Above --silent is used to a...