Sunday, August 31, 2014

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

Thanks, would really appreciate some code to look at. Please do post if you can when you get to a real computer.

Tarique




On Sat, Aug 30, 2014 at 6:11 PM, mark_story <mark.story@gmail.com> wrote:
I do this by adding a header with a jQuery beforeSend hook. I don't have an example handy as I am not at a real computer right now.

-mark

--
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+unsubscribe@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.



--
=============================================================
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+unsubscribe@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: BelongsToMany model

i just changed the key to leerlingen_id and it works. Just a workaround but i dont want to screw with the core files. CakePHP is supposed to be easy to use that means that if i follow the tutorial it should do what is says.

Op zondag 31 augustus 2014 21:35:59 UTC+2 schreef José Lorenzo:
You also have control over what is the foreignKey to use when creating the association. Refer the the ORM docs to customize what the query builder is doing.

On Sunday, August 31, 2014 7:30:36 PM UTC+2, Abdelmajid el Ibrahimi wrote:
But even if i take that out it still says the same.

Op zondag 31 augustus 2014 11:45:25 UTC+2 schreef José Lorenzo:
There is no "public $primaryKey" in CakePHP 3.0

You may use $this->primaryKey($myKey) inside the initialize() method

On Sunday, August 31, 2014 3:54:56 AM UTC+2, Abdelmajid el Ibrahimi wrote:
I have made two tables leerlingen and verzorgers. Because these have a many to many relation i added a table leerlingen_verzorgers.
I have added 3 model tables:

