Skip to content

Instantly share code, notes, and snippets.

$("#myTable td:nth-child(1)").click(function(event)
{
event.preventDefault();
var $td= $(this).closest('tr').children('td');
var currentCellText = $td.eq(0).text();
var CellText = $td.eq(1).text();
$.ajax({
url:'<?php echo "getowner";?>',
type: 'GET',
data: 'id='+currentCellText,
public function getowner() {
$id = $_GET['id'];
$data = $this->Powners->get($id);
echo json_encode($data);
}
/////////controller
public function getowner() {
$id = $_GET['id'];
$data = $this->Powners->get($id);
$petowner = $data->oname;
$ostreet = $data->ostreet;
$retvalue = $petowner . "|" . $ostreet;
namespace App\Model\Entity;
use Cake\ORM\Entity;
class Article extends Entity
{
protected function _getTitle($title)
{
return ucwords($title);
}
entity code:
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Cake\Utility\Inflector;
/**
* Pet Entity.
*/

Anyone new to RBAC I highly suggest using laravel's or Spatie https://github.com/spatie/laravel-permission

However being familiar with RBAC I use built in authentication but have custom authorization.

I use static helper classes, but instance will also work. And these are just simple examples of making sure a required role of a method matches with one of the logged in users role.

I have a role field in users table like:

   role 

At times on a shared host you may not be able to use a symbolic link. I sometimes just display from a folder outside of web folder:

A bare basic example, this file just name it DisplayImage.php

<?php
$basedir = '/some_folder/images'; // on hard drive
$imagedir = $_GET['dir'];
$image = $_GET['img'];
@jimgwhit
jimgwhit / Upload.md
Created June 14, 2020 19:49
Image upload
// In an update method
public function add()
{
    // Validate as needed
    $lid=DB::table('dc_dogs')->count();
    $lid=$lid+1;
    $file=Request::file('ufile');
    $file_name=$file->getClientOriginalName();
 $file_ext=$file-&gt;getClientOriginalExtension();
@jimgwhit
jimgwhit / Json_response.md
Created June 30, 2020 01:47
Json response with Jquery

Just quick examples, so apply validation and authentication and authorization as needed.

For returning a single record:

    public function testc() {
        $dogid = Request::input('somevar');
        $dog = Dog::find($dogid)->toArray();
        return Response::json($dog);
    }
On a PHP coding forum someone ask how to loop a certain array.
The data was in Json format (not shown), but this will give a good idea of how to handle looping an array.
I just named the Json data $mydata.
First json decode it:
```
$decoded = json_decode($mydata, true);
// I just put the json in the variable $mydata to work with.