duanlu0075 2017-07-12 13:16
浏览 127
已采纳

Fat Free框架动态路由不起作用

I am trying to get variable from URL to pass to the Controller

The URL looks like this http://example.org/MyCategory or http://example.org/MyCategory-1

My DB contains table for all categories that includes category_slug column

The route is GET /@category_slug = MainController->CategorySlug

My main controller has method that supposed to handle this, which should invoke method getBySlug() from the Categories model

Main Controller

function CategorySlug($category_slug){
    $categories = new Categories($this->db);
    $cat = $categories->getBySlug($category_slug);

    $this->f3->set('categories',$cat);
    echo \Template::instance()->render('index.html');
}

Categories Model

public function getBySlug($category_slug)
{
    $this->load(array('category_slug=?', $category_slug));
    return $this->query;
}

As you see from the code above, I am passing variable $category_slug, but have an error

  • 写回答

1条回答 默认 最新

  • douxigai8757 2017-07-12 16:49
    关注

    @AlexB, what error are you getting?

    However, you need to pick up the variable from the URL before you pass it to your methods;

    $category_slug = $this->f3->get('PARAMS.category_slug')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错