class VerzorgersTable extends Table {
    public $primaryKey = 'verzorger_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Leerlingen',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenTable extends Table {
    public $primaryKey = 'leerling_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Verzorgers',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenVerzorgersTable extends Table {
    public function initialize(array $config) {
        $this->belongsTo('Leerlingen');
        $this->belongsTo('Verzorgers');
    }
}

Now when i want to retrieve a verzorger with all the leerlingen i get an error that he doesn't know the leerlingen_id this is right because it is leerling_id. But with the verzorgers table he does use the right id and asks for the verzorger_id.

My relation table looks like this:
leerlingen_verzorgers
--------------------------
id
leerling_id
verzorgers_id
jaar

The generated query looks like this:

'SELECT Leerlingen.leerling_id AS `Leerlingen__leerling_id`, Leerlingen.voornaam AS `Leerlingen__voornaam`, Leerlingen.achternaam AS `Leerlingen__achternaam`, Leerlingen.geboortedatum AS `Leerlingen__geboortedatum`, Leerlingen.geslacht AS `Leerlingen__geslacht`, Leerlingen.email AS `Leerlingen__email`, Leerlingen.opmerking AS `Leerlingen__opmerking`, LeerlingenVerzorgers.id AS `LeerlingenVerzorgers__id`, LeerlingenVerzorgers.leerling_id AS `LeerlingenVerzorgers__leerling_id`, LeerlingenVerzorgers.verzorger_id AS `LeerlingenVerzorgers__verzorger_id`, LeerlingenVerzorgers.jaar AS `LeerlingenVerzorgers__jaar` FROM leerlingen AS Leerlingen INNER JOIN leerlingen_verzorgers LeerlingenVerzorgers ON (LeerlingenVerzorgers.verzorger_id IN (:c0) AND Leerlingen.leerling_id = (LeerlingenVerzorgers.leerlingen_id))

so first he uses the right leerling_id but at the end he uses leerlingen_id. Anyone knows what i did wrong?

--
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+unsubscribe@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: BelongsToMany model

You also have control over what is the foreignKey to use when creating the association. Refer the the ORM docs to customize what the query builder is doing.

On Sunday, August 31, 2014 7:30:36 PM UTC+2, Abdelmajid el Ibrahimi wrote:
But even if i take that out it still says the same.

Op zondag 31 augustus 2014 11:45:25 UTC+2 schreef José Lorenzo:
There is no "public $primaryKey" in CakePHP 3.0

You may use $this->primaryKey($myKey) inside the initialize() method

On Sunday, August 31, 2014 3:54:56 AM UTC+2, Abdelmajid el Ibrahimi wrote:
I have made two tables leerlingen and verzorgers. Because these have a many to many relation i added a table leerlingen_verzorgers.
I have added 3 model tables:

class VerzorgersTable extends Table {
    public $primaryKey = 'verzorger_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Leerlingen',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenTable extends Table {
    public $primaryKey = 'leerling_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Verzorgers',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenVerzorgersTable extends Table {
    public function initialize(array $config) {
        $this->belongsTo('Leerlingen');
        $this->belongsTo('Verzorgers');
    }
}

Now when i want to retrieve a verzorger with all the leerlingen i get an error that he doesn't know the leerlingen_id this is right because it is leerling_id. But with the verzorgers table he does use the right id and asks for the verzorger_id.

My relation table looks like this:
leerlingen_verzorgers
--------------------------
id
leerling_id
verzorgers_id
jaar

The generated query looks like this:

'SELECT Leerlingen.leerling_id AS `Leerlingen__leerling_id`, Leerlingen.voornaam AS `Leerlingen__voornaam`, Leerlingen.achternaam AS `Leerlingen__achternaam`, Leerlingen.geboortedatum AS `Leerlingen__geboortedatum`, Leerlingen.geslacht AS `Leerlingen__geslacht`, Leerlingen.email AS `Leerlingen__email`, Leerlingen.opmerking AS `Leerlingen__opmerking`, LeerlingenVerzorgers.id AS `LeerlingenVerzorgers__id`, LeerlingenVerzorgers.leerling_id AS `LeerlingenVerzorgers__leerling_id`, LeerlingenVerzorgers.verzorger_id AS `LeerlingenVerzorgers__verzorger_id`, LeerlingenVerzorgers.jaar AS `LeerlingenVerzorgers__jaar` FROM leerlingen AS Leerlingen INNER JOIN leerlingen_verzorgers LeerlingenVerzorgers ON (LeerlingenVerzorgers.verzorger_id IN (:c0) AND Leerlingen.leerling_id = (LeerlingenVerzorgers.leerlingen_id))

so first he uses the right leerling_id but at the end he uses leerlingen_id. Anyone knows what i did wrong?

--
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+unsubscribe@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 Possible to remove column?

You may also want to try the migrations plugin:

https://github.com/cakephp/migrations

On Sunday, August 31, 2014 8:24:21 PM UTC+2, Dieter Gribnitz wrote:
Nevermind, I got it working.
Pretty obvious.
Just tried removeColumn(...) and it works.
You might consider mentioning it in the documentation after the addColumn section.

--
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+unsubscribe@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 Possible to remove column?

Nevermind, I got it working.
Pretty obvious.
Just tried removeColumn(...) and it works.
You might consider mentioning it in the documentation after the addColumn section.

--
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+unsubscribe@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.

3.0 Possible to remove column?

I can't seem to find any method to remove columns via Database/Schema/Table.
Is there a way to do this?
I am creating an uninstaller for a plugin and this would come in handy.
If not I will just use a normal sql query instead.

--
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+unsubscribe@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: BelongsToMany model

But even if i take that out it still says the same.

Op zondag 31 augustus 2014 11:45:25 UTC+2 schreef José Lorenzo:
There is no "public $primaryKey" in CakePHP 3.0

You may use $this->primaryKey($myKey) inside the initialize() method

On Sunday, August 31, 2014 3:54:56 AM UTC+2, Abdelmajid el Ibrahimi wrote:
I have made two tables leerlingen and verzorgers. Because these have a many to many relation i added a table leerlingen_verzorgers.
I have added 3 model tables:

class VerzorgersTable extends Table {
    public $primaryKey = 'verzorger_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Leerlingen',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenTable extends Table {
    public $primaryKey = 'leerling_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Verzorgers',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenVerzorgersTable extends Table {
    public function initialize(array $config) {
        $this->belongsTo('Leerlingen');
        $this->belongsTo('Verzorgers');
    }
}

Now when i want to retrieve a verzorger with all the leerlingen i get an error that he doesn't know the leerlingen_id this is right because it is leerling_id. But with the verzorgers table he does use the right id and asks for the verzorger_id.

My relation table looks like this:
leerlingen_verzorgers
--------------------------
id
leerling_id
verzorgers_id
jaar

The generated query looks like this:

'SELECT Leerlingen.leerling_id AS `Leerlingen__leerling_id`, Leerlingen.voornaam AS `Leerlingen__voornaam`, Leerlingen.achternaam AS `Leerlingen__achternaam`, Leerlingen.geboortedatum AS `Leerlingen__geboortedatum`, Leerlingen.geslacht AS `Leerlingen__geslacht`, Leerlingen.email AS `Leerlingen__email`, Leerlingen.opmerking AS `Leerlingen__opmerking`, LeerlingenVerzorgers.id AS `LeerlingenVerzorgers__id`, LeerlingenVerzorgers.leerling_id AS `LeerlingenVerzorgers__leerling_id`, LeerlingenVerzorgers.verzorger_id AS `LeerlingenVerzorgers__verzorger_id`, LeerlingenVerzorgers.jaar AS `LeerlingenVerzorgers__jaar` FROM leerlingen AS Leerlingen INNER JOIN leerlingen_verzorgers LeerlingenVerzorgers ON (LeerlingenVerzorgers.verzorger_id IN (:c0) AND Leerlingen.leerling_id = (LeerlingenVerzorgers.leerlingen_id))

so first he uses the right leerling_id but at the end he uses leerlingen_id. Anyone knows what i did wrong?

--
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+unsubscribe@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 Plugin Installation DB schema setup

Thanks,
That is exactly what I was looking for.

On Sunday, August 31, 2014 11:43:57 AM UTC+2, José Lorenzo wrote:
For "packaging" and versioning the database I would suggest using the migrations plugin:

http://github.com/cakephp/migrations

Composer has post install scripts you can setup. But it would be better to let the user run the migrations on their own.


On Sunday, August 31, 2014 10:46:49 AM UTC+2, Dieter Gribnitz wrote:
Hi,
I had a look around on the web and could not find any documentation surrounding the setup of plugins.
If there are any documentation surrounding plugin packaging I would greatly appreciate someone pointing me in the right direction.
I have managed to set up a simple installer that loads the plugin via a git repo similar to debug-kit.

Here are the basic questions I have regarding this:
Is there currently any way to export a part of your DB schema in 3.0 and package it in the config of the plugin on the git repo?
Is there any way to alter tables with version changes?
Are there any scripts that get triggered to run post plugin install or update?

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+unsubscribe@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

Hey, that's great news!

I was going  to bake a plugin application this evening to see if I could reproduce your problem. I'm glad you could figure it out!

On Sunday, August 31, 2014 5:42:21 PM UTC+2, Joe Theuerkauf wrote:
Okay, i think i'm finally on the right track.

As i noted, going to [host]/captchas was giving a Controller-not-found error. i realize now it's because the route connecting '/captchas' required an action to match... Oops. After trying the full URL that the Captcha validator uses, i got a JSON response, but it was a 500 error, the database was still trying to find the table kodiak.captchas. Changed TableRegistry::get('Captchas') to TableRegistry::get('Thook/Websites.Captchas') and got a JSON response i expected.

i know most of this is considered basic stuff, so i appreciate the patience in trying to help me. At least i'm trying to figure it out on my own while i wait for help, right? :)
-joe



On Saturday, 30 August 2014 12:28:50 UTC-4, Joe Theuerkauf wrote:
@José: Here's what i'm using that works on the Contact page where i need to load the Captchas model to grab a question:

Works:
Plugin::loadAll([
    [
        'Thook/Websites' => ['routes' => true]
    ]
]);

Also works:
Plugin::load('Thook/Websites');

Doesn't work:
Plugin::load('Thook/Websites', ['routes' => true]);

Results in ([...] shortening the path to relevant stuff):
Warning (2): include([...]/Plugin/Thook\Websites\config\routes.php): failed to open stream: No such file or directory [ROOT\vendor\cakephp\cakephp\src\Core\Plugin.php, line 346]
Warning (2): include() [function.include]: Failed opening '[...]/Plugin/Thook\Websites\config\routes.php' for inclusion (include_path='.;C:\WebServer\php5\pear\pear') [ROOT\vendor\cakephp\cakephp\src\Core\Plugin.php, line 346]

However, the file path it's trying to include IS valid (aside from directory separators).

---

@mark
In my primary routes file:

Router::scope('/', function(RouteBuilder $routes) {
    // Some routes linking to main App Controllers, working.

    // Per your response:
    $routes->connect('/captchas/:action/*', [
        'plugin' => 'Thook/Websites',
        'controller' => 'captchas' // Also tried 'Captchas', but the other routes' controller values are lower-case & working
    ]);

    $routes->connect(':controller', ['action' => 'index], ['routeClass' => 'InflectedRoute']);

    $routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);

    // This will be dropped for production. ;)
    $routes->connect('/', [
        'controller' => 'pages',
        'action'     => 'display',
        'home'
    ]);
});

Still receiving Controller not found when i go directly to [host]/captchas:

Missing Controller

Error: CaptchasController could not be found.

Error: Create the class CaptchasController below in file: App\Controller\CaptchasController.php

<?php  namespace App\Controller;    use App\Controller\AppController;    class CaptchasController extends AppController {    }  

Thanks a lot guys, for taking a look at this with me.
-joe


On Saturday, 30 August 2014 08:33:57 UTC-4, mark_story wrote:
If Router::plugin() isn't getting you the routes you want, you can combine scope() and connect () to create the exact routes you want. Just keep in mind that all the routing data that doesn't change should be in the defaults list. For example

$routes->connect('/captchas/:action/*', ['plugin' => 'Thook/Websites','controller' => 'Captchas']);

Would let you connect all the actions on the CaptchasController in your plugin.

-mark


--
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+unsubscribe@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

Okay, i think i'm finally on the right track.

As i noted, going to [host]/captchas was giving a Controller-not-found error. i realize now it's because the route connecting '/captchas' required an action to match... Oops. After trying the full URL that the Captcha validator uses, i got a JSON response, but it was a 500 error, the database was still trying to find the table kodiak.captchas. Changed TableRegistry::get('Captchas') to TableRegistry::get('Thook/Websites.Captchas') and got a JSON response i expected.

i know most of this is considered basic stuff, so i appreciate the patience in trying to help me. At least i'm trying to figure it out on my own while i wait for help, right? :)
-joe



On Saturday, 30 August 2014 12:28:50 UTC-4, Joe Theuerkauf wrote:
@José: Here's what i'm using that works on the Contact page where i need to load the Captchas model to grab a question:

Works:
Plugin::loadAll([
    [
        'Thook/Websites' => ['routes' => true]
    ]
]);

Also works:
Plugin::load('Thook/Websites');

Doesn't work:
Plugin::load('Thook/Websites', ['routes' => true]);

Results in ([...] shortening the path to relevant stuff):
Warning (2): include([...]/Plugin/Thook\Websites\config\routes.php): failed to open stream: No such file or directory [ROOT\vendor\cakephp\cakephp\src\Core\Plugin.php, line 346]
Warning (2): include() [function.include]: Failed opening '[...]/Plugin/Thook\Websites\config\routes.php' for inclusion (include_path='.;C:\WebServer\php5\pear\pear') [ROOT\vendor\cakephp\cakephp\src\Core\Plugin.php, line 346]

However, the file path it's trying to include IS valid (aside from directory separators).

---

@mark
In my primary routes file:

Router::scope('/', function(RouteBuilder $routes) {
    // Some routes linking to main App Controllers, working.

    // Per your response:
    $routes->connect('/captchas/:action/*', [
        'plugin' => 'Thook/Websites',
        'controller' => 'captchas' // Also tried 'Captchas', but the other routes' controller values are lower-case & working
    ]);

    $routes->connect(':controller', ['action' => 'index], ['routeClass' => 'InflectedRoute']);

    $routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);

    // This will be dropped for production. ;)
    $routes->connect('/', [
        'controller' => 'pages',
        'action'     => 'display',
        'home'
    ]);
});

Still receiving Controller not found when i go directly to [host]/captchas:

Missing Controller

Error: CaptchasController could not be found.

Error: Create the class CaptchasController below in file: App\Controller\CaptchasController.php

<?php  namespace App\Controller;    use App\Controller\AppController;    class CaptchasController extends AppController {    }  

Thanks a lot guys, for taking a look at this with me.
-joe


On Saturday, 30 August 2014 08:33:57 UTC-4, mark_story wrote:
If Router::plugin() isn't getting you the routes you want, you can combine scope() and connect () to create the exact routes you want. Just keep in mind that all the routing data that doesn't change should be in the defaults list. For example

$routes->connect('/captchas/:action/*', ['plugin' => 'Thook/Websites','controller' => 'Captchas']);

Would let you connect all the actions on the CaptchasController in your plugin.

-mark


--
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+unsubscribe@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: find all on complex model

Hi Stephen,
Yes your example was a great effort and I solved the problem. The issue is that I didnt add the fields argument in so this kept giving me undefined errors.
I dont think your code will work as you dont specify fields.
Your models are setup like mine s that was really well done.

Also I need a find all as find first returns only 1 row.



      $this->Lesson->recursive = -1;
    
            $options['joins'] = array(
               array('table' => 'lessons_students',
                'alias' => 'LessonsStudent',
                'type' => 'LEFT',
                'conditions' => array(
                'Lesson.id = LessonsStudent.lesson_id',
                 )
                 ),
               
                array('table' => 'students',
                'alias' => 'Student',
                'type' => 'LEFT',
                'conditions' => array(
                'LessonsStudent.student_id=Student.id',
                 )
                 ),
                       
            );
           
   
        
       
    
      $options['fields'] = array('Student.*','Lesson.*','LessonsStudent.*');
       
             $options['conditions'] = array('Lesson.tutor_id'  => 2);
           
           
   $student=$this->set( 'student',$this->Lesson->find('all', $options));

--
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+unsubscribe@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: find all on complex model

There are plenty of complete examples here:





On 31 Aug 2014, at 10:06, ajt <jagguy999@gmail.com> wrote:

I tried this and as expected it doesnt work and it cant work because HABTM is a different case.
THis has to be the hardest framework to just get data to display from tables. There just is no docs for a complete example.

  $student=  $this->Lesson->find('all', array('contain' => array( 'Student' , 'Tutor')));   

--
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+unsubscribe@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: BelongsToMany model

There is no "public $primaryKey" in CakePHP 3.0

You may use $this->primaryKey($myKey) inside the initialize() method

On Sunday, August 31, 2014 3:54:56 AM UTC+2, Abdelmajid el Ibrahimi wrote:
I have made two tables leerlingen and verzorgers. Because these have a many to many relation i added a table leerlingen_verzorgers.
I have added 3 model tables:

class VerzorgersTable extends Table {
    public $primaryKey = 'verzorger_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Leerlingen',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenTable extends Table {
    public $primaryKey = 'leerling_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Verzorgers',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenVerzorgersTable extends Table {
    public function initialize(array $config) {
        $this->belongsTo('Leerlingen');
        $this->belongsTo('Verzorgers');
    }
}

Now when i want to retrieve a verzorger with all the leerlingen i get an error that he doesn't know the leerlingen_id this is right because it is leerling_id. But with the verzorgers table he does use the right id and asks for the verzorger_id.

My relation table looks like this:
leerlingen_verzorgers
--------------------------
id
leerling_id
verzorgers_id
jaar

The generated query looks like this:

'SELECT Leerlingen.leerling_id AS `Leerlingen__leerling_id`, Leerlingen.voornaam AS `Leerlingen__voornaam`, Leerlingen.achternaam AS `Leerlingen__achternaam`, Leerlingen.geboortedatum AS `Leerlingen__geboortedatum`, Leerlingen.geslacht AS `Leerlingen__geslacht`, Leerlingen.email AS `Leerlingen__email`, Leerlingen.opmerking AS `Leerlingen__opmerking`, LeerlingenVerzorgers.id AS `LeerlingenVerzorgers__id`, LeerlingenVerzorgers.leerling_id AS `LeerlingenVerzorgers__leerling_id`, LeerlingenVerzorgers.verzorger_id AS `LeerlingenVerzorgers__verzorger_id`, LeerlingenVerzorgers.jaar AS `LeerlingenVerzorgers__jaar` FROM leerlingen AS Leerlingen INNER JOIN leerlingen_verzorgers LeerlingenVerzorgers ON (LeerlingenVerzorgers.verzorger_id IN (:c0) AND Leerlingen.leerling_id = (LeerlingenVerzorgers.leerlingen_id))

so first he uses the right leerling_id but at the end he uses leerlingen_id. Anyone knows what i did wrong?

--
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+unsubscribe@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 Plugin Installation DB schema setup

For "packaging" and versioning the database I would suggest using the migrations plugin:

http://github.com/cakephp/migrations

Composer has post install scripts you can setup. But it would be better to let the user run the migrations on their own.


On Sunday, August 31, 2014 10:46:49 AM UTC+2, Dieter Gribnitz wrote:
Hi,
I had a look around on the web and could not find any documentation surrounding the setup of plugins.
If there are any documentation surrounding plugin packaging I would greatly appreciate someone pointing me in the right direction.
I have managed to set up a simple installer that loads the plugin via a git repo similar to debug-kit.

Here are the basic questions I have regarding this:
Is there currently any way to export a part of your DB schema in 3.0 and package it in the config of the plugin on the git repo?
Is there any way to alter tables with version changes?
Are there any scripts that get triggered to run post plugin install or update?

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+unsubscribe@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.

3.0 Plugin Installation DB schema setup

Hi,
I had a look around on the web and could not find any documentation surrounding the setup of plugins.
If there are any documentation surrounding plugin packaging I would greatly appreciate someone pointing me in the right direction.
I have managed to set up a simple installer that loads the plugin via a git repo similar to debug-kit.

Here are the basic questions I have regarding this:
Is there currently any way to export a part of your DB schema in 3.0 and package it in the config of the plugin on the git repo?
Is there any way to alter tables with version changes?
Are there any scripts that get triggered to run post plugin install or update?

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+unsubscribe@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: find all on complex model

Again if this isn't working it's likely your tables or associations are wrong, can you provide a pastie.


On 31 August 2014 09:06, ajt <jagguy999@gmail.com> wrote:
I tried this and as expected it doesnt work and it cant work because HABTM is a different case.
THis has to be the hardest framework to just get data to display from tables. There just is no docs for a complete example.

  $student=  $this->Lesson->find('all', array('contain' => array( 'Student' , 'Tutor')));   

--
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+unsubscribe@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+unsubscribe@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: find all on complex model

I tried this and as expected it doesnt work and it cant work because HABTM is a different case.
THis has to be the hardest framework to just get data to display from tables. There just is no docs for a complete example.

  $student=  $this->Lesson->find('all', array('contain' => array( 'Student' , 'Tutor')));   

--
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+unsubscribe@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: find all on complex model

You haven't provided any code other than a straight forward find query, we're likely to point you to book when this is the case, we need your code to help you also (like when I asked to see your associations).

Here's an example based on the models and desired relationships you mentioned, this works for me but it assumes you've named your tables correctly like such:

lessons
id | tutor_id | ...
lesson_students
id | lesson_id | student_id
tutors
id | ...
students
id | ...


It's much more simple to use contain over joins and hopefully you can see why.

Also notice the 'with' part on the HABTM joins, writing this tells the association which model to use to join the tables, you can leave this blank and it will create a model on the fly. See more in the HABTM docs on this.

Specifying one in advance this way allows you to access the join model easily and write methods within it, it's not required.


On 31 August 2014 01:05, ajt <jagguy999@gmail.com> wrote:
No this is not what you do as the Student has a HABTM relationship and I am told to do joins.

Also when saying adding something I NEED the code as please dont  assume by adding containable I know what your talking about or the docs explain things.

I dont understand why simply getting information from 4 tables is just so complicated and where is the complete examples of this?





--
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+unsubscribe@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+unsubscribe@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.

Saturday, August 30, 2014

BelongsToMany model

I have made two tables leerlingen and verzorgers. Because these have a many to many relation i added a table leerlingen_verzorgers.
I have added 3 model tables:

class VerzorgersTable extends Table {
    public $primaryKey = 'verzorger_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Leerlingen',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenTable extends Table {
    public $primaryKey = 'leerling_id';
   
    public function initialize(array $config) {
        $this->belongsToMany('Verzorgers',
            ['through' => 'LeerlingenVerzorgers',]);
        $this->addBehavior('Timestamp');
    }
}

class LeerlingenVerzorgersTable extends Table {
    public function initialize(array $config) {
        $this->belongsTo('Leerlingen');
        $this->belongsTo('Verzorgers');
    }
}

Now when i want to retrieve a verzorger with all the leerlingen i get an error that he doesn't know the leerlingen_id this is right because it is leerling_id. But with the verzorgers table he does use the right id and asks for the verzorger_id.

My relation table looks like this:
leerlingen_verzorgers
--------------------------
id
leerling_id
verzorgers_id
jaar

The generated query looks like this:

'SELECT Leerlingen.leerling_id AS `Leerlingen__leerling_id`, Leerlingen.voornaam AS `Leerlingen__voornaam`, Leerlingen.achternaam AS `Leerlingen__achternaam`, Leerlingen.geboortedatum AS `Leerlingen__geboortedatum`, Leerlingen.geslacht AS `Leerlingen__geslacht`, Leerlingen.email AS `Leerlingen__email`, Leerlingen.opmerking AS `Leerlingen__opmerking`, LeerlingenVerzorgers.id AS `LeerlingenVerzorgers__id`, LeerlingenVerzorgers.leerling_id AS `LeerlingenVerzorgers__leerling_id`, LeerlingenVerzorgers.verzorger_id AS `LeerlingenVerzorgers__verzorger_id`, LeerlingenVerzorgers.jaar AS `LeerlingenVerzorgers__jaar` FROM leerlingen AS Leerlingen INNER JOIN leerlingen_verzorgers LeerlingenVerzorgers ON (LeerlingenVerzorgers.verzorger_id IN (:c0) AND Leerlingen.leerling_id = (LeerlingenVerzorgers.leerlingen_id))

so first he uses the right leerling_id but at the end he uses leerlingen_id. Anyone knows what i did wrong?

--
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+unsubscribe@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: find all on complex model

No this is not what you do as the Student has a HABTM relationship and I am told to do joins.

Also when saying adding something I NEED the code as please dont  assume by adding containable I know what your talking about or the docs explain things.

I dont understand why simply getting information from 4 tables is just so complicated and where is the complete examples of this?





--
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+unsubscribe@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

@José: Here's what i'm using that works on the Contact page where i need to load the Captchas model to grab a question:

Works:
Plugin::loadAll([
    [
        'Thook/Websites' => ['routes' => true]
    ]
]);

Also works:
Plugin::load('Thook/Websites');

Doesn't work:
Plugin::load('Thook/Websites', ['routes' => true]);

Results in ([...] shortening the path to relevant stuff):
Warning (2): include([...]/Plugin/Thook\Websites\config\routes.php): failed to open stream: No such file or directory [ROOT\vendor\cakephp\cakephp\src\Core\Plugin.php, line 346]
Warning (2): include() [function.include]: Failed opening '[...]/Plugin/Thook\Websites\config\routes.php' for inclusion (include_path='.;C:\WebServer\php5\pear\pear') [ROOT\vendor\cakephp\cakephp\src\Core\Plugin.php, line 346]

However, the file path it's trying to include IS valid (aside from directory separators).

---

@mark
In my primary routes file:

Router::scope('/', function(RouteBuilder $routes) {
    // Some routes linking to main App Controllers, working.

    // Per your response:
    $routes->connect('/captchas/:action/*', [
        'plugin' => 'Thook/Websites',
        'controller' => 'captchas' // Also tried 'Captchas', but the other routes' controller values are lower-case & working
    ]);

    $routes->connect(':controller', ['action' => 'index], ['routeClass' => 'InflectedRoute']);

    $routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);

    // This will be dropped for production. ;)
    $routes->connect('/', [
        'controller' => 'pages',
        'action'     => 'display',
        'home'
    ]);
});

Still receiving Controller not found when i go directly to [host]/captchas:

Missing Controller

Error: CaptchasController could not be found.

Error: Create the class CaptchasController below in file: App\Controller\CaptchasController.php

<?php  namespace App\Controller;    use App\Controller\AppController;    class CaptchasController extends AppController {    }  

Thanks a lot guys, for taking a look at this with me.
-joe


On Saturday, 30 August 2014 08:33:57 UTC-4, mark_story wrote:
If Router::plugin() isn't getting you the routes you want, you can combine scope() and connect () to create the exact routes you want. Just keep in mind that all the routing data that doesn't change should be in the defaults list. For example

$routes->connect('/captchas/:action/*', ['plugin' => 'Thook/Websites','controller' => 'Captchas']);

Would let you connect all the actions on the CaptchasController in your plugin.

-mark


--
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+unsubscribe@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: find all on complex model

$this->Lesson->find('all', array(
'contain' => array(
'Student' , 'Tutor')));

given that your models are named as the conventions suggest

You also need to attach the Containable Behaviour to your model

/thomas


On 30 Aug 2014, at 16:41, ajt <jagguy999@gmail.com> wrote:

> I am having all sorts of problems and the docs for this is just awful. I have looked into simply getting data from the linked tables and after HOURS no one can give me a working example. I can only assume that this is hard to do or maybe it cant be done?
>
> 'The relationships are
> Lesson (main table where fk is linked to Tutor BelongsTo)
> LessonsStudents (the created table with student_id,lesson_id)
> Students (HASTBM student)
> Tutors (linked to Lessons)
>
> How can I get data from Lesson, Student and Tutor table in a find? I just need an example and not a link to the docs as the docs dont have a complete controller/view example of this.
>
>
>
> --
> 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+unsubscribe@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+unsubscribe@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: find all on complex model

I am having all sorts of problems and the docs for this is just awful. I have looked into simply getting data from the linked tables and after HOURS no one can give me a working example. I can only assume that this is hard to do or maybe it cant be done?

'The relationships are
Lesson (main table where fk is linked to Tutor BelongsTo)
LessonsStudents (the  created table with student_id,lesson_id)
Students (HASTBM student)
Tutors (linked to Lessons)

How can I get data from Lesson, Student and Tutor table in a find? I just need an example and not a link to the docs as the docs dont have a complete controller/view example of this.


--
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+unsubscribe@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.

Dispay data from HABTM in a view

Hi ,

I have the odd situation where I can retrieve data from a HABTM model (from debug array)but cant actually display any of it in the view. I keep getting index undefined error for everything. I want data from both tables but it doesnt work


//view doesnt work
  foreach ($student as $item2):
           echo '<td>'. $item2['Lesson']['id'].'</td>';   
       echo '<td>'. $item2['Student']['first_name'].'</td>'; //error undefined index


//controler

class LessonsController extends AppController {

...
  $this->Lesson->recursive = -1;
    
            $options['joins'] = array(
               array('table' => 'lessons_students',
                'alias' => 'LessonsStudent',
                'type' => 'LEFT',
                'conditions' => array(
                'Lesson.id = LessonsStudent.lesson_id',
                 )
                 ),
               
                array('table' => 'students',
                'alias' => 'Student',
                'type' => 'LEFT',
                'conditions' => array(
                'LessonsStudent.student_id=Student.id',
                 )
                 ),
                       
            );
           
            $options['conditions'] = array('Student.id' => 2);
      //  $Item->find('all', $options);
           
     $student=$this->set( 'student',$this->Lesson->find('all', $options));

--
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+unsubscribe@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.

3.x - Custom Route Class, match()

It might be possible to remove the automatic addition of the action key. However, I suspect a few tests will need to be updated.

--
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+unsubscribe@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

I do this by adding a header with a jQuery beforeSend hook. I don't have an example handy as I am not at a real computer right now.

-mark

--
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+unsubscribe@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: CakePHP 3.0.0-beta1 released

There might be a few other class renames happening, but the non-internal ones should all have aliases so your code doesn't break right away. However,the aliases will likely be removed for the release candidates, just so they don't stick around for a really long time.

-mark

--
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+unsubscribe@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

If Router::plugin() isn't getting you the routes you want, you can combine scope() and connect () to create the exact routes you want. Just keep in mind that all the routing data that doesn't change should be in the defaults list. For example

$routes->connect('/captchas/:action/*', ['plugin' => 'Thook/Websites','controller' => 'Captchas']);

Would let you connect all the actions on the CaptchasController in your plugin.

-mark

--
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+unsubscribe@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.

Smarty with Cakephp 2.XX .

I would look at Twig personally. It is a really solid template library, that has syntax similar to jinja and django. It also has automatic escaping which is a key feature if you are going to use a templating library. You should be able to find a few view classes that add twig support to cakephp as well.

-mark

--
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+unsubscribe@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

What happens if you use Plugin::load('PluginName'); instead of loadAll() ?

On Saturday, August 30, 2014 8:20:41 AM UTC+2, Joe Theuerkauf wrote:
*sigh* i guess i still need help here, but with the routing, not the DB connection.

i want to preserve the original way i was accessing my general-purpose Controller: /captchas/whatever.

i'm generally confused by routing, but AM reading the docs trying to figure it out. i know i don't want to use /thook/websites/captchas to get to this Controller. It's just a validation AJAX call, and besides, having the extra path segments in there feels awkward to me.

Trying to follow these:
http://book.cakephp.org/3.0/en/plugins.html#plugin-configuration
http://book.cakephp.org/3.0/en/plugins.html#plugin-controllers
http://book.cakephp.org/3.0/en/development/routing.html#plugin-routing

i've enabled the plugin's 'routes' option in bootstrap.php Plugin::loadAll() and i have this in my plugin's routes.php:
Route::plugin('Thook/Websites', function($routes) {
    $routes->fallbacks();
});

i also tried adding this to the App/Config/routes.php:
Routes::scope('/', function($routes) {
// ... other routes
    $routes->connect('/captchas', ['plugin' => 'Thook/Websites']);
// ... some other routes
});

i'm unable to get the message described in the docs (Model not found) when i go to the intended URL. Instead i get Controller not found (App\Controller\ThookController).

i'll keep trying, but anything toward helping me understand this better would be hugely appreciated.
-joe


On Saturday, 30 August 2014 01:04:22 UTC-4, Joe Theuerkauf wrote:
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+unsubscribe@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: find all on complex model

Looks like you are using recursive, you could try adding 'recursive' => 2 (or 3) to get deeper associations. Failing that you should look into Containable and HABTM or Has Many Through



On 30 August 2014 07:54, ajt <jagguy999@gmail.com> wrote:
I cant get the student name to appear or student id

--
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+unsubscribe@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+unsubscribe@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.

Friday, August 29, 2014

Re: find all on complex model

I cant get the student name to appear or student id

--
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+unsubscribe@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.

find all on complex model

I just need to get the details from a find all across 4 associated tables. I looked at the docs and I can get the data from 2 tables but not the other tables.
I have a lessons table where I get the relevant tutor id rows to display only. This works fine. I have a lessons-students table related to the lessons table over the FK lessons id. From this lessons-students table I then a field linked to another table.

lessons table (fk tutor_id but no student_id)
tutors table(linked to lessons table with tutor_id)
lessons_students table (linked with lessonID and has a studentID)
students table(linked with studentID from lesson-students table)

so if I get a row from lessons table I want the tutor name (from tutor table and I can do this now), the student name via the studentID . This is 4 tables and this is proving a headache as the docs just do simple examples.

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

    class LessonsController extends AppController {
       $this->set( 'tutor',$this->Lesson->find('all', array(
                 'conditions'=>array('Lesson.Tutor_id'=> 1,'Lesson.id'=>'Lesson_Students.lesson_id') ) ));
            
        
   
    view
    ////////
   
      <?php
          foreach ($tutor as $item):
               
            echo '<tr><td>'. $item['Lesson']['id'].'</td>';
          //  echo '<td>'. $item['Tutor']['id']['username'].'</td>';
            echo '<td>'. $item['Lesson']['tutor_id'].'</td>';
             echo '<td>'. $item['Tutor']['last_name'].'</td>'; 
               echo '<td>'. $item['Lesson_Student']['student_id'].'</td>';
            echo '</tr>';
         endforeach;
         unset($item);


--
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+unsubscribe@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.