3.0.x - defaultConnectionName not working in Plugin

2014-08-29 Thread Joe Theuerkauf
A while ago i created this thread: 
https://groups.google.com/forum/#!topic/cake-php/A5WHkiWCPd4

i was trying to hook up tables from a second database, using a different 
Datasource connection from *app.php*.

My default is kodiak, the other is websites. It's a general-use set of 
tables, like MimeTypes, Captcha questions, etc.

i got them working by putting them in together with Table/Entity classes 
from the kodiak database. However, i wanted to organize the class files 
for these Tables/Entities away from the other stuff, and the suggestion was 
to use a Plugin syntax.

Cut to tonight:

1. i used the cake command line to build models within my plugin:



*cake bake model Thook\Websites.Captchas --connection=websites*2. The files 
were built successfully within *Plugin/Thook/Websites/src*.

3. i added



*public static function defaultConnectionName() {return 'websites';}*to 
each of the Table classes i built, as i had done originally under 
*App/Model/Table*. i kinda feel this part should be added automatically if 
*--connection* is specified on the command line, but the point is moot.

4. i changed the line in my Controller that loads the Captchas Model (per 
http://book.cakephp.org/3.0/en/plugins.html#plugin-models at the end of 
that section):

*$captchasTable = TableRegistry::get('Thook/Websites.Captchas');*
i think that's the right syntax. If i try anything else similar to it, i 
get class-not-found errors.

Using that syntax, i get this:


*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 116 
→ Cake\Database\Schema\Collection-_reflect(string, string, array, 
Cake\Database\Schema\Table)
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 136 → 
Cake\ORM\Table-schema()
ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 119 → 
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 65 → 
Cake\ORM\Table-find(string)
(expanded...)
 $termsTable = TableRegistry::get('Terms');
 $captchasTable = TableRegistry::get('Thook/Websites.Captchas');

*Line 65: $captcha = $captchasTable-find('random')-first();*
So it brings me back to the same thing i was struggling with last time: it 
looks like the Table class gets loaded, but *defaultConnectionName* isn't 
doing its job to tell the App to use the 'websites' connection instead of 
'default' (kodiak). 

*find('random')* is in a Table extension class i added, and was also 
working until i started trying the Plugin approach for the Model.

Any help?

-- 
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: TranslateBehavior clarification

2014-08-29 Thread José Lorenzo
Please ope a ticket, I will look why it is not working when selecting only 
a few fields

On Thursday, August 28, 2014 10:22:56 PM UTC+2, Thomas von Hassel wrote:

 Hey

 Sorry to bump this, but is there a verdict from the powers that be ? ;)

 /thomas


 On 27 Aug 2014, at 16:53, José Lorenzo jose@gmail.com wrote:

 What happens if you try to select a few fields?

 On Wednesday, August 27, 2014 3:05:28 PM UTC+2, Thomas von Hassel wrote:

 Hey 

 In 2.x when you used translate, the table should not contain the field(s) 
 that you were translating. 

 In 3.x it’s not clear if this is still the case or if the table should 
 have the fields that you are trying to translate. For instance, when the 
 table has a translated field `name`, using find(‘list’)-select([‘id’, 
 ‘name’]) fails, but setting the locale and doing a find(‘all’) correctly 
 output the translated fields. 



 /thomas 



 -- 
 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.x - defaultConnectionName not working in Plugin

2014-08-29 Thread José Lorenzo
How did you load your plugin?

