Wednesday, April 30, 2014

Re: How to retrieve data from anther table in one model

You're doing it all wrong so even if you get this to work you are exposing yourself to problems down the line.

First, each table should have its own model. Second, name your tables correctly if you can. If you can't for whatever reason, then place public $useTable = 'your_table_name'; at the top of the model (rather than public $useTable = false;). Third, link your models through table associations. Then you can daisy chain models. For example, $this->TableOne->TableTwo-find('all');

On 30 Apr 2014, at 05:44:22, gyrate360 <gyrate360@gmail.com> wrote:

> I wanna retrieve data from anther table in one model.
> case is like this:
> in a model,eg:StaticTable,I set $useTable as false;
> so in one function,I just wanna get data from some table.how can I manage
> it?
> Here is my code,but it doese't work.
> part of the code in app/Model/StaticTable.php:
> class StaticTable extends Model{
> public $useTable = false;
> protected $_tableName = '';
> public function get_some_data(){
> $this->_tableName = 'tb_server_info';
> $serverInfo = $this->find('all', array(
> 'conditions' => array('status'=>1),
> 'order'=>array('created_date'=>'asc')
> ));
> $this->_tableName = 'tb_platform_info';
> $platformInfo= $this->find('all', array(
> 'conditions' => array('status'=>1),
> 'order'=>array('created_date'=>'asc')
> ));
> return
> array('server_info'=>$serverInfo.'platform_info'=>$platformInfo);
> }
> }
>
>
>
> --
> View this message in context: http://cakephp.1045679.n5.nabble.com/How-to-retrieve-data-from-anther-table-in-one-model-tp5718071.html
> Sent from the CakePHP mailing list archive at Nabble.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.




Jeremy Burns
Class Outfit

http://www.classoutfit.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.

No comments: