【问题标题】:Pass Variable from View to Controller in Codeigniter using PHP使用 PHP 在 Codeigniter 中将变量从视图传递到控制器
【发布时间】:2017-03-27 16:05:26
【问题描述】:

我正在做一个项目,我需要将变量从视图传递到控制器的方法,在该方法中我将使用该变量的值。我尝试了以下方法。

查看

...
$user = 3;
...
<ul class="nav navbar-nav navbar-right">
                <li>
                    <a href="<?php echo base_url() ?>index.php/studentDashboardController/index?user=$user">
                        My Dashboard
                    </a>
                </li>
...

studentDashboardController(方法 1

public function index()
{
    ...
    if ( isset($_GET['user']) ) {
        $user = $_GET['user'];
        echo '<script type="text/javascript">alert("User taken from GET: ' . $user . '")</script>';
    }
    ...

方法 1 的输出

studentDashboardController(方法 2

public function index()
{
    ...
    if($this->input->get())
    {
        $user = $this->input->get('user');
        echo '<script type="text/javascript">alert("Uid taken from Method 2 ' . $user . '")</script>';
    }
    ...

方法 2 的输出

任何有关如何获取此传递变量的值的建议都将受到高度赞赏。

【问题讨论】:

    标签: php codeigniter view controller parameter-passing


    【解决方案1】:

    您在打印 $user 变量时缺少 PHP 表示法。更新视图中的以下行

    <a href="<?php echo base_url() ?>index.php/studentDashboardController/index?user=<?php echo $user; ?>">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      相关资源
      最近更新 更多