cake learner,
I've been able to get the controller object and it's models into my
components like this:
// in the component
function initialize(&$controller, $settings=array()) {
$this->controller = $controller;
$this->model = &$controller->{$this->controller->modelClass};
$this->data = &$controller->data;
}
The references (&) may not be quite right. They work, but I'm still
fumbling around a little as I learn things.
That's made my components smart enough to respond to multiple
controllers.
Later in component functions I can do normal finds like this:
$parentList = $this->model->find('list', array(
'fields' => array($this->model->primaryKey,
"indexed_name"),
'order'=>'lft desc',
'recursive' => 2));
This example works on Tree structures so many controllers and models
need to be fed in. I've even been able to define virtualFields for the
model from inside the component.
Regards,
Don Drake
On Mar 7, 9:24 am, cake-learner <[email protected]> wrote:
> find function doesn't work on component.
> Say if i execute the following sentence
> $this -> Account -> find( 'all' );
>
> cakephp execute select from accounts( there is not * ).
> As long as I get the sql working i don't mind not using the find
>
> On Mar 7, 3:49 am, "Krissy Masters" <[email protected]>
> wrote:
>
> > Whats wrong with a cake find()?
>
> > If data is coming from a form it would be in $this->data....
>
> > Have you read or looked at the cookbook?
>
> > $account = $this->Account->find('first', array('conditions' =>
> > array('Account.username' => $emailAddress)));
>
> > -----Original Message-----
> > From: [email protected] [mailto:[email protected]] On Behalf
>
> > Of cake-learner
> > Sent: Monday, March 07, 2011 7:34 AM
> > To: CakePHP
> > Subject: cakephp model problem
>
> > Still continue having problem with cakephp model.
>
> > I always have the account empty and don't know why.
>
> > Configure::write( "debug", 2 );
> > $emailAddress = $_POST[ 'email_address' ];
> > $sql = "SELECT * FROM accounts WHERE username = '" . $emailAddress .
> > "' LIMIT 1";
> > echo $sql;
> > $account = $this -> Account -> Query( $sql );
> > var_dump( $account );
>
> > The following is the sql executed and works ( can get the result )
> > when try to execute this sql sentence on phpmyadmin.
> > SELECT * FROM accounts WHERE username = '[email protected]' LIMIT 1
>
> > --
> > Our newest site for the community: CakePHP Video
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group
> > athttp://groups.google.com/group/cake-php
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php