Discussion:
[Ask] Query to select multiple table in cakephp
thom
2011-03-18 01:30:25 UTC
Permalink
Hello, I just wonder how to write this query in cakephp controller

SELECT aros_acos.*, acos.id, acos.alias FROM aros_acos, acos WHERE
aros_acos.aco_id = acos.id

Any one can help?
--
Regards,,,
mastanto
http://www.mastanto.com
http://thom-sharing.blogspot.com
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
thom
2011-03-18 01:44:56 UTC
Permalink
Post by thom
Hello, I just wonder how to write this query in cakephp controller
SELECT aros_acos.*, acos.id, acos.alias FROM aros_acos, acos WHERE
aros_acos.aco_id = acos.id
Any one can help?
Oh, my bad. I found it already in the manual. Sorry.
--
Regards,,,
mastanto
http://www.mastanto.com
http://thom-sharing.blogspot.com
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
thom
2011-03-18 03:50:16 UTC
Permalink
Post by thom
Oh, my bad. I found it already in the manual. Sorry.
Back again. I'm in trouble.
I still dont make it. May someone guide me?

My Controller
====================
class ArosAcosController extends AppController {

var $name = 'aros_acos';

function index() {
$this->ArosAcos->recursive = -1;
$this->set('aros_acos', $this->ArosAcos->find('all'));
}
}
===================

MyModel
===================
<?php
class ArosAcos extends AppModel {
var $name = 'ArosAcos';
$options['joins'] = array(
array('table' => 'aros_acos',
'alias' => 'ArosAcos',
'type' => 'INNER',
'conditions' => array(
'ArosAcos.acos_id = acos.id',
)
));
}
?>
===================


It gives me error :
Call to undefined method stdClass::find() in
D:\_\www\bread\app\controllers\aros_acos_controller.php on line 8
--
Regards,,,
mastanto
http://www.mastanto.com
http://thom-sharing.blogspot.com
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
cricket
2011-03-18 04:14:22 UTC
Permalink
Post by thom
Post by thom
Oh, my bad. I found it already in the manual. Sorry.
Back again. I'm in trouble.
I still dont make it. May someone guide me?
My Controller
====================
class ArosAcosController extends AppController {
       var $name = 'aros_acos';
       function index() {
               $this->ArosAcos->recursive = -1;
               $this->set('aros_acos', $this->ArosAcos->find('all'));
       }
}
===================
MyModel
===================
<?php
class ArosAcos extends AppModel {
       var $name = 'ArosAcos';
       $options['joins'] = array(
                                       array('table' => 'aros_acos',
                                               'alias' => 'ArosAcos',
                                               'type' => 'INNER',
                                               'conditions' => array(
                                               'ArosAcos.acos_id = acos.id',
                                               )
                                       ));
}
?>
===================
Call to undefined method stdClass::find() in
D:\_\www\bread\app\controllers\aros_acos_controller.php on line 8
When I did this I didn't bother modelizing ArosAcos. This is from my
SectionsController. Each Group has different rights for each Section.

/* fetch the permissions for this group
*/
$perms = $this->Acl->Aco->find(
'all',
array(
'fields' => array('Aco.foreign_key'),
'conditions' => array(
'Aco.model' => 'Section',
'Aco.id = Permission.aco_id'
),
'recursive' => -1,
'joins' => array(
array(
'table' => 'aros',
'alias' => 'Aro',
'type' => 'INNER',
'conditions'=> array(
'Aro.model' => 'Group',
"Aro.foreign_key = ${group_id}"
)
),
array(
'table' => 'aros_acos',
'alias' => 'Permission',
'type' => 'INNER',
'conditions'=> array(
'Permission.aro_id = Aro.id',
'Permission._read >= 0'
)
)
)
)
);

$section_ids = Set::extract($perms, '{n}.Aco.foreign_key');

What I was doing was generating the Section navigation based on the
User's Group, then caching the output.

