drpkcwwav20524605 2014-11-14 12:58
浏览 94
已采纳

codeigniter可以支持内联函数吗?

Can we write multiple functions inside another function in Codeigniter.? here is my controlller

class Products extends CI_Controller {

  public function myproduct() {
      $this->load->view('myproduct'); // call myproduct.php

           public function features() {
              $this->load->view('features');  // call "myproduct/features"
            }

           public function screenshots() {
              $this->load->view('screenshots');  // call "myproduct/screenshots"
            }
    }
}

as per my controller there are 2 inline functions inside myproduct(). my aim isto display the url as

localhost/mysite/products/myproduct
localhost/mysite/products/myproduct/features
localhost/mysite/products/myproduct/screenshots

i already tried it but it gives me a error

Parse error: syntax error, unexpected 'public' (T_PUBLIC) in D:\...........\application\controllers\mysite\products.php on line 5

and the line 5 was

public function features() { .........
  • 写回答

3条回答 默认 最新

  • doubengman2072 2014-11-14 13:05
    关注

    You can just treat this as a uri paramater in the url:

    public function myproduct($param = null) 
    {
        if($param == null) {
            $this->load->view('myproduct'); 
        } elseif($param == 'features') {
            $this->load->view('features');
        } elseif ($param == 'screenshots') {
            $this->load->view('screenshots');
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失