无限级分类问题
无限级分类 我现在知道最底部节点 也就是知道
用一个方法找出所有的父节点!谢谢
回复内容:
无限级分类 我现在知道最底部节点 也就是知道
用一个方法找出所有的父节点!谢谢
如果你问的是如何用一句 SQL 语句来找出所有的父节点的话,join 可能可以实现,但是不建议用数据库实现。一是尽量减小粒度(虽然实践表明绝大多数的减小粒度都是无用功),使其便于修改;二是这样会给数据库造成较大压力,使流程处理时间大幅增加,数据库不擅长逻辑处理,更擅长简单的取。
如果你问的是如何在一个方法中取出,高级语言有一个普遍的语法特性,叫 递归,说白了就是自己调用自己。
我们来构思一下实现方式(php语言为例):
$father = ""; public function get_all_father($son_of_son) { global $father; if (找他爹($son_of_son)) { $他爹 = 找他爹($son_of_son); $father = $father.'.'.$他爹; //以 . 隔开一层一层的father get_all_father($他爹); } return $father.'.'.$son_of_son; } public function 找他爹($儿子) { if (在数据库里找到($儿子)的爹了) { return 他爹; } else { return FALSE; } } //特别声明,除了那一句 “在数据库里找到($儿子)的爹了” 和 “return 他爹;” 是我简写了以外,其他代码都是可以运行的,没错,汉字也行,以utf-8编码保存就行。
这只是一个思路,离实际能在symfony里运行的代码还有很大差距。当然这是在两个function里实现的,你可以把下面那个function缩成一行放在上面的里面......
按存储结构不同,这个要看你的表格结构,不能靠猜的。
常见的有,链表式的必须递归回溯,左右值式的所有超集并按左值排序。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
