Vote for CakePHP on DevDocs!

2014-07-23 Thread OJ Tibi - @ojtibi
Hi folks!

I've recently stumbled upon an all-in-one documentation web app named 
DevDocs. I suggest you look around, play with it and search through 
documentation you might use everyday (vanilla PHP, Angular, vanilla 
JavaScript, other preprocessors, etc.)

If you like DevDocs and love CakePHP, please vote on the card named CakePHP 
on the "To Do [Others]" list for its inclusion here:

https://trello.com/b/6BmTulfx/devdocs-documentation

Also, I think it would be helpful to add some comments if you want the 
authors to know which version of the docs you want to be included.

Cheers!

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3 - Accessing user session in models

2014-07-23 Thread Stefano Zoffoli
Thank you!


--
 Stefano Zoffoli
*Resp. Sviluppo Software*
347 8180258

*Librasoft Snc*
www.LibrasoftSnc.it 
www.ProgettoKuma.it 
0543 424612


2014-07-23 18:18 GMT+02:00 José Lorenzo :

> The displayField you can get it from the table. That is
> $event->subject()->displayField();
>
> You can also determine the prefix from the table in $event->subject() I
> guess
>
>
> On Wednesday, July 23, 2014 4:50:10 PM UTC+2, Stefano Zoffoli wrote:
>>
>> Thank you, this is a very nice solution and it worked perfectly!
>>
>> How can I pass extra infos for Logs' description field? (i mean like a
>> custom prefix string and the entity displayfield's value?)
>>
>>
>> --
>>  Stefano Zoffoli
>> *Resp. Sviluppo Software*
>> 347 8180258
>>
>> *Librasoft Snc*
>> www.LibrasoftSnc.it 
>> www.ProgettoKuma.it 
>> 0543 424612
>>
>>
>> 2014-07-23 13:55 GMT+02:00 José Lorenzo :
>>
>>> I see I would re-do that at the controller level:
>>>
>>> class AuditLogger implements \Cake\Event\EventListener {
>>>
>>>   public function construct(AuthComponent $auth) {
>>> $this->_auth = $auth;
>>>   }
>>>
>>>   public function implementedEvents() {
>>> return ['Model.afterSave' => 'logSave'];
>>>   }
>>>
>>>   public function logSave($event, $entity, $options) {
>>>  $logs->save(new Entity(['user_id' => $this->auth->user('id'),
>>> ...]));
>>>   }
>>> }
>>>
>>> And in your Controller:
>>>
>>> public function beforeFilter() {
>>>
>>>$this->Customers->eventManager()->attach(new AuditLogger($this->Auth)
>>> );
>>> }
>>>
>>> This way you keep your separation of concerns and have smaller and more
>>> testable classes that you can reuse :)
>>>
>>> On Wednesday, July 23, 2014 12:56:51 PM UTC+2, Stefano Zoffoli wrote:

 Yes of course:
 I have a CustomersTable, a UsersTable and a LogsTable. The LogsTable
 has basically 4 fields: id, user_id, description, created.

 When an authenticated user saves a customer, i'd like to log this user
 action. So, in CustomersTable I added a callback method like this:

 public function afterSave(Event $event, Entity $entity, array $options)
 {
   $logs = TableRegistry::get('Logs');
   $log = $logs->newEntity([
 'user_id' => AuthComponent::user('id'),
   'description' => 'Saved customer',
   ]);
   $logs->save($log);
 }

 But AuthComponent::user() is not static and gave me fatal error.


 --
  Stefano Zoffoli
 *Resp. Sviluppo Software*
 347 8180258

 *Librasoft Snc*
 www.LibrasoftSnc.it 
 www.ProgettoKuma.it 
 0543 424612


 2014-07-23 12:40 GMT+02:00 José Lorenzo :

> That's not possible anymore. We are currently investigating clean ways
> of implementing this use case. May I ask why you need the session in the
> table?
>
>
> On Wednesday, July 23, 2014 11:53:48 AM UTC+2, Stefano Zoffoli wrote:
>>
>> Hi,
>> i'd like to read user auth infos in a Table Class (for example i want
>> to log which user has saved a given entity in a AfterSave callback 
>> method).
>>
>> In cakephp 2 there was AuthComponent::user() static method, but in
>> cakephp 3 that method is not static anymore, and I can't find a simple 
>> way
>> to access that information outside of Controllers.
>>
>> How can i do that?
>> Thank you
>>
>> --
>>  Stefano Zoffoli
>> *Resp. Sviluppo Software*
>> 347 8180258
>>
>> *Librasoft Snc*
>> www.LibrasoftSnc.it 
>> www.ProgettoKuma.it 
>> 0543 424612
>>
>  --
> 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 cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>

  --
>>> 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 cake-php+unsubscr...@googlegroups.com.
>>> To post to this group, send email to cake-php@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> Like Us on FaceBook htt

Re: file upload

2014-07-23 Thread Stephen S
Do you mean you're trying to initiate a file download on click? Can you
provide some code snippets so we can help further, the error you've shared
only shows that it's trying to render a view or layout that doesn't exist.


On 23 July 2014 12:45, Eric Yullu  wrote:

> created an application that is utlizing file upload, but when i click
> download button i get error, media.ctp not found
>
> --
> 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 cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Kind Regards
 Stephen Speakman

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3 - Accessing user session in models

2014-07-23 Thread José Lorenzo
The displayField you can get it from the table. That is 
$event->subject()->displayField();

You can also determine the prefix from the table in $event->subject() I 
guess

