无法使用CakePHP找到与paginate.com兼容的对象
我不熟悉PHP和CakePHP。使用CakePhp连接数据库时发现问题 下面是我的应用程序配置。 我在Bitnami WAMP堆栈5.4.40-0上 我正在使用CakePHP3.0.4创建一个web mvc应用程序 My app.php文件中的数据源条目无法使用CakePHP找到与paginate.com兼容的对象,php,cakephp,cakephp-3.0,Php,Cakephp,Cakephp 3.0,我不熟悉PHP和CakePHP。使用CakePhp连接数据库时发现问题 下面是我的应用程序配置。 我在Bitnami WAMP堆栈5.4.40-0上 我正在使用CakePHP3.0.4创建一个web mvc应用程序 My app.php文件中的数据源条目 /** * Connection information used by the ORM to connect * to your application's datastores. * Drivers include Mysql Pos
/**
* 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'],
],
请求URL:/myjobs
我的控制器代码
<?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']);
}
}
我猜是我的表结构有问题
可能CakePHP在表中查找某些属性。
特别是作为主键的id的auto-increment属性
我根据书签表创建了我的表结构,它工作了
我有一个enum字段,它没有通过CakePHP映射到对象。我想枚举是CakePHP的局限性
问候,
Saurav键入错误url时会发生此错误:
它应该是其中之一
localhost:8765/my-app
localhost:8765/myApp
localhost:8765/my_app
但不是:localhost:8765/myapp您烘焙了该控制器,然后将其从Jobs
重命名为MyJobs
?什么是$this->Jobs
(即检查-它是对象还是空)<代码>内部服务器位于哪里运行在端口8765中位于
-也就是说,它正在运行您的代码。它是空的…控制器被重命名此答案与问题无关-控制器没有加载模型,因此传递给paginate的变量是空的,而不是模型的名称,或者查询对象。是的,但是由于db结构中的某些问题,没有加载模型可能您是对的…但是除了重命名控制器类之外,我没有对其进行任何更改…如果控制器名称与模型名称匹配,则loadModel调用是不必要的/由约定覆盖的;因此,重命名控制器文件直接导致其不工作。这就是我第一个问题的原因,即控制器是否已重命名。有关更多信息,请参阅Controller.php的源代码。
localhost:8765/my-app
localhost:8765/myApp
localhost:8765/my_app