Skip to content

Commit

Permalink
Merge pull request #445 from kenirwin/model_template_fix
Browse files Browse the repository at this point in the history
Updated code examples to working code for 3.4
  • Loading branch information
josegonzalez committed May 26, 2017
2 parents 3e1ccc8 + a25123e commit f071bd7
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ Basic example
{
public function initialize(array $config)
{
$this->table('users');
$this->displayField('name');
$this->primaryKey('id');
$this->setTable('users');
$this->setDisplayField('username');
$this->setPrimaryKey('id');
// for CakePHP 3.0.x-3.3.x, use the following lines instead of the previous:
// $this->table('users');
// $this->displayField('username');
// $this->primaryKey('id');
$this->addBehavior('Josegonzalez/Upload.Upload', [
// You can configure as many upload fields as possible,
// where the pattern is `field` => `config`
Expand All @@ -44,9 +50,9 @@ Basic example
.. code:: php
<?php echo $this->Form->create('User', ['type' => 'file']); ?>
<?php echo $this->Form->input('User.username'); ?>
<?php echo $this->Form->input('User.photo', ['type' => 'file']); ?>
<?php echo $this->Form->create($user, ['type' => 'file']); ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->input('photo', ['type' => 'file']); ?>
<?php echo $this->Form->end(); ?>
Using the above setup, uploaded files cannot be deleted. To do so, a
Expand Down Expand Up @@ -74,9 +80,15 @@ field must be added to store the directory of the file as follows:
{
public function initialize(array $config)
{
$this->table('users');
$this->displayField('name');
$this->primaryKey('id');
$this->setTable('users');
$this->setDisplayField('username');
$this->setPrimaryKey('id');
// for CakePHP 3.0.x-3.3.x, use the following lines instead of the previous:
// $this->table('users');
// $this->displayField('username');
// $this->primaryKey('id');
$this->addBehavior('Josegonzalez/Upload.Upload', [
'photo' => [
'fields' => [
Expand All @@ -94,10 +106,10 @@ field must be added to store the directory of the file as follows:
.. code:: php
<?php echo $this->Form->create('User', ['type' => 'file']); ?>
<?php echo $this->Form->input('User.username'); ?>
<?php echo $this->Form->input('User.photo', ['type' => 'file']); ?>
<?php echo $this->Form->input('User.photo_dir', ['type' => 'hidden']); ?>
<?php echo $this->Form->create($user, ['type' => 'file']); ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->input('photo', ['type' => 'file']); ?>
<?php echo $this->Form->input('photo_dir', ['type' => 'hidden']); ?>
<?php echo $this->Form->end(); ?>
Displaying links to files in your view
Expand Down

0 comments on commit f071bd7

Please sign in to comment.