On Friday, August 29, 2014 9:32:48 AM UTC+2, Joe Theuerkauf wrote:

 A while ago i created this thread: 
 https://groups.google.com/forum/#!topic/cake-php/A5WHkiWCPd4

 i was trying to hook up tables from a second database, using a different 
 Datasource connection from *app.php*.

 My default is kodiak, the other is websites. It's a general-use set of 
 tables, like MimeTypes, Captcha questions, etc.

 i got them working by putting them in together with Table/Entity classes 
 from the kodiak database. However, i wanted to organize the class files 
 for these Tables/Entities away from the other stuff, and the suggestion was 
 to use a Plugin syntax.

 Cut to tonight:

 1. i used the cake command line to build models within my plugin:



 *cake bake model Thook\Websites.Captchas --connection=websites*2. The 
 files were built successfully within *Plugin/Thook/Websites/src*.

 3. i added



 *public static function defaultConnectionName() {return 'websites';}*to 
 each of the Table classes i built, as i had done originally under 
 *App/Model/Table*. i kinda feel this part should be added automatically 
 if *--connection* is specified on the command line, but the point is moot.

 4. i changed the line in my Controller that loads the Captchas Model (per 
 http://book.cakephp.org/3.0/en/plugins.html#plugin-models at the end of 
 that section):

 *$captchasTable = TableRegistry::get('Thook/Websites.Captchas');*
 i think that's the right syntax. If i try anything else similar to it, i 
 get class-not-found errors.

 Using that syntax, i get this:


 *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 
 116 → Cake\Database\Schema\Collection-_reflect(string, string, array, 
 Cake\Database\Schema\Table)
 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 136 → 
 Cake\ORM\Table-schema()
 ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 119 → 
 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 65 → 
 Cake\ORM\Table-find(string)
 (expanded...)
  $termsTable = TableRegistry::get('Terms');
  $captchasTable = TableRegistry::get('Thook/Websites.Captchas');

 *Line 65: $captcha = $captchasTable-find('random')-first();*
 So it brings me back to the same thing i was struggling with last time: it 
 looks like the Table class gets loaded, but *defaultConnectionName* isn't 
 doing its job to tell the App to use the 'websites' connection instead of 
 'default' (kodiak). 

 *find('random')* is in a Table extension class i added, and was also 
 working until i started trying the Plugin approach for the Model.

 Any help?



-- 
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.


Using multiple images with cakephp

2014-08-29 Thread Eloi Galles
Hi, 

I used https://github.com/josegonzalez/cakephp-upload

to make a system to upload multiple images.

All database is ok but when I try this code :

  public $actsAs = array(
  'Acl' = array('type' = 'requester', 'enabled' = false),
  'Translate',
  'Upload.Upload' = array(
'resume' = array(
  'fields' = array(
'dir' = 'resume_dir',
'type' = 'resume_type',
'size' = 'resume_size',
  )
),
'photo' = array(
  'fields' = array(
'dir' = 'photo_dir',
'type' = 'photo_type',
'size' = 'photo_size',
  ),
  'thumbnailSizes' = array(
'mini' = '400x350',
  ),
)
  )
  );

the request data in post returns me :

array(
'Post' = array(
'text' = '',
'id' = '2',
'users_id' = '2',
'post_types_id' = '2',
'owner_id' = '2',
'has_resource' = '1',
'photo_dir' = '/files/posts/photo/2/',
'photo' = array(
(int) 0 = array(
'name' = 'IMG_0213_2.jpg',
'type' = 'image/jpeg',
'tmp_name' = '/private/var/tmp/phpcrov66',
'error' = (int) 0,
'size' = (int) 0
),
(int) 1 = array(
'name' = 'IMG_0217.jpg',
'type' = 'image/jpeg',
'tmp_name' = '/private/var/tmp/phpX24eiH',
'error' = (int) 0,
'size' = (int) 0
)
),
'resource' = 
'[\/files\/posts\/photo\/2\/\/IMG_0213_2.jpg,\/files\/posts\/photo\/2\/\/IMG_0217.jpg]'
),
'PostType' = array(
'id' = '2'
)
)



But the images does not upload. Anyone knows why ? Thank you !



-- 
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.


Paginate from linked model

2014-08-29 Thread ajt
Hi ,

How do I display paginate data from a linked tables.
This is data from a Tutor table but I need data from the linked lesson 
table which has a student_id and that lesson table is linked to the student 
table.
So I have a tutor to lesson link in the model and a student to lesson link 
in the student model.

