Hi Dakota,
*Thanks for taking the time to answer my specific questions, I appreciate
it. I have got this part working, but will no doubt return to this forum
with further questions as 3.xx is a learning curve.*
*Thanks again.*
*Dave*
On Monday, 22 September 2014 08:01:11 UTC+1, Dakota wrote:
>
> Hey Dave,
>
> 1. Assuming you are in the UsersController and what to get the value of a
> single field of users with $id:
> $tempKey =$this->Users->get($id, ['fields' => ['temp_key']])->tempKey;
> While this is more verbose that 2.x was, I believe this is for the better.
> You can quite easily implement a field method for your tables.
>
> 2. CakePHP 2.x is (Assuming UsersController):
> $this->User->set($this->request->data);
> if ($this->User->validates(array('fieldList' => array('email')))) {
> }
>
> CakePHP 3.x is (Assuming UsersController):
> $userEntity = $this->Users->newEntity($this->request->data);
> if ($this->Users->validate($userEntity, ['email'])) {
> }
>
> Or:
> $validator = new \Cake\Validation\Validator();
> $validator->add('email', ['rule' => 'email']);
> $errors = $validator->errors($this->request->data);
> Which, while more verbose, allows you to very easily create transient
> validation rules without needing to touch the ORM layer.
>
> The Cake 3 ORM layer is far more complex than the old Cake 2.x model
> layer, however, this extra complexity makes it far more powerful. You can
> literally build any SQL statement you want without ever having to write a
> single line of SQL.
>
> As for the switch to Square brackets, Cake 3 requires PHP 5.4, and [] is
> quicker to write than array(), so it makes sense.
>
> And the namespacing and use's is a small price to pay for the benefits
> that namespaces provide.
>
> Hope this clarifies things for you!
>
> On Sunday, 21 September 2014 22:48:10 UTC+2, Dave Edwards wrote:
>>
>> Thanks, I thought that this is where I may get some help over the new
>> 'features' or ways of working in 3.xx, that I do not understand, and not
>> told to go and read up on PHP - that's actually quite dismissive and
>> patronising. What I actually need to understand is what you've done to Cake
>> 3.xx. because I do not understand your new documentation - sorry for being
>> so thick. I may be mistaken, but I thought that cake got it's name because
>> using the framework was a 'piece of cake' i.e. simple to use - I'm afraid
>> as a user of cake that this is no longer the case :(
>>
>> I do understand 2.xx and its' documentation... not 3.xx
>>
>> A a couple of examples, in 2.xx I could do this
>>
>> $key = $this->User->field('temp_key')
>>
>> now I have to do this
>>
>> /* something else needs to go here, but I haven't worked it out yet
>> because I keep getting errors*/
>> $key = $users->find()->extract('temp_key')
>>
>> another example is that I could do this
>>
>> if ($this->User->validates(array('fieldList' => array('email'))))
>> {
>>
>> }
>>
>> now I have to do this
>>
>> $users = TableRegistry::get('Users');
>> $user = $users->newEntity($this->request->data());
>> $valid = $users->validate($user, ['email']);
>>
>> if ($valid) {
>>
>> }
>>
>> Is this progress?
>>
>> With regards to square brackets, (now that I've looked it up), you could
>> have simply said that in PHP 5.4 square brackets are a short syntax for
>> array(), and whilst the old method will not be removed, we've decide to use
>> them. I would have understood that - so I'm obviously not that thick.
>>
>> If we were all programmers to your standard, we wouldn't need to use a
>> framework, but a framework *should* remove the hard work...
>>
>> Thanks for the reply.
>>
>> Dave
>>
>>
>> On Sunday, 21 September 2014 21:03:00 UTC+1, José Lorenzo wrote:
>>>
>>> I think to read a bit more of how php works, it will help you understand
>>> much better how to work with CakePHP. I don't know a good tutorial for
>>> learning PHP, though.
>>> You can also google about the new features in the language since PHP
>>> 5.3, specially the changes in 5.4 since you look confused about the use of
>>> square brackets.
>>>
>>> On Sunday, September 21, 2014 7:43:03 PM UTC+2, Dave Edwards wrote:
>>>>
>>>> Thanks, but neither seem to work...
>>>>
>>>> You suggested, $allTitles = $articles->find()->extract('title');
>>>>
>>>> I tried $users->find()->extract('temp_key') but gives an error of
>>>> Call to a member function find() on a non-object
>>>>
>>>> You suggested $this->User->validates(array('fieldList' =>
>>>> array('email', 'password')))
>>>>
>>>> I tried $this->User->validates(array('fieldList' => array('email')))
>>>> but gives an error of
>>>> Unknown method "validates"
>>>> I wouldn't have thought that the second solution would have worked
>>>> anyway as 3.xx seems to have done away with the use of the word array in
>>>> favour of square brackets. why I don't know?
>>>>
>>>> In fact, I've just found an entry on validating in controllers in '
>>>> http://book.cakephp.org/3.0/en/orm/table-objects.html' why this isn't
>>>> in 'http://book.cakephp.org/3.0/en/core-libraries/validation.html', I
>>>> again don't know. This seems to be a common theme with the new docs, with
>>>> a
>>>> lot of useful information scattered across the docs in many different
>>>> places and not always where you'd expect to find it!
>>>>
>>>>
>>>> Dave
>>>>
>>>> On Sunday, 21 September 2014 13:29:55 UTC+1, Dr. Tarique Sani wrote:
>>>>>
>>>>>
>>>>> There are several ways to achieve what you want and they are all in
>>>>> the docs. Quoting a few lines from the V3 Book
>>>>>
>>>>> $allTitles = $articles->find()->extract('title'); //you can add a
>>>>> ->where() to this
>>>>>
>>>>> $this->User->validates(array('fieldList' => array('email',
>>>>> 'password')))
>>>>>
>>>>> Yes your controller looks just about right and it is very easy to
>>>>> understand what to expect as I read further.
>>>>>
>>>>> HTH
>>>>>
>>>>> T
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Sep 21, 2014 at 4:23 PM, Dave Edwards <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am trying to write an app in 3.xx using functionality that I have
>>>>>> previously used in 2.xx but despite scouring the docs, I cannot find the
>>>>>> answers. Apologies if they are in there, but there seems to be 5x the
>>>>>> amount of documentation especially around the new ORM.
>>>>>>
>>>>>> In 2.xx I could easily find the value of a single field e.g.
>>>>>> $this->User->field('temp_key') Is there a 3.xx equivalent ?
>>>>>>
>>>>>> In 2.xx I could validate a field in a model
>>>>>> e.g. $this->User->validates(array('fieldList' => array('email'))) Is
>>>>>> there
>>>>>> a 3.xx equivalent ?
>>>>>>
>>>>>> Lastly a general question. The top of my Users controller currently
>>>>>> looks like this, and I've not yet finished it...
>>>>>>
>>>>>> namespace App\Controller;
>>>>>>
>>>>>> use App\Controller\AppController;
>>>>>> use Cake\Network\Exception\ForbiddenException;
>>>>>> use Cake\Event\Event;
>>>>>> use Cake\ORM\TableRegistry;
>>>>>> use Cake\Utility\Security;
>>>>>> use Cake\ORM\Entity;
>>>>>>
>>>>>> class UsersController extends AppController {
>>>>>>
>>>>>> Does this look right, compared to the simplicity of 2.xx this now
>>>>>> looks very unwieldy and complicated?
>>>>>>
>>>>>> Thanks for any replies.
>>>>>>
>>>>>> Dave
>>>>>>
>>>>>> --
>>>>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>>>>> Find us on Twitter http://twitter.com/CakePHP
>>>>>>
>>>>>> ---
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "CakePHP" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>> Visit this group at http://groups.google.com/group/cake-php.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> =============================================================
>>>>> Hire a CakePHP dev team : http://sanisoft.com
>>>>> =============================================================
>>>>>
>>>>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.