0
votes

$categ = $this->FreeadsCategory->bindModel( array( 'hasMany' => array( 'Subcategory' => array('foreignKey' => 'category_id', 'order'=>'id ASC') ) ) );

$data = $this->FreeadsCategory->findById($i); $this->set("datas", $data);

  1. I am not able to fetch the datas in view page using cakephp
  2. If i give pr($datas); showing nothing in ctp file
  3. If i print the data in controller i am getting the following array structure

Array ( [FreeadsCategory] => Array ( [id] => 1 [uuid] => 51512434-e4c4-441b-b90e-16f8732d5573 [category] => Automobiles [status] => Active )

[Subcategory] => Array
    (
        [0] => Array
            (
                [id] => 1
                [uuid] => 4ea15f22-adf0-4020-b35d1-052ff9ff9a27
                [category_id] => 1
                [subcategory] => Cars/Cabs/Jeeps
                [status] => Active
            )

        [1] => Array
            (
                [id] => 5
                [uuid] => 51cec363-e7ac-4095-a86b-0ccdf260d1b4
                [category_id] => 1
                [subcategory] => Buses/Lorries
                [status] => Active
            )

)

1

1 Answers

0
votes

You don't fetch data in views, that violates the MVC pattern. Technically there are ways to do it but it's plain wrong, you'll end up with unmaintanable garbage code.

I really recommend you to get started by reading about the MVC design pattern and to do the CakePHP blog tutorial first to get a minimum of understanding of how CakePHP works.