nchankov / cakemenu

Plugin for creating menu from the database. Using Authake to restrict the access to the nodes.
13 stars 7 forks source link

Getting Cakemenu and Authake to Play Nice #1

Closed larry-tx closed 13 years ago

larry-tx commented 13 years ago

I've got Cakemenu and Authake, each, working perfectly. They are two fantastic plugins. Unfortunately, try as I might, I can't get them to work together. I get the error message that the relevant columns in my cakemenu table don't exist when in fact, they do.

The SQL for my cakemenu table is:

CREATE TABLE cakemenu ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(45) DEFAULT NULL, link varchar(255) DEFAULT NULL, parent_id varchar(45) DEFAULT NULL, lft int(11) DEFAULT NULL, rght int(11) DEFAULT NULL, icon varchar(45) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;

The beforeFilter in app_controller is:

function beforeFilter() {
    $this->set('menu', $this->Cakemenu->nodes(array('fields' => array('cakemenu.id, cakemenu.name')), $auth='Authake', $cache=null));
    //$this->set('menu', $this->Cakemenu->nodes());
    $this->auth();
}

And error message that I'm getting is:

Warning (512): SQL Error: 1054: Unknown column 'cakemenu.id' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 681] Code | Context

        'level', 'error', 'code', 'helpID', 'description', 'file', 'path', 'line', 'context'
    );
    echo $_this->_output($data);

$sql = "SELECT cakemenu.id, cakemenu.name FROM cakemenu AS Menu WHERE 1 = 1 ORDER BY Menu.lft ASC " $error = "1054: Unknown column 'cakemenu.id' in 'field list'" $out = null

Debugger::handleError() - CORE\cake\libs\debugger.php, line 306 DboSource::showQuery() - CORE\cake\libs\model\datasources\dbo_source.php, line 681 DboSource::execute() - CORE\cake\libs\model\datasources\dbo_source.php, line 266 DboSource::fetchAll() - CORE\cake\libs\model\datasources\dbo_source.php, line 410 DboSource::read() - CORE\cake\libs\model\datasources\dbo_source.php, line 820 Model::find() - CORE\cake\libs\model\model.php, line 2111 CakemenuComponent::_fetch() - APP\plugins\cakemenu\controllers\components\cakemenu.php, line 104 CakemenuComponent::nodes() - APP\plugins\cakemenu\controllers\components\cakemenu.php, line 39 AppController::beforeFilter() - APP\controllers\app_controller.php, line 8 Controller::startupProcess() - CORE\cake\libs\controller\controller.php, line 526 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 187 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171 [main] - APP\webroot\index.php, line 83

Query: SELECT cakemenu.id, cakemenu.name FROM cakemenu AS Menu WHERE 1 = 1 ORDER BY Menu.lft ASC

Warning (2): Invalid argument supplied for foreach() [CORE\cake\libs\model\model.php, line 2318]

Fatal error: Call to a member function getUserId() on a non-object in E:\xampp\htdocs\mysite\app\plugins\cakemenu\controllers\components\cakemenu.php on line 117

Can you give me any idea what I'm doing wrong?

nchankov commented 13 years ago

LarryTX,

few things on your code: if you run that sql in your mysql console (or phpMyAdmin) you will answer your self why the fields are not shown :)

SELECT 
  cakemenu.id, 
  cakemenu.name 
FROM 
  `cakemenu` AS `Menu` 
WHERE 
  1 = 1 
ORDER BY 
  `Menu`.`lft` ASC

As you can see the cakemenu table, has been aliased with Menu alias. So, instead of cakemenu.id you should write Menu.id (same apply for name column).

Another thing is the second parameter of Cakemenu::nodes(); - it should be a reference to Authake component, rather than a string.

Also, remove the field's option from the first parameter, because the plugin require some of the fields mostly cakemenu.link :) but also the icon. So without them it will throw some warnings.

So, your final code should look like this:

function beforeFilter() {
   $this->set('menu', $this->Cakemenu->nodes(null, $this->Authake, null));
   $this->auth();
}