dongtanjian9310 2015-03-24 03:25
浏览 37

Cakephp 3.0采集了数据

Hi I'm a novice in cakephp However, I'm trying to make my blog with cakephp 3.0 which is stable version. I got stuck not taken database show view.ctp

Controller => "ListjobsController.php"

<?php
namespace App\Controller;
 class ListjobsController extends AppController{
    public function jobdetail(){
        $jobdetail = $this->Listjobs->find('all');
        $this->set( compact('jobdetail'));
    }
}

Model =>Table => "ListjobsTable.php"

<?php
namespace App\Model\Table;
use Cake\ORM\Table;

class ListjobsTable extends Table{
    public function initialize(array $config){
        $this->table('listjobs');
        $this->displayField('title');
        $this->primaryKey('id');
         $this->belongsToMany('Users',[
            'foreignKey' => 'user_id'
        ]);
    }
}

Template => Listjobs => "jobdetail.ctp"

<p><?= pr($jobdetail);exit; ?></p>

it does not appear that the current database information:

Cake\ORM\Query Object


(
[sql] => SELECT Listjobs.id AS `Listjobs__id`, Listjobs.user_id AS `Listjobs__user_id`, Listjobs.type_id AS `Listjobs__type_id`, Listjobs.cate_id AS `Listjobs__cate_id`, Listjobs.title AS `Listjobs__title`, Listjobs.location AS `Listjobs__location`, Listjobs.description AS `Listjobs__description`, Listjobs.skillsrequired AS `Listjobs__skillsrequired`, Listjobs.companyname AS `Listjobs__companyname`, Listjobs.website AS `Listjobs__website`, Listjobs.email AS `Listjobs__email`, Listjobs.password AS `Listjobs__password`, Listjobs.created AS `Listjobs__created`, Listjobs.modified AS `Listjobs__modified` FROM listjobs Listjobs
[params] => Array
    (
    )

[defaultTypes] => Array
    (
        [Listjobs.id] => integer
        [id] => integer
        [Listjobs.user_id] => integer
        [user_id] => integer
        [Listjobs.type_id] => integer
        [type_id] => integer
        [Listjobs.cate_id] => integer
        [cate_id] => integer
        [Listjobs.title] => string
        [title] => string
        [Listjobs.location] => string
        [location] => string
        [Listjobs.description] => text
        [description] => text
        [Listjobs.skillsrequired] => text
        [skillsrequired] => text
        [Listjobs.companyname] => string
        [companyname] => string
        [Listjobs.website] => string
        [website] => string
        [Listjobs.email] => string
        [email] => string
        [Listjobs.password] => string
        [password] => string
        [Listjobs.created] => datetime
        [created] => datetime
        [Listjobs.modified] => datetime
        [modified] => datetime
    )

[decorators] => 0
[executed] => 
[hydrate] => 1
[buffered] => 1
[formatters] => 0
[mapReducers] => 0
[contain] => Array
    (
    )

[matching] => Array
    (
    )

[extraOptions] => Array
    (
    )

[repository] => App\Model\Table\ListjobsTable Object
    (
        [registryAlias] => Listjobs
        [table] => listjobs
        [alias] => Listjobs
        [entityClass] => \Cake\ORM\Entity
        [associations] => Array
            (
                [0] => users
            )

        [behaviors] => Array
            (
            )

        [defaultConnection] => default
        [connectionName] => default
    )

)

I can not understand why the data in the database does not appear. hope you can help me!!!

  • 写回答

3条回答 默认 最新

  • duanmei2459 2015-03-24 08:17
    关注

    The find() method always returns a Query object, that is the reason you cannot see the results but only the SQL that is going to be executed. If you are just starting with cake 3 there are a couple nice way in which you can see what the results of a query are:

    debug($this->Table->find('all')->toArray());
    

    That will give you an array of entities that were fetched from the database, the output may still be a bit confusing for you if you are not use to the idea of entities. SO here is another trick:

    // In bootstrap.php
    function dj($data)
    {
         debug(json_encode($data, JSON_PRETTY_PRINT));
    }
    

    And then:

    dj($this->Table->find('all'));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line