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,
/////////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);
}
public function getowner() {
$id = $_GET['id'];
$data = $this->Powners->get($id);
echo json_encode($data);
}

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);
    }
entity code:
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Cake\Utility\Inflector;
/**
* Pet Entity.
*/
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.
@jimgwhit
jimgwhit / db.php
Created May 16, 2021 20:29 — forked from luckyshot/db.php
PHP/MySQL (PDO Database) method with named parameters
<?php
/*
PHP/MySQL (PDO) method with named parameters
---------------------------------------------
https://gist.github.com/luckyshot/9477105
Last updated: 12 Sep 17
$config = [