我想在另一个内部使用控制器函数名称,因此它看起来好像是一个子url。我该怎么做呢?
示例:
CREATE FUNCTION isInArea(p POINT, poly POLYGON)
RETURNS INT(1)
DETERMINISTIC
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE pX DECIMAL(9, 6);
DECLARE pY DECIMAL(9, 6);
DECLARE ls LINESTRING;
DECLARE poly1 POINT;
DECLARE poly1X DECIMAL(9, 6);
DECLARE poly1Y DECIMAL(9, 6);
DECLARE poly2 POINT;
DECLARE poly2X DECIMAL(9, 6);
DECLARE poly2Y DECIMAL(9, 6);
DECLARE i INT DEFAULT 0;
DECLARE result INT(1) DEFAULT 0;
SET
pX = X(p);
SET
pY = Y(p);
SET
ls = ExteriorRing(poly);
SET
poly2 = EndPoint(ls);
SET
poly2X = X(poly2);
SET
poly2Y = Y(poly2);
SET
n = NumPoints(ls); WHILE i < n DO
SET
poly1 = PointN(
ls,
(i + 1)
);
SET
poly1X = X(poly1);
SET
poly1Y = Y(poly1); IF (
(
(
(poly1X <= pX) && (pX < poly2X)
) || (
(poly2X <= pX) && (pX < poly1X)
)
) && (
pY > (poly2Y - poly1Y) * (pX - poly1X) / (poly2X - poly1X) + poly1Y
)
) THEN
SET
result = ! result; END IF;
SET
poly2X = poly1X;
SET
poly2Y = poly1Y;
SET
i = i + 1;
END WHILE;
RETURN result;
End;
目前如果我想调用bananas()函数,url将如下所示:
example.com/food/bananasa
我希望它看起来像这样:
example.com/food/fruits/bananas
example.com/food/fruits/apples
答案 0 :(得分:2)
在routes.php
$route['food/fruits/bananas'] = 'food/bananasa';
$route['food/fruits/apples'] = 'food/apples';
添加如下
答案 1 :(得分:1)
您可以创建{@ 1}}定义,例如@Abdulla,或者您可以重新构建控制器文件夹,更改此内容:
$route
到此:
controllers
-> food.php
-> animals.php
这样做会将您的网址变为controllers
-> food
-> fruits.php
-> vegetables.php
-> animals
-> pets.php
-> wild.php
答案 2 :(得分:1)
如果您有永久性结构, 重新映射功能应该有助于更改代码。
public function _remap($method)
{
if ($method == 'some_method')
{
$this->$method();
}
else
{
$this->default_method();
}
}
参考:https://codeigniter.com/userguide3/general/controllers.html?highlight=remap#remapping-method-calls
添加:您可以使用父类使其成为构造函数,然后调用
parent::__construct();
在你班上。