Mostrando postagens com marcador CakePHPCookbook. Mostrar todas as postagens
Mostrando postagens com marcador CakePHPCookbook. Mostrar todas as postagens

sábado, 30 de janeiro de 2016

Strict (2048): Declaration of App\Controller\UsersController::beforeFilter() should be compatible with App\Controller\AppController::beforeFilter(Cake\Event\Event $event) [APP/Controller\UsersController.php, line 12]

Strict (2048): Declaration of App\Controller\UsersController::beforeFilter() should be compatible with App\Controller\AppController::beforeFilter(Cake\Event\Event $event) [APP/Controller\UsersController.php, line 12]
Warning (4096): Argument 1 passed to App\Controller\UsersController::beforeFilter() must be an instance of App\Controller\Event, instance of Cake\Event\Event given, called in C:\Users\daniel\blog\vendor\cakephp\cakephp\src\Event\EventManager.php on line 385 and defined [APP/Controller\UsersController.php, line 14]

Hi!

If you are just like me studying the tutorial

CakePHP Cookbook Documentation
Release 3.x
Cake Software Foundation
January 18, 2016

You should have been found this problem when you finished the blog example.

Solution


Change this

    public function beforeFilter(Event $event)
    {
        parent::beforeFilter($event);
        // Allow users to register and logout.
        // You should not add the "login" action to allow list. Doing so would
        // cause problems with normal functioning of AuthComponent.
        $this->Auth->allow(['add', 'logout']);
    }

For this

    public function beforeFilter(\Cake\Event\Event $event)
    {
        $this->Auth->allow(['add','logout']);
    }
 
Good luck!




DROPDOWNLIST - You want to show the name, not the id. Me too. That's how I did it.

Hi!

Straight to the point.

        First, I was studying the tutorial. And was working with treelist. This is no good for me. So, I asked myself,  how do make this dropdownlist show the name? The standard answer is, "YOU SHOULD USE VIRTUAL FIELD". And I found it really annoying. So, I found out this solution.

        //You write this in your controller

        $query = $this->Articles->Categories->find('all', array('fields' => array('id', 'name')));
        foreach($query as $row)
        {
            $id = $row['id'];
            $name = $row['name'];
            $categories[$id] = $name;
        }

       //You write this in  your template
     
       echo $this->Form->input('category_id', array('type' => 'select','options'=> $categories));

And you are done! And of story!

Good luck!

PS: I'm new to cakePHP. This was really annoying to find out.

More informations click on the link bellow

http://stackoverflow.com/questions/19920094/cakephp-format-findall-to-list-in-view

Lines of the tutorial are incomplete - Page 90 - CakePHP Cookbook

Hi!

I found this problem when I was studying the tutorial

CakePHP Cookbook Documentation
Release 3.x
Cake Software Foundation
January 18, 2016

<td><?= $category->id ?></td>
<td><?= $category->parent_id ?></td>
<td><?= $category->lft ?></td>
<td><?= $category->rght ?></td>
<td><?= h($category->name) ?></td>
<td><?= h($category->description) ?></td>
<td><?= h($category->created) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $category->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $category->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $category->id], 
<?= $this->Form->postLink(__('Move down'), ['action' => 'moveDown', $category->
<?= $this->Form->postLink(__('Move up'), ['action' => 'moveUp', $category-></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

Correction

    <?= $this->Html->link(__('View'), ['action' => 'view', $category->id]) ?>
    <?= $this->Html->link(__('Edit'), ['action' => 'edit', $category->id]) ?>
    <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $category->id]) ?>
    <?= $this->Form->postLink(__('Move down'), ['action' => 'moveDown', $category->id]) ?>
    <?= $this->Form->postLink(__('Move up'), ['action' => 'moveUp', $category->id]) ?>

Good luck!

segunda-feira, 25 de janeiro de 2016

Error: SQLSTATE[HY000]: General error: 1364 Field 'parent_id' doesn't have a default value

CakePHP Cookbook Documentation
Release 3.x
Cake Software Foundation

January 18, 2016

Page 88

These fields are automatically managed by the TreeBehavior when a category is saved.
Using your web browser, add some new categories using the /yoursite/categories/add controller

action.

Error: SQLSTATE[HY000]: General error: 1364 Field 'parent_id' doesn't have a default value

If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.

SQL Query:

INSERT INTO categories (lft, rght) VALUES (:c0, :c1)
If you want to customize this error message, create src\Template\Error\pdo_error.ct

SOLUTION

The parent_id was created as not null, make it nullable.

I did it using PHP Admin
I'm using vertrigo (the best wamp I ever found)