I wasnt clear about this from the docs
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html

 $this-paginate = array( 'limit' = 1 );
  $this-Paginator-settings = $this-paginate;
   
  
$mytutor = $this-Paginator-paginate('Tutor'); //lesson and student 
linked table data?
  
$this-set('mytutor', $mytutor);

-- 
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.


cakephp return data format inconsitency

2014-08-29 Thread Campise
I see data returned in different formats for different models and I don't 
know why.  

I have the following 2 models defined (I realize the associations don't 
make complete sense - I changed their context - but the issue exists 
nonetheless :) :

//
// RecipeItem Model
//
class RecipeItem extends AppModel
public $belongsTo = array(
'Recipe' = array(
'className' = 'Recipe',
'foreignKey' = 'recipe_id',
'conditions' = '',
'fields' = '',
'order' = ''
),
'Ingredient' = array(
'className' = 'Ingredient',
'foreignKey' = 'ingredient_id',
'conditions' = '',
'fields' = '',
'order' = ''
)
);
};

//
// Ingredient Model
//
class Ingredient extends AppModel {
public $belongsTo = array(
'IngredientType' = array(
'className' = 'IngredientType',
'foreignKey' = 'ingredient_type_id',
'conditions' = '',
'fields' = '',
'order' = ''
),
'User' = array(
'className' = 'User',
'foreignKey' = 'user_id',
'conditions' = '',
'fields' = '',
'order' = ''
)
);
};

//
// IngredientType
//
class IngredientType extends AppModel {
public $hasMany = array(
'Ingredient' = array(
'className' = 'Ingredient',
'foreignKey' = 'ingredient_type_id',
'dependent' = false,
'conditions' = '',
'fields' = '',
'order' = '',
'limit' = '',
'offset' = '',
'exclusive' = '',
'finderQuery' = '',
'counterQuery' = ''
)
);
};

I get my data returned in this format : 

RecipeItem: [
{
id: 16181,
recipe_id: 4150,
ingredient_id: 6866,
amount_in_ounces: 16.00,
created: 2014-08-06 21:34:50,
modified: 2014-08-06 21:34:50,
Ingredient: {
id: 6866,
ingredient_type_id: 2,
user_id: 1,
name: Cinnamon,
notes: Cinnamon spice notes,
favorite: 0,
created: 2014-07-20 23:13:08,
modified: 2014-07-20 23:13:08,
IngredientType: {
id: 2,
name: Spice
}
}
},
];

when I use Containable in my Controller :

$data = $this-Recipe-find( 'first',
array(
'contain'   = array(
'RecipeItem' = array('Ingredient' = 
array('IngredientType')),
),
'conditions' = array(
'Recipe.id' = $this-request['id'],
'Recipe.user_id' = $this-request['user_id']
)
)
);


But CakePHP returns the default format at times :

{
Ingredient: {
id: 6784,
ingredient_type_id: 5,
user_id: 1,
name: Cinnamon,
notes: Some notes...,
favorite: 0,
created: 2014-07-20 23:13:08,
modified: 2014-07-20 23:13:08
},
IngredientType: {
id: 5,
name: Allspice
},
User: {
id: 1,
username: ccampise,
password: 3eccc6ad7b84c40434740c782266ec3cced19133,
notes: null,
created: 2014-05-16 18:27:56,
modified: -00-00 00:00:00
}
},


when I use the same Containable notation :

$data = $this-Ingredient-find( 'first',
array(
'contain'   = array('IngredientType'),
)
);

I'm not sure I have a preference, but I do prefer to use *one* or the 
other, and not both for consistency in my models.

Any thoughts?  Thanks!

-- 
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.x - defaultConnectionName not working in Plugin

2014-08-29 Thread Joe Theuerkauf
i wasn't. My mistake. However, i guess there was more to the puzzle. Even 
after adding Plugin::loadAll() to bootstrap.php, it wasn't working.

