Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated code examples to working code for 3.4 #445

Merged
merged 4 commits into from
May 26, 2017

Conversation

kenirwin
Copy link
Contributor

I tried using the existing documentation to set up CakePHP-upload for the first time and ran into a few issues. This pull request reflects the changes I had to make to get it to work.

  • As of CakePHP 3.4, the initialize() function uses setTable(), setDisplayField(), and setPrimaryKey() instead of the method names not including 'set';
  • It looks like the Form helper used Model names in some earlier version of CakePHP, but those now get left out. I changed to using $user instead of User in lines 47 & 97; I removed the 'User.' from the field names in the input.

@davidyell
Copy link
Member

These changes would make the minimum required Cake version 3.4, which won't be to everyone's taste.

Better to keep the older deprecated methods, to broaden compatibility.

@davidyell davidyell added the 3.x label May 25, 2017
@Spriz
Copy link

Spriz commented May 26, 2017

Really 🤔 I mean if not even FoC pushes towards the latest version, then who would?

At least when it's just docs :)

@@ -44,9 +44,9 @@ Basic example

.. code:: php

<?php echo $this->Form->create('User', ['type' => 'file']); ?>
<?php echo $this->Form->input('User.username'); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok -- I've added the old code in comments after each affected code block. Will this work?

$this->table('users');
$this->displayField('name');
$this->primaryKey('id');
$this->setTable('users');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a note here saying these are for 3.4+, and having the older ones commented out for those who have yet to upgrade cake core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure -- I will give it a go.

@Spriz
Copy link

Spriz commented May 26, 2017

I think the $this->Form->create('User', ['type' => 'file']);-part is a leftover from cake 2.x - eh?

@kenirwin
Copy link
Contributor Author

That could well be. Since I started using cake 2 weeks ago, I will defer to others' experience with that. With that in mind, I've removed the older code.

One other thing I wonder about is this:
$this->setDisplayField('name'); // $this->displayField('name');

There's no name field in the database; it calls for a username. Should that be
$this->setDisplayField('username'); // $this->displayField('username');

It didn't seem to make a difference in behavior for me, but I wonder if it's more correct.

@josegonzalez
Copy link
Member

Yeah that should be username, can you change that too?

@kenirwin
Copy link
Contributor Author

Ok - I've fixed the display name.

@josegonzalez josegonzalez merged commit f071bd7 into FriendsOfCake:master May 26, 2017
@kenirwin kenirwin deleted the model_template_fix branch June 1, 2017 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants