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

domingo, 14 de fevereiro de 2016

General error: 1364 Field 'id' doesn't have a default value

Hi!

The id you defined for your entity is not identity. It must be!

Good luck!

Error: SQLSTATE[HY000]: General error: 1364 Field '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 projetos (user_id, nome) VALUES (:c0, :c1)

terça-feira, 9 de fevereiro de 2016

cakephp 3 installation issue - unexpected T_OBJECT_OPERATOR in config/bootstrap.php on line 107

Hi!

You have just deployed your applicaton and you received this error

unexpected T_OBJECT_OPERATOR
?

Don't worry, it's the version of your PHP.

I changed from 5.3 to 5.5.

Yeah, I have no time keep investigating, so I decided to go to 5.5.

It worked.

Good Luck!



segunda-feira, 8 de fevereiro de 2016

Can't logout on Chrome? Maybe Chrome is not the problem.


Hi!

I was having this issue. Then I found Raffi's answer. Which is perfect.
In my case, only admin was able to logout.
Then he made me understand that I forgot to define that, if you are not admin, you also can logout!

        public function isAuthorized($user)
        {

                $action = $this->request->params['action'];

                if (in_array($action, ['logout']))

                {
                   return true; // If user wants to logout, ok for everyone.
                }
                else
                {
                    // If he or she is not trying to logout, then, if the role of the user is admin, anything goes
                    if (isset($user['role']) && $user['role'] === 'admin')
                    {
                         return true;
                    }                  

                    return false;
                }



                // Default deny
                //return false;
         
        }

Hope it helps!

Good luck!

http://stackoverflow.com/questions/27232679/cakephp-3-users-not-allowed-to-logout

Login, Logout is making you insane? / CakePHP 3.0 / That's how I did.

Hi!

This thing of login, logout is p. in the a.. Well that's how I did mine

        $this->loadComponent('Auth', [
                'authorize' => 'Controller',
                'authenticate' => [
                'Form' => [
                'fields' => [
                'username',
                'password' => 'password'
                ]
                ]
                ],
                'loginAction' => [
                'controller' => 'Users',
                'action' => 'login'
                ],
                'loginRedirect' => [
                                'controller' => 'Users',
                                'action' => 'index'
                            ],
                'logoutRedirect' => [
                                'controller' => 'Users',
                                'action' => 'login'
                            ]                        
                ]);
                // Allow the display action so our pages controller
                // continues to work.
                $this->Auth->allow(['display']);
    }

Hope it helps.

Good Luck!


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!