ACO alias doesn't work with 'controllers/Controller' value - cakephp

I am new to ACLs in CakePHP. I believe my Administrator group is set up correctly with full access to the 'controllers' ACO. However I get an error when I try to go to any controller or action that is not explicitly made public.
Warning (512): DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:
Aro: Array
(
[User] => Array
(
[id] => 9
[email] => Admin
[group_id] => 3
[is_active] => 1
[created] => 2013-04-08 07:59:52
[modified] => 2013-04-08 07:59:52
[Group] => Array
(
[id] => 3
[name] => Administrators
[user_count] => 2
[created] => 2013-04-08 06:34:58
[modified] => 2013-04-08 06:34:58
)
)
)
Aco: controllers/Users/index [CORE/Cake/Model/Permission.php, line 94]
In my acos table there is an entry for 'controllers/Users/index' as the alias. This entry has a parent_id that references 'controllers/Users', which in turn has a parent_id which references 'controllers'.
There is only one entry in my 'aros_acos' table that is granting full permission to the Administrators group.
Based on the error above I did a little digging and found that if I directly try to call $this->Acl->Aco->node('controllers/Users/index'); the returned value is false. But if I do the same query on $this->Acl->Aco->node('controllers'); the returned value is the correct array.
Something is clearly not functioning properly but I can't figure out where I am going wrong. I have been digging in the Documentation Book and API all day and have not found any reason why 'controllers/Users/index' isn't found but 'controllers' is. At this point it seems like it has something to do with the / character but I don't know why. I used the same string when adding the Aco and it saved correctly.
Thanks!

I found the problem by installing the ACL Plugin at:
http://www.alaxos.net/blaxos/pages/view/plugin_acl_2.0
After running this great utility I found that I was incorrectly adding my ACOs with the fill path in the alias. It turns out the alias is just the action or controller name and based on the parent_id's it finds the correct path.
This is not very well documented in the CakePHP Documentation, but what else is new.
Example:
I was adding 'controllers/Users/index' instead of 'index'.
Hope this can help someone else solve this problem! I wasted an entire day on it.

Related

cakephp Associations Delete not working

I have a table of files and a table of permissions. The idea is that the user can assign permissions to other users to allow them to read, edit, etc. I set up an association so that the files, which I call workspaces, have many permissions. Here is the declaration in the workspaces model linking the permissions model
public $hasMany = array(
'Permission' => array(
'className' => 'Permission',
'foreignKey'=> 'workspace_id',
'dependent' => true
)
);
The problem is that when I go to delete a file, I get an error.
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Permission.id' in 'field list'
SQL Query: SELECT `Permission`.`id` FROM `cadwolfc_workspaces`.`permissions` AS `Permission` WHERE `Permission`.`workspace_id` = 71
Why is cakephp looking for an id parameter in the permissions table when I have clearly defined the workspace_id as the foreign key? I had assumed that by linking the models and then deleting a workspace, the associated permissions would be deleted. That is what I am trying to do here. I don't understand why a select query is being executed when a delete query is what is needed?
Update: The call to delete the workspace item is done through an ajax call by passing the id of the workspace. I have confirmed that $fileid is the correct number.
$this->Workspace->delete($fileid);
Update 2: When I add a column to the permissions table titled 'id' add make its value the appropriate number, then the delete call works fine and all items are deleted. Why is this?

CakePHP retrieving data from model using find(). Different array keys on production server

I have the same exact code on my production and development servers but I seem to get different array keys when using find('first') to retrieve data.
Development:
Array
(
[Page] => Array
(
[title] => Welcome!
[keywords] => keyword 1 keyword 2 keyword 3
)
)
Production:
Array
(
[0] => Array
(
[title] => Welcome!
[keywords] => keyword 1 keyword 2 keyword 3
)
)
Code in AppController:
//get page title and keywords
$currentPage = $this->Page->find('first',
array(
'conditions' => array('Page.name' => $this->params['controller']),
'fields' => array('Page.title', 'Page.keywords')
));
pr($currentPage);
I remember this one... :P I had the same problem before
It's caused either by the php version or the mysql version. Check if your server passes the minimum requirements for your cake version
requirements for cakephp2.0
requirements for cakephp1.3
you can check them using a phpinfo();
Hope this helps
use $this->set(compact('currentPage',$currentPage));

