Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法筛选cakephp模型中的值_Php_Cakephp_Cakephp Model - Fatal编程技术网

无法筛选cakephp模型中的值

无法筛选cakephp模型中的值,php,cakephp,cakephp-model,Php,Cakephp,Cakephp Model,我创建了一个类别模型。我还创建了一个项目模型。项目模型属于类别模型,因此当您创建新项目时,会收到一个类别下拉列表,以选择所需的类别 其中一个类别是“根”,我不想在下拉列表中显示。我像这样创建了我的belongsTo方法 project.php模型 对于我的控制器,我已打开脚手架 这是我的分类模型 类别模型 我想您的意思是从下拉菜单中删除具有关联的Root?在这种情况下,请尝试以下操作: $categories = $this->Category->find('list',

我创建了一个类别模型。我还创建了一个项目模型。项目模型属于类别模型,因此当您创建新项目时,会收到一个类别下拉列表,以选择所需的类别

其中一个类别是“根”,我不想在下拉列表中显示。我像这样创建了我的belongsTo方法

project.php模型 对于我的控制器,我已打开脚手架

这是我的分类模型

类别模型
我想您的意思是从下拉菜单中删除具有关联的
Root
?在这种情况下,请尝试以下操作:

$categories = $this->Category->find('list', 
                    array('conditions' => array('Category.name !=' => 'Root')));

$this->set(compact('categories'));

改用
'conditions'=>数组('Categories!='=>'1'),

验证用于保存数据,而不是查找数据

class Category extends AppModel {
    var $name = 'Category';
    var $displayField = 'name';
        var $actsAs = array('Tree');

        
    var $validate = array(
        'name' => array(
            'alphanumeric' => array(
                'rule' => array('alphanumeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'parent_id' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'url' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );
        
    var $belongsTo = array(
        'ParentCategory' => array(
            'className' => 'Category',
            'conditions' => '',
                        'foreignKey' => 'parent_id',
            'fields' => '',
            'order' => ''
        ),
    );
}
$categories = $this->Category->find('list', 
                    array('conditions' => array('Category.name !=' => 'Root')));

$this->set(compact('categories'));