This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Listener; | |
use Cake\Utility\Inflector; | |
use Crud\Listener\BaseListener; | |
use Crud\Event\Subject; | |
class ContainedModelsListener extends BaseListener { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$registry = $this->helpers(); | |
$helpers = $this->helpers; | |
pr($helpers); | |
/* | |
Array( | |
[CrudView] => Array( | |
[className] => App\View\Helper\CrudViewHelper | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ParticipantsTable extends AppTable | |
{ | |
public function beforeMarshal(Event $event, \ArrayObject $data, \ArrayObject $options) { | |
if(isset($data['partner']) && is_array($data['partner'])) { | |
$participant = $this->get($data['id']); | |
$data['partner']['participant_type_id'] = $participant->type_id; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model\Table\Behavior; | |
trait UpdateCounterCacheTrait { | |
public function cleanupBelongsToMany($return_count = null) { | |
if($return_count) { | |
return $count; | |
} | |
return $this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* use like: | |
* httpPostDataFile( | |
* 'https://www.google.com/search', // the url to post to, optionally including get parameters like: ?this=that&here=there | |
* [ | |
* 'q' => 'php http upload file', // post data like: <input name="q" value="php http upload file" /> | |
* ... | |
* ], [ | |
* 'image' => [ // the input name used like: <input name="image" type="file" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ATable extends \Cake\ORM\Table | |
{ | |
public function validationDefault(Validator $validator) | |
{ | |
$fields = ['salutation', 'firstname', 'lastname']; | |
$validator | |
->provider('allEmptyOrFilled', $fields); | |
foreach($fields as $field) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
class AppController extends \Cake\Controller\Controller | |
{ | |
public function initialize() | |
{ | |
parent::initialize(); | |
/* | |
* Can't listen on the "initialize" event here obviously, "startup" and all later ones do work though. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AModel { | |
var $hasMany = array( | |
'Field' => array( | |
'className' => 'Field', | |
'foreignKey' => '', | |
'dependent' => false, | |
'conditions' => '', | |
'fields' => '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
class AController extends AppController { | |
public function index() { | |
try { | |
$this->set('data', $this->paginate()); | |
} catch(\Cake\Network\Exception\NotFoundException $e) { | |
$this->redirect(['page' => 1] + $this->request->query); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In your controller action set it up like that: | |
$action->config('scaffold.relations_actions_blacklist', [ | |
'Registrations' => ['edit', 'delete'], // only allow view action | |
'Rewards' => ['delete'], // don't allow delete | |
]); | |
Change/add this in the appropriate place in the Template/Element/view/relations/has_many.ctp which you have copied from the CrudView plugin to your own src/ dir: | |
foreach (${$viewVar}->{$details['entities']} as ${$otherSingularVar}) : | |
. |
NewerOlder