On Wednesday, July 23, 2014 4:50:10 PM UTC+2, Stefano Zoffoli wrote:
>
> Thank you, this is a very nice solution and it worked perfectly!
>
> How can I pass extra infos for Logs' description field? (i mean like a 
> custom prefix string and the entity displayfield's value?)
>
>
> --
>  Stefano Zoffoli
> *Resp. Sviluppo Software*
> 347 8180258
>
> *Librasoft Snc*
> www.LibrasoftSnc.it 
> www.ProgettoKuma.it 
> 0543 424612 
>   
>
> 2014-07-23 13:55 GMT+02:00 José Lorenzo :
>
>> I see I would re-do that at the controller level:
>>
>> class AuditLogger implements \Cake\Event\EventListener {
>>
>>   public function construct(AuthComponent $auth) {
>> $this->_auth = $auth;
>>   }
>>
>>   public function implementedEvents() {
>> return ['Model.afterSave' => 'logSave'];
>>   }
>>
>>   public function logSave($event, $entity, $options) {
>>  $logs->save(new Entity(['user_id' => $this->auth->user('id'), ...]));
>>   }
>> }
>>
>> And in your Controller:
>>
>> public function beforeFilter() {
>>
>>$this->Customers->eventManager()->attach(new AuditLogger($this->Auth)
>> );
>> }
>>
>> This way you keep your separation of concerns and have smaller and more 
>> testable classes that you can reuse :)
>>
>> On Wednesday, July 23, 2014 12:56:51 PM UTC+2, Stefano Zoffoli wrote:
>>>
>>> Yes of course:
>>> I have a CustomersTable, a UsersTable and a LogsTable. The LogsTable has 
>>> basically 4 fields: id, user_id, description, created.
>>>
>>> When an authenticated user saves a customer, i'd like to log this user 
>>> action. So, in CustomersTable I added a callback method like this:
>>>
>>> public function afterSave(Event $event, Entity $entity, array $options) {
>>>   $logs = TableRegistry::get('Logs');
>>>   $log = $logs->newEntity([
>>> 'user_id' => AuthComponent::user('id'),
>>>   'description' => 'Saved customer',
>>>   ]);
>>>   $logs->save($log);
>>> }
>>>
>>> But AuthComponent::user() is not static and gave me fatal error.
>>>
>>>
>>> --
>>>  Stefano Zoffoli
>>> *Resp. Sviluppo Software*
>>> 347 8180258
>>>
>>> *Librasoft Snc*
>>> www.LibrasoftSnc.it 
>>> www.ProgettoKuma.it 
>>> 0543 424612 
>>>   
>>>
>>> 2014-07-23 12:40 GMT+02:00 José Lorenzo :
>>>
 That's not possible anymore. We are currently investigating clean ways 
 of implementing this use case. May I ask why you need the session in the 
 table?


 On Wednesday, July 23, 2014 11:53:48 AM UTC+2, Stefano Zoffoli wrote:
>
> Hi,
> i'd like to read user auth infos in a Table Class (for example i want 
> to log which user has saved a given entity in a AfterSave callback 
> method).
>
> In cakephp 2 there was AuthComponent::user() static method, but in 
> cakephp 3 that method is not static anymore, and I can't find a simple 
> way 
> to access that information outside of Controllers.
>
> How can i do that?
> Thank you
>
> --
>  Stefano Zoffoli
> *Resp. Sviluppo Software*
> 347 8180258
>
> *Librasoft Snc*
> www.LibrasoftSnc.it 
> www.ProgettoKuma.it 
> 0543 424612 
>   
  -- 
 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 cake-php+unsubscr...@googlegroups.com.
 To post to this group, send email to cake-php@googlegroups.com.
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>  -- 
>> 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 cake-php+unsubscr...@googlegroups.com.
>> To post to this group, send email to cake-php@googlegroups.com.
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group a

file upload

2014-07-23 Thread Eric Yullu
created an application that is utlizing file upload, but when i click 
download button i get error, media.ctp not found

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3 - Accessing user session in models

2014-07-23 Thread Stefano Zoffoli
Thank you, this is a very nice solution and it worked perfectly!

How can I pass extra infos for Logs' description field? (i mean like a
custom prefix string and the entity displayfield's value?)


--
 Stefano Zoffoli
*Resp. Sviluppo Software*
347 8180258

*Librasoft Snc*
www.LibrasoftSnc.it 
www.ProgettoKuma.it 
0543 424612


2014-07-23 13:55 GMT+02:00 José Lorenzo :

> I see I would re-do that at the controller level:
>
> class AuditLogger implements \Cake\Event\EventListener {
>
>   public function construct(AuthComponent $auth) {
> $this->_auth = $auth;
>   }
>
>   public function implementedEvents() {
> return ['Model.afterSave' => 'logSave'];
>   }
>
>   public function logSave($event, $entity, $options) {
>  $logs->save(new Entity(['user_id' => $this->auth->user('id'), ...]));
>   }
> }
>
> And in your Controller:
>
> public function beforeFilter() {
>
>$this->Customers->eventManager()->attach(new AuditLogger($this->Auth));
> }
>
> This way you keep your separation of concerns and have smaller and more
> testable classes that you can reuse :)
>
> On Wednesday, July 23, 2014 12:56:51 PM UTC+2, Stefano Zoffoli wrote:
>>
>> Yes of course:
>> I have a CustomersTable, a UsersTable and a LogsTable. The LogsTable has
>> basically 4 fields: id, user_id, description, created.
>>
>> When an authenticated user saves a customer, i'd like to log this user
>> action. So, in CustomersTable I added a callback method like this:
>>
>> public function afterSave(Event $event, Entity $entity, array $options) {
>>   $logs = TableRegistry::get('Logs');
>>   $log = $logs->newEntity([
>> 'user_id' => AuthComponent::user('id'),
>>   'description' => 'Saved customer',
>>   ]);
>>   $logs->save($log);
>> }
>>
>> But AuthComponent::user() is not static and gave me fatal error.
>>
>>
>> --
>>  Stefano Zoffoli
>> *Resp. Sviluppo Software*
>> 347 8180258
>>
>> *Librasoft Snc*
>> www.LibrasoftSnc.it 
>> www.ProgettoKuma.it 
>> 0543 424612
>>
>>
>> 2014-07-23 12:40 GMT+02:00 José Lorenzo :
>>
>>> That's not possible anymore. We are currently investigating clean ways
>>> of implementing this use case. May I ask why you need the session in the
>>> table?
>>>
>>>
>>> On Wednesday, July 23, 2014 11:53:48 AM UTC+2, Stefano Zoffoli wrote:

 Hi,
 i'd like to read user auth infos in a Table Class (for example i want
 to log which user has saved a given entity in a AfterSave callback method).

 In cakephp 2 there was AuthComponent::user() static method, but in
 cakephp 3 that method is not static anymore, and I can't find a simple way
 to access that information outside of Controllers.

 How can i do that?
 Thank you

 --
  Stefano Zoffoli
 *Resp. Sviluppo Software*
 347 8180258

 *Librasoft Snc*
 www.LibrasoftSnc.it 
 www.ProgettoKuma.it 
 0543 424612

>>>  --
>>> 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 cake-php+unsubscr...@googlegroups.com.
>>> To post to this group, send email to cake-php@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/cake-php.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> 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 cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: 3.0: defaultConnectionName doesn't create correct connection

2014-07-23 Thread Joe Theuerkauf
Thanks for the suggestion. i'll read up on how to do that, but don't be 
surprised if i end up back here for some clarifications. But i'll give it a 
try before bugging the group again. :)
-joe


