0

I am trying myself on cakephp, but it´s not working so far, and I don´t know why.

MODEL (group.php)

class Group extends AppModel {
var $name = 'Group';
}

Controller (GroupsController.php)

namespace App\Controller;

use App\Controller\AppController;

class GroupsController extends AppController{
var $name = 'Groups';

public function index(){

    $this->set('groups', $this->Group->find('all'));


    }
}

View (index.ctp)

<?php foreach ($groups as $group): ?>
<div class="groups">
<?= $this->element('groups', ['group' => $group]) ?>
</div>
<?php endforeach; ?>

I am getting ->

Error: Call to a member function find() on boolean 
File C:\xampp\htdocs\cakephp\src\Controller\GroupsController.php 
Line: 19

Can anybody point out the problem?

5
  • 3
    No offense, but you really should start with reading the manual first! Do the tutorials, bake your code, and ideally read the whole docs at least once! You are mixing Cake 2.x with Cake 3.x, violating the naming conventions, missing namespace declarations, etc... Commented Jan 1, 2016 at 18:47
  • Kinda hard to get, Video Tutorials are mostly for 1.x or 2.x - and true I was reading the Docs for 2.x, just realized that, preconfigured should be 3.x, well thats on the developer tho! haha I will look into 3.x now. But pointing out the mistakes wouldve helped anyways. Commented Jan 1, 2016 at 18:52
  • I ment the tutorials in the docs (bookmarker, blog) :) The 3.0 ones should actually be the default btw. The main problem is probably your model and the $this->Group reference. The model is named incorrectly (should be GroupsTable(.php)), extends a (by default) non-existing class (AppModel is gone in 3.x, the base is now \Cake\ORM\Table), is missing the proper namespace declaration (App\Model\Table), and may even be placed in the wrong folder (just guessing on this one). And finally it should be $this->Groups (plural) in your controller. Commented Jan 1, 2016 at 19:00
  • Thanks for the answer. Sadly didn´t work. Kinda hard to get throw the Docs, a simple Beginner Tut. would probably help. When I ahve time to read ~ 800 Pages, I will come back. Commented Jan 1, 2016 at 19:54
  • The manual does have beginner tutorials book.cakephp.org/3.0/en/tutorials-and-examples.html Commented Jan 2, 2016 at 12:09

1 Answer 1

1

The following link should help you get started, This is the full Documentation of the bookmarks tutorial APP

however, I will include a quick run through of what you probably need to do,

first construct your database table using the conventions of cakephp this will give you the basics

then you can use the following command to ask cakephp to create your classes for you,

bin/cake bake all {classname}

once the classes are built you will need to take some time to understand the content of the following folders:-

  1. src/Model
  2. src/Controller
  3. src/Template
  4. src/View

those folders contain the basic backbone of your app logic, if you need to modify or create Routes config/routes.php is your target

good luck!

Sign up to request clarification or add additional context in comments.

3 Comments

Wow this is a one year old post :D I created already 3 apps by now, but thanks for the effort anyways ^^
sorry, i noticed after i posted the reply, and it was embarrassing :D
Well you get an + for the effort anyways ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.