This is from a site that's still running on 1.2.x.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
thom
2011-03-18 07:46:14 UTC
Permalink
Post by cricket
When I did this I didn't bother modelizing ArosAcos. This is from my
SectionsController. Each Group has different rights for each Section.
Well, what exactly I want is I wanna make a simple ACL Management
based on aros_acos table. So, I wanna update permission, just like
drupal's. But It's not as simple as I thought. Or maybe it's just my
mind which made it not.

I am not quiet understand yet with Joining table in cake. So, what do
you suggest then? I am at my confusing-point already.
--
Regards,,,
mastanto
http://www.mastanto.com
http://thom-sharing.blogspot.com
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
ShadowCross
2011-03-20 08:34:32 UTC
Permalink
The error message mentions "stdClass::find()", which seems to indicate
that it's not using your ArosAcos model at all. I think the main part
of your problem is that in your ArosAcosController, you have:

var $name = 'aros_acos';

when it should be:

var $name = 'ArosAcos';

Cake uses the $name attibute of your controller to determine the
default classname of the model your controller is using (you can
override this with $uses). Since you don't have a model named
"aros_acos" (you have a filename aros_acos.php, but the model name is
"ArosAcos"), it's not loading the model.

When you execute the line:

$this->ArosAcos->recursive = -1;

PHP creates a new generic "empty" object on-the-fly (based on
stdClass), ($this->ArosAcos) with a attribute "recursive" and assigns
-1 to that property. Since stdClass does not have a find() method,
you get the error message on the next line.

Your attempt to define the joining table using the $options['join'] in
the ArosAcos won't work, because Cake isn't looking for $options in
your model attributes (see http://book.cakephp.org/view/1057/Model-Attributes
and http://api13.cakephp.org/class/model for API detail).

As cricket was hinting, under most circumstances, you normally don't
need to "modelize" join tables (in this case "ArosAcos").

Have you considered one of the ACL Plugins currently available? (You
can google "Cake ACL Plugin" -- the one I use is described on
http://bakery.cakephp.org/articles/interlock/2010/03/02/updated-acl-plugin)
ACL can be complicated AND can prevent your code from running (how
much time have I wasted troubleshooting why a new action I added to an
existing controller refused to work, simply because I forgot to add
permissions to my "admin" user?), so using an existing plugin to
facilitate maintenance of you ACL can give you a little more time to
learn Cake, and also provide you an example of how other Cake
programmers "do it". Read up on Plugins (http://book.cakephp.org/view/
1111/Plugins)
Post by thom
Post by cricket
When I did this I didn't bother modelizing ArosAcos. This is from my
SectionsController. Each Group has different rights for each Section.
Well, what exactly I want is I wanna make a simple ACL Management
based on aros_acos table. So, I wanna update permission, just like
drupal's. But It's not as simple as I thought. Or maybe it's just my
mind which made it not.
I am not quiet understand yet with Joining table in cake. So, what do
you suggest then? I am at my confusing-point already.
--
Regards,,,
mastantohttp://www.mastanto.comhttp://thom-sharing.blogspot.com
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
thom
2011-03-18 04:16:35 UTC
Permalink
Back again. I'm in trouble.
I still dont make it. May someone guide me?

My Controller
====================
class ArosAcosController extends AppController {

var $name = 'aros_acos';

function index() {
$this->ArosAcos->recursive = -1;
$this->set('aros_acos', $this->ArosAcos->find('all'));
}
}
===================

MyModel
===================
<?php
class ArosAcos extends AppModel {
var $name = 'ArosAcos';
$options['joins'] = array(
array('table' => 'aros_acos',
'alias' => 'ArosAcos',
'type' => 'INNER',
'conditions' => array(
'ArosAcos.acos_id = acos.id',
)
));
}
?>
===================


It gives me error :
Call to undefined method stdClass::find() in
D:\_\www\bread\app\controllers\aros_acos_controller.php on line 8
--
Regards,,,
mastanto
http://www.mastanto.com
http://thom-sharing.blogspot.com
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Continue reading on narkive:
Search results for '[Ask] Query to select multiple table in cakephp' (Questions and Answers)
3
replies
Suggest PHP Framework Please?
started 2010-11-01 22:29:22 UTC
programming & design
Loading...