On Wednesday, 23 July 2014 02:34:29 UTC-4, José Lorenzo wrote:
>
> I would use plugins for organizing them
>
> On Wednesday, July 23, 2014 5:33:18 AM UTC+2, Joe Theuerkauf wrote:
>>
>> Okay, i fixated on this tonight & i think i got it to work. i put 
>> CaptchasTable back in App/Model/Table, and behold the class loads correctly 
>> (i forgot to adjust the namespace in the previous message).
>>
>> However, before i do a happy dance, i'd like to know if it's *POSSIBLE* 
>> to organize my Models into subdirectories as i was attempting to do:
>>
>> Model/Table/* : My project's main DB Table classes
>> Model/Table/Websites/* : Table classes from the Websites database, so 
>> they're not cluttering up my project's main tables... 
>> Model/Table//* : Similar if i need to connect to any other 
>> databases...
>>
>> Can this be done at all?
>>
>>
>>
>>
>>
>> On Tuesday, 22 July 2014 21:26:20 UTC-4, Joe Theuerkauf wrote:
>>>
>>> José:
>>>
>>> Sorry for the delayed response. i've been getting burned out (and burned 
>>> up with the weather), so i took a day to breathe.
>>>
>>> i called $this->Captchas->defaultConnectionName() from inside the 
>>> ContactsController:
>>>
>>> public function index() {
>>>  $this->loadModel('Captchas');
>>>  // PS: i'm using the LogTrait in the class...
>>>  $this->log('defaultConnectionName: ' . 
>>> $this->Captchas->defaultConnectionName());
>>>
>>> // ...
>>> }
>>>
>>>
>>> Output in error.log:
>>>
>>> 2014-07-23 01:16:55 Error: defaultConnectionName: default
>>>
>>>
>>> Obviously, not what i was expecting. And that's the value whether i have 
>>> CaptchasTable in the main Model/Table or in Model/Table/Website.
>>>
>>> If you have further suggestions, please let me know. i know 3.0 is alpha 
>>> so i do expect some breakage. But when the documentation is so brief & 
>>> doesn't seem to work, it can be frustrating.
>>> -joe
>>>
>>>
>>> On Monday, 21 July 2014 04:08:18 UTC-4, José Lorenzo wrote:

 what is returned if you call $this->Captchas->defaultConnectionName() ?

 On Sunday, July 20, 2014 6:29:33 PM UTC+2, Joe Theuerkauf wrote:
>
> i tried this topic before, but the only response was for an older 
> version of Cake...
>
> i'm following this documentation:
>
> http://book.cakephp.org/3.0/en/orm/table-objects.html#configuring-connections
>
> i'm trying to keep a few tables that would be application-agnostic in 
> a different database. i'm not trying to create associations as mentioned 
> in 
> #3463. i just need to query independent records from these tables.
>
> Here's what i have so far:
> // Config/app.php
> $config = [
> // ...
>   'Datasources' => [
> 'default' => [
>   // Connection to this DB works.
>   'database' => 'kodiak',
> ],
> 'websites' => [
>   // Connection is identical, except different 'database' value
>   'database' => 'websites',
> ]
>   ]
> // ...
> ];
>
> // Model/Table/Websites/CapchasTable.php
> class CaptchasTable extends Table {
> public static function defaultConnectionName () {
> return 'websites';
> }
> }
>
> // Controller/ContactsController.php
> public function index () {
> $this->loadModel('Captchas');
>
> $captcha = $this->Captchas->find('all', [
> 'conditions' => [],
> 'order' => 'RAND()',
> 'limit' => 1
> ]);
>
> // etc.
> }
>
> Here's the error output:
>
> SQLSTATE[42S02]: Base table or view not found: 1146 Table 
> *'kodiak.captchas'* doesn't exist
>
> Error: An Internal Error Has Occurred.
> Stack Trace
>
> ROOT\vendor\cakephp\cakephp\src\Database\Schema\Collection.php 
> line 113 → Cake\Database\Schema\Collection->_executeSql(string, array)
> ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 323 → 
> Cake\Database\Schema\Collection->describe(string)
> ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 127 → 
> Cake\ORM\Table->schema()
> ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 110 → 
> Cake\ORM\Query->addDefaultTypes(Cake\ORM\Table)
> ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 927 → 
> Cake\ORM\Query->__construct(Cake\Database\Connection, Cake\ORM\Table)
> ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 724 → 
> Cake\ORM\Table->query()
> APP/Controller\ContactsController.php line 36 → 
> Cake\ORM\Table->find(string, array)
> [internal function] → App\Controller\ContactsController->index()
> ROOT\vendor\cakephp\cakephp\src\Controller\Controller.php line 373 
> → ReflectionMethod->invokeArgs(App

Re: Cake 3 - Accessing user session in models

2014-07-23 Thread José Lorenzo
I see I would re-do that at the controller level:

class AuditLogger implements \Cake\Event\EventListener {

  public function construct(AuthComponent $auth) {
$this->_auth = $auth;
  }

  public function implementedEvents() {
return ['Model.afterSave' => 'logSave'];
  }

  public function logSave($event, $entity, $options) {
 $logs->save(new Entity(['user_id' => $this->auth->user('id'), ...]));
  }
}

And in your Controller:

public function beforeFilter() {
   
   $this->Customers->eventManager()->attach(new AuditLogger($this->Auth));
}

This way you keep your separation of concerns and have smaller and more 
testable classes that you can reuse :)

On Wednesday, July 23, 2014 12:56:51 PM UTC+2, Stefano Zoffoli wrote:
>
> Yes of course:
> I have a CustomersTable, a UsersTable and a LogsTable. The LogsTable has 
> basically 4 fields: id, user_id, description, created.
>
> When an authenticated user saves a customer, i'd like to log this user 
> action. So, in CustomersTable I added a callback method like this:
>
> public function afterSave(Event $event, Entity $entity, array $options) {
>   $logs = TableRegistry::get('Logs');
>   $log = $logs->newEntity([
> 'user_id' => AuthComponent::user('id'),
>   'description' => 'Saved customer',
>   ]);
>   $logs->save($log);
> }
>
> But AuthComponent::user() is not static and gave me fatal error.
>
>
> --
>  Stefano Zoffoli
> *Resp. Sviluppo Software*
> 347 8180258
>
> *Librasoft Snc*
> www.LibrasoftSnc.it 
> www.ProgettoKuma.it 
> 0543 424612 
>   
>
> 2014-07-23 12:40 GMT+02:00 José Lorenzo :
>
>> That's not possible anymore. We are currently investigating clean ways of 
>> implementing this use case. May I ask why you need the session in the table?
>>
>>
>> On Wednesday, July 23, 2014 11:53:48 AM UTC+2, Stefano Zoffoli wrote:
>>>
>>> Hi,
>>> i'd like to read user auth infos in a Table Class (for example i want to 
>>> log which user has saved a given entity in a AfterSave callback method).
>>>
>>> In cakephp 2 there was AuthComponent::user() static method, but in 
>>> cakephp 3 that method is not static anymore, and I can't find a simple way 
>>> to access that information outside of Controllers.
>>>
>>> How can i do that?
>>> Thank you
>>>
>>> --
>>>  Stefano Zoffoli
>>> *Resp. Sviluppo Software*
>>> 347 8180258
>>>
>>> *Librasoft Snc*
>>> www.LibrasoftSnc.it 
>>> www.ProgettoKuma.it 
>>> 0543 424612 
>>>   
>>  -- 
>> 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 cake-php+unsubscr...@googlegroups.com.
>> To post to this group, send email to cake-php@googlegroups.com.
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Finding if a event exists for a date

2014-07-23 Thread Jumy Elerossë
Stephen, thank you SO MUCH.

If anybody need to do something similar, this is the code:

if ($this->request->is('post')) {

$date = $this->request->data['BookedSurvey']['survey_date'];
$formattedDate = CakeTime::format(
"{$date['year']}-{$date['month']}-{$date['day']}", "%B %e, %Y"); //'Jul 23, 
2014'
print_r($formattedDate);
$isBooked = $this->Point->BookedSurvey->find('count', array(
'conditions' => CakeTime::dayAsSql($formattedDate, 'survey_date') // 
replace the date as you see fit, using Jul 23, 2014 as an example
));

echo "status";
print_r($isBooked);
print_r(date('m'));
print_r($this->request->data['BookedSurvey']['survey_date']);
if($isBooked > 0) {
echo "Already booked";
}


 
}


Again, many thanks!!!

On Wednesday, 23 July 2014 12:20:54 UTC+1, Stephen S wrote:
>
> Check out 
> http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::format
>
> You can pass your date and specify which date format you want (see 
> http://www.php.net/date), so something like
>
> $date = $this->request->data['BookedSurvey']['survey_date'];
> $formattedDate = 
> CakeTime::format("{$date['year']}-{$date['month']}-{$date['day']}", "%M %D, 
> %Y);
>
> I imagine there's a much better way to do this but I'm strapped for time 
> right now to think any harder, sorry! :)
>
>
> On 23 July 2014 12:11, Jumy Elerossë > 
> wrote:
>
>> Thank you very much Stephen. I only have a noob question... How can I 
>> tell to my Form to send the date in that format? 
>>
>> This is the code of the button that I have in my view:
>>
>> echo $this->Form->input('BookedSurvey.survey_date', array(
>> 'type'=>'date',
>> 'label' => '',
>> 'dateFormat' => 'DMY',
>> 'minYear' => date('Y'),
>> 'minMonth' => date('M'),
>> 'minDay' => date('D'),
>> 'div' => 'col col-md-9',
>> 'style' => 'margin: 15px 5px 5px 0px'
>> ));
>>
>> And when I do a 
>> print_r($this->request->data['BookedSurvey']['survey_date']);
>>
>> it send the date as 
>> Array ( [day] => 22 [month] => 01 [year] => 2014 )
>>
>>
>> It's the only thing that I can't make to work...
>>
>>
>> On Wednesday, 23 July 2014 11:35:42 UTC+1, Stephen S wrote:
>>
>>> Add the following above your controller class:
>>>
>>> App::uses('CakeTime', 'Utility');
>>>
>>>
>>> This will give you access to the CakeTime utility within your controller 
>>> ($this->Time references the helper which is for use in views) Something 
>>> like this should work I think, syntax may be a little off maybe, I haven't 
>>> had time to test.
>>>
>>> $isBooked = $this->Point->BookedSurvey->find('count', array(
 'conditions' => CakeTime::dayAsSql('Jul 23, 2014', 'survey_date') 
 // replace the date as you see fit, using Jul 23, 2014 as an example
 ));
>>>
>>>
>>>
>>> On 23 July 2014 11:21, Jumy Elerossë  wrote:
>>>
 Thank very much for your help.

 Yes, survey_date is using datetime, so the code should be something 
 like this?

 if ($this->request->is('post')) {
 
 
 $isBooked = $this->Point->BookedSurvey->find('count', 
 array(
 'conditions' => array(
 $this->Time->dayAsSql('BookedSurvey.survey_date') 
 => date('Y-m-d') // Maybe pass an actual specific date rather than just 
 today
 )
  ));
 
 echo "status";

 if($isBooked > 0) {
 echo "Already booked";
 }

  
 }


 Because it returns this error:

> Fatal Error
>
> Error: Call to a member function dayAsSql() on a non-object 
>

 On Wednesday, 23 July 2014 08:41:00 UTC+1, Stephen S wrote:

> You could try something like the following
>
> $isBooked = $this->Point->BookedSurvey->find('count', array(
> 'conditions' => array(
> 'BookedSurvey.survey_date' => date('Y-m-d') // Maybe pass an 
> actual specific date rather than just today
> )
> ));
>
> if($isBooked > 0) {
> echo "Already booked";
> }
>
> If your survey_date field is using datetime, you can check between 
> 00:00:00 and 23:59:59 using the TimeHelper::dayAsSql method here 
> http://book.cakephp.org/2.0/en/core-libraries/helpers/t
> ime.html#TimeHelper::dayAsSql
>
> I'd recommend using the time helper where applicable really, you'd 
> need to use CakeTime:: if you plan to do this in a controller or model.
>
> Hope this helps
>  
>
> On 23 July 2014 01:44, Jumy 

Re: Finding if a event exists for a date

2014-07-23 Thread Stephen S
Check out
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::format

You can pass your date and specify which date format you want (see
http://www.php.net/date), so something like

$date = $this->request->data['BookedSurvey']['survey_date'];
$formattedDate =
CakeTime::format("{$date['year']}-{$date['month']}-{$date['day']}", "%M %D,
%Y);

I imagine there's a much better way to do this but I'm strapped for time
right now to think any harder, sorry! :)


On 23 July 2014 12:11, Jumy Elerossë  wrote:

> Thank you very much Stephen. I only have a noob question... How can I tell
> to my Form to send the date in that format?
>
> This is the code of the button that I have in my view:
>
> echo $this->Form->input('BookedSurvey.survey_date', array(
> 'type'=>'date',
> 'label' => '',
> 'dateFormat' => 'DMY',
> 'minYear' => date('Y'),
> 'minMonth' => date('M'),
> 'minDay' => date('D'),
> 'div' => 'col col-md-9',
> 'style' => 'margin: 15px 5px 5px 0px'
> ));
>
> And when I do a
> print_r($this->request->data['BookedSurvey']['survey_date']);
>
> it send the date as
> Array ( [day] => 22 [month] => 01 [year] => 2014 )
>
>
> It's the only thing that I can't make to work...
>
>
> On Wednesday, 23 July 2014 11:35:42 UTC+1, Stephen S wrote:
>
>> Add the following above your controller class:
>>
>> App::uses('CakeTime', 'Utility');
>>
>>
>> This will give you access to the CakeTime utility within your controller
>> ($this->Time references the helper which is for use in views) Something
>> like this should work I think, syntax may be a little off maybe, I haven't
>> had time to test.
>>
>> $isBooked = $this->Point->BookedSurvey->find('count', array(
>>> 'conditions' => CakeTime::dayAsSql('Jul 23, 2014', 'survey_date') //
>>> replace the date as you see fit, using Jul 23, 2014 as an example
>>> ));
>>
>>
>>
>> On 23 July 2014 11:21, Jumy Elerossë  wrote:
>>
>>> Thank very much for your help.
>>>
>>> Yes, survey_date is using datetime, so the code should be something like
>>> this?
>>>
>>> if ($this->request->is('post')) {
>>>
>>>
>>> $isBooked = $this->Point->BookedSurvey->find('count', array(
>>> 'conditions' => array(
>>> $this->Time->dayAsSql('BookedSurvey.survey_date')
>>> => date('Y-m-d') // Maybe pass an actual specific date rather than just
>>> today
>>> )
>>> ));
>>>
>>> echo "status";
>>>
>>> if($isBooked > 0) {
>>> echo "Already booked";
>>> }
>>>
>>>
>>> }
>>>
>>>
>>> Because it returns this error:
>>>
 Fatal Error

 Error: Call to a member function dayAsSql() on a non-object

>>>
>>> On Wednesday, 23 July 2014 08:41:00 UTC+1, Stephen S wrote:
>>>
 You could try something like the following

 $isBooked = $this->Point->BookedSurvey->find('count', array(
 'conditions' => array(
 'BookedSurvey.survey_date' => date('Y-m-d') // Maybe pass an
 actual specific date rather than just today
 )
 ));

 if($isBooked > 0) {
 echo "Already booked";
 }

 If your survey_date field is using datetime, you can check between
 00:00:00 and 23:59:59 using the TimeHelper::dayAsSql method here
 http://book.cakephp.org/2.0/en/core-libraries/helpers/t
 ime.html#TimeHelper::dayAsSql

 I'd recommend using the time helper where applicable really, you'd need
 to use CakeTime:: if you plan to do this in a controller or model.

 Hope this helps


 On 23 July 2014 01:44, Jumy Elerossë  wrote:

>  Hello everyone.
>
> I'm struggling with a problem since a week ago, and this is driving me
> crazy.
>
> I'm doing a website for doing surveys in the forest. This is the
> schema:
>
> 1 place have several points, and for each point, an user can book a
> day for doing a survey. If that point has booked already a survey for that
> date, an error will be shown.
>
> I have the following tables: places, points, users and booked_surveys.
>
> The table booked_surveys has the following fields: id, survey_date,
> point_id and user_id
>
> Models: Place, Point, User, BookedSurvey
>
> Controllers: PlacesController, PointController, UserController,
> BookedSurveysController
>
> Views: add, edit, index and view for each one.
>
> When the user is viewing a point, there's a date selector in the view
> for booking:
>
> Book a date:
>
> Form->create('BoostCake', array(
> 'inputDefaults' => array(
> 'div' => 'form-group',
> 'label' => array(
> 

Re: Finding if a event exists for a date

2014-07-23 Thread Jumy Elerossë
Thank you very much Stephen. I only have a noob question... How can I tell 
to my Form to send the date in that format? 

This is the code of the button that I have in my view:

echo $this->Form->input('BookedSurvey.survey_date', array(
'type'=>'date',
'label' => '',
'dateFormat' => 'DMY',
'minYear' => date('Y'),
'minMonth' => date('M'),
'minDay' => date('D'),
'div' => 'col col-md-9',
'style' => 'margin: 15px 5px 5px 0px'
));

And when I do a 
print_r($this->request->data['BookedSurvey']['survey_date']);

it send the date as 
Array ( [day] => 22 [month] => 01 [year] => 2014 )


It's the only thing that I can't make to work...

On Wednesday, 23 July 2014 11:35:42 UTC+1, Stephen S wrote:
>
> Add the following above your controller class:
>
> App::uses('CakeTime', 'Utility');
>
>
> This will give you access to the CakeTime utility within your controller 
> ($this->Time references the helper which is for use in views) Something 
> like this should work I think, syntax may be a little off maybe, I haven't 
> had time to test.
>
> $isBooked = $this->Point->BookedSurvey->find('count', array(
>> 'conditions' => CakeTime::dayAsSql('Jul 23, 2014', 'survey_date') // 
>> replace the date as you see fit, using Jul 23, 2014 as an example
>> ));
>
>
>
> On 23 July 2014 11:21, Jumy Elerossë > 
> wrote:
>
>> Thank very much for your help.
>>
>> Yes, survey_date is using datetime, so the code should be something like 
>> this?
>>
>> if ($this->request->is('post')) {
>> 
>> 
>> $isBooked = $this->Point->BookedSurvey->find('count', array(
>> 'conditions' => array(
>> $this->Time->dayAsSql('BookedSurvey.survey_date') => 
>> date('Y-m-d') // Maybe pass an actual specific date rather than just today
>> )
>> ));
>> 
>> echo "status";
>>
>> if($isBooked > 0) {
>> echo "Already booked";
>> }
>>
>>  
>> }
>>
>>
>> Because it returns this error:
>>
>>> Fatal Error
>>>
>>> Error: Call to a member function dayAsSql() on a non-object 
>>>
>>
>> On Wednesday, 23 July 2014 08:41:00 UTC+1, Stephen S wrote:
>>
>>> You could try something like the following
>>>
>>> $isBooked = $this->Point->BookedSurvey->find('count', array(
>>> 'conditions' => array(
>>> 'BookedSurvey.survey_date' => date('Y-m-d') // Maybe pass an 
>>> actual specific date rather than just today
>>> )
>>> ));
>>>
>>> if($isBooked > 0) {
>>> echo "Already booked";
>>> }
>>>
>>> If your survey_date field is using datetime, you can check between 
>>> 00:00:00 and 23:59:59 using the TimeHelper::dayAsSql method here 
>>> http://book.cakephp.org/2.0/en/core-libraries/helpers/
>>> time.html#TimeHelper::dayAsSql
>>>
>>> I'd recommend using the time helper where applicable really, you'd need 
>>> to use CakeTime:: if you plan to do this in a controller or model.
>>>
>>> Hope this helps
>>>  
>>>
>>> On 23 July 2014 01:44, Jumy Elerossë  wrote:
>>>
  Hello everyone.

 I'm struggling with a problem since a week ago, and this is driving me 
 crazy.

 I'm doing a website for doing surveys in the forest. This is the schema:

 1 place have several points, and for each point, an user can book a day 
 for doing a survey. If that point has booked already a survey for that 
 date, an error will be shown.

 I have the following tables: places, points, users and booked_surveys.

 The table booked_surveys has the following fields: id, survey_date, 
 point_id and user_id

 Models: Place, Point, User, BookedSurvey

 Controllers: PlacesController, PointController, UserController, 
 BookedSurveysController

 Views: add, edit, index and view for each one.

 When the user is viewing a point, there's a date selector in the view 
 for booking:

 Book a date:
 
 Form->create('BoostCake', array(
 'inputDefaults' => array(
 'div' => 'form-group',
 'label' => array(
 'class' => 'col col-md-1 control-label'
 ),
 'wrapInput' => 'col col-md-9',
 'class' => 'form-control'
 ),
 'class' => 'form-horizontal'
 )); ?>
 
 Form->create('Point');
 

 echo $this->Form->input('BookedSurvey.survey_date', 
 array(
 'type'=>'date',
 'label' => '',
 'dateFormat' => 'YMD',
   

Re: Cake 3 - Accessing user session in models

2014-07-23 Thread Stefano Zoffoli
Yes of course:
I have a CustomersTable, a UsersTable and a LogsTable. The LogsTable has
basically 4 fields: id, user_id, description, created.

When an authenticated user saves a customer, i'd like to log this user
action. So, in CustomersTable I added a callback method like this:

public function afterSave(Event $event, Entity $entity, array $options) {
  $logs = TableRegistry::get('Logs');
  $log = $logs->newEntity([
'user_id' => AuthComponent::user('id'),
  'description' => 'Saved customer',
  ]);
  $logs->save($log);
}

But AuthComponent::user() is not static and gave me fatal error.


--
 Stefano Zoffoli
*Resp. Sviluppo Software*
347 8180258

*Librasoft Snc*
www.LibrasoftSnc.it 
www.ProgettoKuma.it 
0543 424612


2014-07-23 12:40 GMT+02:00 José Lorenzo :

> That's not possible anymore. We are currently investigating clean ways of
> implementing this use case. May I ask why you need the session in the table?
>
>
> On Wednesday, July 23, 2014 11:53:48 AM UTC+2, Stefano Zoffoli wrote:
>>
>> Hi,
>> i'd like to read user auth infos in a Table Class (for example i want to
>> log which user has saved a given entity in a AfterSave callback method).
>>
>> In cakephp 2 there was AuthComponent::user() static method, but in
>> cakephp 3 that method is not static anymore, and I can't find a simple way
>> to access that information outside of Controllers.
>>
>> How can i do that?
>> Thank you
>>
>> --
>>  Stefano Zoffoli
>> *Resp. Sviluppo Software*
>> 347 8180258
>>
>> *Librasoft Snc*
>> www.LibrasoftSnc.it 
>> www.ProgettoKuma.it 
>> 0543 424612
>>
>  --
> 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 cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Extending Core classes?

2014-07-23 Thread Dieter Gribnitz
Thanks,
That works prefectly

On Wednesday, July 23, 2014 12:44:15 PM UTC+2, José Lorenzo wrote:
>
> The easiest way is to extend the core class and make your controller use 
> it. In you case it is as easy as declaring $viewClass in your AppController:
>
>
> https://github.com/cakephp/cakephp/blob/3.0/src/Controller/Controller.php#L172
>
> just re-declare that string so it says App\View\View
>
>
>
> On Wednesday, July 23, 2014 11:06:33 AM UTC+2, Dieter Gribnitz wrote:
>>
>> Is it currently possible to extend core classes in 3.0?
>> The namespace convention works with most files but how would I go about 
>> doing something like this.
>>
>> I would like to modify a method in Cake\View\View
>> Here is what I have tried.
>>
>> I have copied the cakephp/src/View/View.php file to my src/View/View.php 
>> file.
>> Changed the namespace to:
>> namespace App\View;
>> Changed the class to:
>> class View extends \Cake\View
>>
>> This file does not seem to get called like the other Controllers, 
>> Helpers, Components etc...
>> Is it possible to override Files like these while leaving the core alone?
>> In 2.x you could do this with the Lib dir.
>>
>>
>>

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Extending Core classes?

2014-07-23 Thread José Lorenzo
The easiest way is to extend the core class and make your controller use 
it. In you case it is as easy as declaring $viewClass in your AppController:

https://github.com/cakephp/cakephp/blob/3.0/src/Controller/Controller.php#L172

just re-declare that string so it says App\View\View



On Wednesday, July 23, 2014 11:06:33 AM UTC+2, Dieter Gribnitz wrote:
>
> Is it currently possible to extend core classes in 3.0?
> The namespace convention works with most files but how would I go about 
> doing something like this.
>
> I would like to modify a method in Cake\View\View
> Here is what I have tried.
>
> I have copied the cakephp/src/View/View.php file to my src/View/View.php 
> file.
> Changed the namespace to:
> namespace App\View;
> Changed the class to:
> class View extends \Cake\View
>
> This file does not seem to get called like the other Controllers, Helpers, 
> Components etc...
> Is it possible to override Files like these while leaving the core alone?
> In 2.x you could do this with the Lib dir.
>
>
>

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cake 3 - Accessing user session in models

2014-07-23 Thread José Lorenzo
That's not possible anymore. We are currently investigating clean ways of 
implementing this use case. May I ask why you need the session in the table?

On Wednesday, July 23, 2014 11:53:48 AM UTC+2, Stefano Zoffoli wrote:
>
> Hi,
> i'd like to read user auth infos in a Table Class (for example i want to 
> log which user has saved a given entity in a AfterSave callback method).
>
> In cakephp 2 there was AuthComponent::user() static method, but in cakephp 
> 3 that method is not static anymore, and I can't find a simple way to 
> access that information outside of Controllers.
>
> How can i do that?
> Thank you
>
> --
>  Stefano Zoffoli
> *Resp. Sviluppo Software*
> 347 8180258
>
> *Librasoft Snc*
> www.LibrasoftSnc.it 
> www.ProgettoKuma.it 
> 0543 424612 
>   

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Extending Core classes?

2014-07-23 Thread Dieter Gribnitz
Is it currently possible to extend core classes in 3.0?
The namespace convention works with most files but how would I go about 
doing something like this.

I would like to modify a method in Cake\View\View
Here is what I have tried.

I have copied the cakephp/src/View/View.php file to my src/View/View.php 
file.
Changed the namespace to:
namespace App\View;
Changed the class to:
class View extends \Cake\View

This file does not seem to get called like the other Controllers, Helpers, 
Components etc...
Is it possible to override Files like these while leaving the core alone?
In 2.x you could do this with the Lib dir.


-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Finding if a event exists for a date

2014-07-23 Thread Stephen S
Add the following above your controller class:

App::uses('CakeTime', 'Utility');


This will give you access to the CakeTime utility within your controller
($this->Time references the helper which is for use in views) Something
like this should work I think, syntax may be a little off maybe, I haven't
had time to test.

$isBooked = $this->Point->BookedSurvey->find('count', array(
> 'conditions' => CakeTime::dayAsSql('Jul 23, 2014', 'survey_date') //
> replace the date as you see fit, using Jul 23, 2014 as an example
> ));



On 23 July 2014 11:21, Jumy Elerossë  wrote:

> Thank very much for your help.
>
> Yes, survey_date is using datetime, so the code should be something like
> this?
>
> if ($this->request->is('post')) {
>
>
> $isBooked = $this->Point->BookedSurvey->find('count', array(
> 'conditions' => array(
> $this->Time->dayAsSql('BookedSurvey.survey_date') =>
> date('Y-m-d') // Maybe pass an actual specific date rather than just today
> )
> ));
>
> echo "status";
>
> if($isBooked > 0) {
> echo "Already booked";
> }
>
>
> }
>
>
> Because it returns this error:
>
>> Fatal Error
>>
>> Error: Call to a member function dayAsSql() on a non-object
>>
>
> On Wednesday, 23 July 2014 08:41:00 UTC+1, Stephen S wrote:
>
>> You could try something like the following
>>
>> $isBooked = $this->Point->BookedSurvey->find('count', array(
>> 'conditions' => array(
>> 'BookedSurvey.survey_date' => date('Y-m-d') // Maybe pass an
>> actual specific date rather than just today
>> )
>> ));
>>
>> if($isBooked > 0) {
>> echo "Already booked";
>> }
>>
>> If your survey_date field is using datetime, you can check between
>> 00:00:00 and 23:59:59 using the TimeHelper::dayAsSql method here
>> http://book.cakephp.org/2.0/en/core-libraries/helpers/
>> time.html#TimeHelper::dayAsSql
>>
>> I'd recommend using the time helper where applicable really, you'd need
>> to use CakeTime:: if you plan to do this in a controller or model.
>>
>> Hope this helps
>>
>>
>> On 23 July 2014 01:44, Jumy Elerossë  wrote:
>>
>>> Hello everyone.
>>>
>>> I'm struggling with a problem since a week ago, and this is driving me
>>> crazy.
>>>
>>> I'm doing a website for doing surveys in the forest. This is the schema:
>>>
>>> 1 place have several points, and for each point, an user can book a day
>>> for doing a survey. If that point has booked already a survey for that
>>> date, an error will be shown.
>>>
>>> I have the following tables: places, points, users and booked_surveys.
>>>
>>> The table booked_surveys has the following fields: id, survey_date,
>>> point_id and user_id
>>>
>>> Models: Place, Point, User, BookedSurvey
>>>
>>> Controllers: PlacesController, PointController, UserController,
>>> BookedSurveysController
>>>
>>> Views: add, edit, index and view for each one.
>>>
>>> When the user is viewing a point, there's a date selector in the view
>>> for booking:
>>>
>>> Book a date:
>>>
>>> Form->create('BoostCake', array(
>>> 'inputDefaults' => array(
>>> 'div' => 'form-group',
>>> 'label' => array(
>>> 'class' => 'col col-md-1 control-label'
>>> ),
>>> 'wrapInput' => 'col col-md-9',
>>> 'class' => 'form-control'
>>> ),
>>> 'class' => 'form-horizontal'
>>> )); ?>
>>>
>>> Form->create('Point');
>>>
>>>
>>> echo $this->Form->input('BookedSurvey.survey_date',
>>> array(
>>> 'type'=>'date',
>>> 'label' => '',
>>> 'dateFormat' => 'YMD',
>>> 'minYear' => date('Y'),
>>> 'minMonth' => date('M'),
>>> 'minDay' => date('D'),
>>> 'div' => 'col col-md-9',
>>> 'style' => 'margin: 15px 5px 5px 0px'
>>> ));
>>>
>>> echo $this->Form->hidden('User.id', array(
>>> 'value' => $user_id)
>>> );
>>>
>>> ?>
>>>
>>>
>>>
>>> 
>>> Form->submit('Book survey', array(
>>> 'div' => 'col col-md-9',
>>> 'class' => 'btn btn-success btn-lg',
>>> 'style' => 'margin: 10px 5px 5px 10px'
>>> )); ?>
>>> 
>>>
>>> And then, the PointsControllers looks if there is someone that already
>>> booked for that day. And this is what is driving me crazy, because I'm not
>>> able to doing it to work. What I tried is this:
>>>
>>> if ($this->request->is('post')) {
>>>
>>>
>>>
>>> // Begin of comprobation
>>>
>>>  $booked_condition = $thi

Re: Finding if a event exists for a date

2014-07-23 Thread Jumy Elerossë
Thank very much for your help.

Yes, survey_date is using datetime, so the code should be something like 
this?

if ($this->request->is('post')) {


$isBooked = $this->Point->BookedSurvey->find('count', array(
'conditions' => array(
$this->Time->dayAsSql('BookedSurvey.survey_date') => 
date('Y-m-d') // Maybe pass an actual specific date rather than just today
)
));

echo "status";

if($isBooked > 0) {
echo "Already booked";
}

 
}


Because it returns this error:

> Fatal Error
>
> Error: Call to a member function dayAsSql() on a non-object 
>

On Wednesday, 23 July 2014 08:41:00 UTC+1, Stephen S wrote:
>
> You could try something like the following
>
> $isBooked = $this->Point->BookedSurvey->find('count', array(
> 'conditions' => array(
> 'BookedSurvey.survey_date' => date('Y-m-d') // Maybe pass an 
> actual specific date rather than just today
> )
> ));
>
> if($isBooked > 0) {
> echo "Already booked";
> }
>
> If your survey_date field is using datetime, you can check between 
> 00:00:00 and 23:59:59 using the TimeHelper::dayAsSql method here 
> http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::dayAsSql
>
> I'd recommend using the time helper where applicable really, you'd need to 
> use CakeTime:: if you plan to do this in a controller or model.
>
> Hope this helps
>
>
> On 23 July 2014 01:44, Jumy Elerossë > 
> wrote:
>
>> Hello everyone.
>>
>> I'm struggling with a problem since a week ago, and this is driving me 
>> crazy.
>>
>> I'm doing a website for doing surveys in the forest. This is the schema:
>>
>> 1 place have several points, and for each point, an user can book a day 
>> for doing a survey. If that point has booked already a survey for that 
>> date, an error will be shown.
>>
>> I have the following tables: places, points, users and booked_surveys.
>>
>> The table booked_surveys has the following fields: id, survey_date, 
>> point_id and user_id
>>
>> Models: Place, Point, User, BookedSurvey
>>
>> Controllers: PlacesController, PointController, UserController, 
>> BookedSurveysController
>>
>> Views: add, edit, index and view for each one.
>>
>> When the user is viewing a point, there's a date selector in the view for 
>> booking:
>>
>> Book a date:
>> 
>> Form->create('BoostCake', array(
>> 'inputDefaults' => array(
>> 'div' => 'form-group',
>> 'label' => array(
>> 'class' => 'col col-md-1 control-label'
>> ),
>> 'wrapInput' => 'col col-md-9',
>> 'class' => 'form-control'
>> ),
>> 'class' => 'form-horizontal'
>> )); ?>
>> 
>> Form->create('Point');
>> 
>>
>> echo $this->Form->input('BookedSurvey.survey_date', 
>> array(
>> 'type'=>'date',
>> 'label' => '',
>> 'dateFormat' => 'YMD',
>> 'minYear' => date('Y'),
>> 'minMonth' => date('M'),
>> 'minDay' => date('D'),
>> 'div' => 'col col-md-9',
>> 'style' => 'margin: 15px 5px 5px 0px'
>> ));
>>
>> echo $this->Form->hidden('User.id', array(
>> 'value' => $user_id)
>> );
>>
>> ?>
>>
>>
>>
>> 
>> Form->submit('Book survey', array(
>> 'div' => 'col col-md-9',
>> 'class' => 'btn btn-success btn-lg',
>> 'style' => 'margin: 10px 5px 5px 10px'
>> )); ?>
>> 
>>
>> And then, the PointsControllers looks if there is someone that already 
>> booked for that day. And this is what is driving me crazy, because I'm not 
>> able to doing it to work. What I tried is this:
>>
>> if ($this->request->is('post')) {
>> 
>> 
>> 
>> // Begin of comprobation
>> 
>>  $booked_condition = 
>> $this->Point->BookedSurvey->find('first', 
>>array('conditions'=>array(
>> 
>>  'DATE(BookedSurvey.survey_date)'=>'date()')));
>>
>> 
>> 
>> if ($booked_condition){
>> 
>> echo "Already booked"; 
>> }
>> 
>>
>> If anyone can PLEASE give some light to this... Please
>>  
>> -- 
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> --- 
>> You received this 

Cake 3 - Accessing user session in models

2014-07-23 Thread Stefano Zoffoli
Hi,
i'd like to read user auth infos in a Table Class (for example i want to
log which user has saved a given entity in a AfterSave callback method).

In cakephp 2 there was AuthComponent::user() static method, but in cakephp
3 that method is not static anymore, and I can't find a simple way to
access that information outside of Controllers.

How can i do that?
Thank you

--
 Stefano Zoffoli
*Resp. Sviluppo Software*
347 8180258

*Librasoft Snc*
www.LibrasoftSnc.it 
www.ProgettoKuma.it 
0543 424612

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Finding if a event exists for a date

2014-07-23 Thread Stephen S
You could try something like the following

$isBooked = $this->Point->BookedSurvey->find('count', array(
'conditions' => array(
'BookedSurvey.survey_date' => date('Y-m-d') // Maybe pass an actual
specific date rather than just today
)
));

if($isBooked > 0) {
echo "Already booked";
}

If your survey_date field is using datetime, you can check between 00:00:00
and 23:59:59 using the TimeHelper::dayAsSql method here
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::dayAsSql

I'd recommend using the time helper where applicable really, you'd need to
use CakeTime:: if you plan to do this in a controller or model.

Hope this helps


On 23 July 2014 01:44, Jumy Elerossë  wrote:

> Hello everyone.
>
> I'm struggling with a problem since a week ago, and this is driving me
> crazy.
>
> I'm doing a website for doing surveys in the forest. This is the schema:
>
> 1 place have several points, and for each point, an user can book a day
> for doing a survey. If that point has booked already a survey for that
> date, an error will be shown.
>
> I have the following tables: places, points, users and booked_surveys.
>
> The table booked_surveys has the following fields: id, survey_date,
> point_id and user_id
>
> Models: Place, Point, User, BookedSurvey
>
> Controllers: PlacesController, PointController, UserController,
> BookedSurveysController
>
> Views: add, edit, index and view for each one.
>
> When the user is viewing a point, there's a date selector in the view for
> booking:
>
> Book a date:
>
> Form->create('BoostCake', array(
> 'inputDefaults' => array(
> 'div' => 'form-group',
> 'label' => array(
> 'class' => 'col col-md-1 control-label'
> ),
> 'wrapInput' => 'col col-md-9',
> 'class' => 'form-control'
> ),
> 'class' => 'form-horizontal'
> )); ?>
>
> Form->create('Point');
>
>
> echo $this->Form->input('BookedSurvey.survey_date',
> array(
> 'type'=>'date',
> 'label' => '',
> 'dateFormat' => 'YMD',
> 'minYear' => date('Y'),
> 'minMonth' => date('M'),
> 'minDay' => date('D'),
> 'div' => 'col col-md-9',
> 'style' => 'margin: 15px 5px 5px 0px'
> ));
>
> echo $this->Form->hidden('User.id', array(
> 'value' => $user_id)
> );
>
> ?>
>
>
>
> 
> Form->submit('Book survey', array(
> 'div' => 'col col-md-9',
> 'class' => 'btn btn-success btn-lg',
> 'style' => 'margin: 10px 5px 5px 10px'
> )); ?>
> 
>
> And then, the PointsControllers looks if there is someone that already
> booked for that day. And this is what is driving me crazy, because I'm not
> able to doing it to work. What I tried is this:
>
> if ($this->request->is('post')) {
>
>
>
> // Begin of comprobation
>
>  $booked_condition = $this->Point->BookedSurvey->find('first',
>array('conditions'=>array(
>
>  'DATE(BookedSurvey.survey_date)'=>'date()')));
>
>
>
> if ($booked_condition){
>
> echo "Already booked";
> }
>
>
> If anyone can PLEASE give some light to this... Please
>
> --
> 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 cake-php+unsubscr...@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Kind Regards
 Stephen Speakman

-- 
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 cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.