i continued to tinker, finally creating a full-blown plugin (*cake bake 
plugin Thook/Websites*). Note the original post was just the Model commands 
- i hadn't created the plugin before hand.

i had to make some adjustments to namespaces and the composer.json path 
strings. It's writing ./plugins/... instead of ./Plugin where bake actually 
places the plugin's directory tree, and path separators are getting mixed 
up. If you want more detail on that, i'll create a dummy plugin  note the 
mix-ups. Yes, it's Windows... ;-)

Whatever i did this time, it's working. i've confirmed by pulling out all 
the old

i don't know if it's because i'm switching between Cake 3 on this project 
and Zend 1 at work, or what, but my brain is pudding. 

Any idea how to get my IDE (PhpStorm) to recognize the namespaces 
correctly, since the *src/* part of the path breaks up the PSR-0/4 
conformity? Just curious. The app functions

Now to work on hooking up the routes  controllers...

Congrats on getting to beta, by the way!
-joe



On Friday, 29 August 2014 04:00:35 UTC-4, José Lorenzo wrote:

 How did you load your plugin?

 On Friday, August 29, 2014 9:32:48 AM UTC+2, Joe Theuerkauf wrote:

 A while ago i created this thread: 
 https://groups.google.com/forum/#!topic/cake-php/A5WHkiWCPd4

 i was trying to hook up tables from a second database, using a different 
 Datasource connection from *app.php*.

 My default is kodiak, the other is websites. It's a general-use set 
 of tables, like MimeTypes, Captcha questions, etc.

 i got them working by putting them in together with Table/Entity classes 
 from the kodiak database. However, i wanted to organize the class files 
 for these Tables/Entities away from the other stuff, and the suggestion was 
 to use a Plugin syntax.

 Cut to tonight:

 1. i used the cake command line to build models within my plugin:



 *cake bake model Thook\Websites.Captchas --connection=websites*2. The 
 files were built successfully within *Plugin/Thook/Websites/src*.

 3. i added



 *public static function defaultConnectionName() {return 'websites';}*to 
 each of the Table classes i built, as i had done originally under 
 *App/Model/Table*. i kinda feel this part should be added automatically 
 if *--connection* is specified on the command line, but the point is 
 moot.

 4. i changed the line in my Controller that loads the Captchas Model (per 
 http://book.cakephp.org/3.0/en/plugins.html#plugin-models at the end of 
 that section):

 *$captchasTable = TableRegistry::get('Thook/Websites.Captchas');*
 i think that's the right syntax. If i try anything else similar to it, i 
 get class-not-found errors.

 Using that syntax, i get this:


 *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 
 116 → Cake\Database\Schema\Collection-_reflect(string, string, array, 
 Cake\Database\Schema\Table)
 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 136 → 
 Cake\ORM\Table-schema()
 ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 119 → 
 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 65 → 
 Cake\ORM\Table-find(string)
 (expanded...)
  $termsTable = TableRegistry::get('Terms');
  $captchasTable = TableRegistry::get('Thook/Websites.Captchas');

 *Line 65: $captcha = $captchasTable-find('random')-first();*
 So it brings me back to the same thing i was struggling with last time: 
 it looks like the Table class gets loaded, but *defaultConnectionName* 
 isn't doing its job to tell the App to use the 'websites' connection 
 instead of 'default' (kodiak). 

 *find('random')* is in a Table extension class i added, and was also 
 working until i started trying the Plugin approach for the Model.

 Any help?



-- 
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.


CakePHP 3 - How to send X-CSRF-Token header

2014-08-29 Thread Dr. Tarique Sani
Hi,

Can anyone share some example code on how to send the X-CSRF-Token header
 containing the CSRF Token as mentioned in
http://book.cakephp.org/3.0/en/core-libraries/components/csrf-component.html#csrf-protection-and-ajax-requests


Thanks

Tarique

-- 
=
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 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.