CakePHP - Retrieving and working with data from different tables

I'm sorry, I am a newbie in CakePHP and I am a little bit confused in this subject, let me explain:
I have a relationship between two tables. One of the table is Dose and the other is tank. So, one Tank belongs to a Dose. A Dose has many Tanks. The table schema is:
CREATE TABLE `doses` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`dose` INT(5) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
In my Tank view I have the following code:
<?php echo $form->input('dose_id', array('class'=>'input', 'label' => ''));?>
Each 'dose' (field) from Dose table correspond to a value, such as 200, 300, and so forth. I need to use these numbers to calculate others numbers before to insert into my database (table tank). For instance, my code in tanks_controllers:
$t_u = $this->data['Tank']['tipo_uso_id'];
if( $t_u == '1'){
$this->data['Tank']['producao_adubo_diaria'] = $this->data['Tank']['dose_id'] * 0.10;
.
.
.
However, it is bringing to me the ID of the Dose and not the value (dose field). Where can I set up this to bring me the correct data (dose)? I tried to set up this way in my model:
'Dose' => array(
'className' => 'Dose',
'foreignKey' => 'dose_id',
'conditions' => '',
'fields' => 'dose',
'order' => ''
)
It did not work.
I appreciate your time helping me.
Thanks in advance.
it is bringing to me the ID of the Dose and not the value (dose field). Where can I set up this to bring me the correct data (dose)?
You need to get it from the db (model), not from the view. So you need to do a find(). If you are new to Cake, you should read the cookbook first to see how it works.
What does $form->input('dose_id') produce? A dropdown? If so; by default cake will produce a dropdown with the value containing (dose_)id, and the text you see as the value of $displayField(usually name/title).
To do this; if I understand you, you would need to first query doses for all the values and store the result in an array using the dose value as the key AND the value, rather than the id as you normally would. You would then be able to access the actual dose value from $this->data.
$doseArray=array();
$doses = $this->Dose->find('all');
foreach($doses['Dose'] as $k => $v) {
$doseArray[$v] = $v;
}
perhaps. Seems a bit redundant so I might be off.

CakePHP - problem with saving from select field

i have a problem i can't figure out
in my cake app i have a form that saves multiple data..
one of my input fields is a select field so i have in the view:
echo $form->input('Booking.room_id', array(
'type' => 'select',
'options' => $booking_options
));
where $booking_options is an array that outputs:
Array
(
[23] => Room name1
[24] => Room name2
)
so when i save the form...
the values in the Booking table for room_id are not 23 or 24 but instead they save as 13 and 14
where can be the problem?
Not the answer to your problem, but you should try the Cake way of populating Select boxes properly!
In your controller:
function add() {
$this->set('rooms',$this->Booking->Room->find('list'));
}
In your Form
$this->Form->input('room_id');
This will automatically create a select box with the rooms found in the find('list'), this lowers the chance on errors.
(make sure the 'rooms' table uses the fields 'id' and 'name')

Cakephp Acl error

I try to use alaxos acl plugin for study of Acl code
and I got error
Warning (512): AclNode::node() - Couldn't find Aro node identified by "Array
(
[Aro0.model] => Group
[Aro0.foreign_key] => admin
)
" [CORE\cake\libs\model\db_acl.php, line 191]
Warning (512): DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:
Aro: Array
(
[User] => Array
(
[id] => 76
[username] => tttttt
[group_id] => admin
[active] => 1
[activation_code] =>
[widget_count] =>
[lastvisit] =>
)
)
Aco: Users/add [CORE\cake\libs\controller\components\acl.php, line 273]
Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cakephp\cake\libs\debugger.php:673) [CORE\cake\libs\
My Db picture here
User and Group Model
thank for answer
You should to set basic require data in database
it important for acl component to work right

Resources