gpt4 book ai didi

php - 无法定位与分页兼容的对象。使用 CakePHP

转载 作者:行者123 更新时间:2023-12-05 09:21:37 26 4
gpt4 key购买 nike

我是 PHP 和 CakePHP 的新手。在使用 CakePhp 连接我的数据库时发现问题。

下面是我的应用配置。我在 Bitnami WAMP 堆栈 5.4.40-0我正在使用 CakePhp 3.0.4 创建一个 web mvc 应用程序

我的 app.php 文件中的数据源条目

/**
* Connection information used by the ORM to connect
* to your application's datastores.
* Drivers include Mysql Postgres Sqlite Sqlserver
* See vendor\cakephp\cakephp\src\Database\Driver for complete list
*/
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => 'nonstandard_port_number',
'username' => 'test2',
'password' => 'computer',
'database' => 'jobs',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,

/**
* Set identifier quoting to true if you are using reserved words or
* special characters in your table or column names. Enabling this
* setting will result in queries built using the Query Builder having
* identifiers quoted when creating SQL. It should be noted that this
* decreases performance because each query needs to be traversed and
* manipulated before being executed.
*/
'quoteIdentifiers' => false,

/**
* During development, if using MySQL < 5.6, uncommenting the
* following line could boost the speed at which schema metadata is
* fetched from the database. It can also be set directly with the
* mysql configuration directive 'innodb_stats_on_metadata = 0'
* which is the recommended value in production environments
*/
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
],

我可以使用 bake 命令生成基本样板代码

但是现在当我在 localhost:8765/myapp 中运行我的应用程序时

出现以下错误

2015-07-01 14:31:22 Error: [RuntimeException] Unable to locate an object compatible with paginate.

请求网址:/myjobs

我的 Controller 代码

<?php
namespace App\Controller;

use App\Controller\AppController;

/**
* Jobs Controller
*
* @property \App\Model\Table\JobsTable $Jobs
*/
class MyJobsController extends AppController
{

/**
* Index method
*
* @return void
*/
public function index()
{
$this->paginate = [
'contain' => ['Jobs']
];
$this->set('jobs', $this->paginate($this->Jobs));
$this->set('_serialize', ['jobs']);
}

/**
* View method
*
* @param string|null $id Job id.
* @return void
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function view($id = null)
{
$job = $this->Jobs->get($id, [
'contain' => ['Jobs']
]);
$this->set('job', $job);
$this->set('_serialize', ['job']);
}

/**
* Add method
*
* @return void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$job = $this->Jobs->newEntity();
if ($this->request->is('post')) {
$job = $this->Jobs->patchEntity($job, $this->request->data);
if ($this->Jobs->save($job)) {
$this->Flash->success(__('The job has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The job could not be saved. Please, try again.'));
}
}
$jobs = $this->Jobs->Jobs->find('list', ['limit' => 200]);
$this->set(compact('job', 'jobs'));
$this->set('_serialize', ['job']);
}

/**
* Edit method
*
* @param string|null $id Job id.
* @return void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function edit($id = null)
{
$job = $this->Jobs->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$job = $this->Jobs->patchEntity($job, $this->request->data);
if ($this->Jobs->save($job)) {
$this->Flash->success(__('The job has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The job could not be saved. Please, try again.'));
}
}
$jobs = $this->Jobs->Jobs->find('list', ['limit' => 200]);
$this->set(compact('job', 'jobs'));
$this->set('_serialize', ['job']);
}

/**
* Delete method
*
* @param string|null $id Job id.
* @return void Redirects to index.
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$job = $this->Jobs->get($id);
if ($this->Jobs->delete($job)) {
$this->Flash->success(__('The job has been deleted.'));
} else {
$this->Flash->error(__('The job could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}

还想知道在 8765 端口运行的内部服务器在哪里。 ?我想使用 eclipse 调试此服务器上的资源。

最佳答案

当您键入错误的 url 时会发生此错误:

应该是其中之一

localhost:8765/my-app   
localhost:8765/myApp
localhost:8765/my_app

但不是:localhost:8765/myapp

关于php - 无法定位与分页兼容的对象。使用 CakePHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31165889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com