单击超链接时将参数从View传递到Controller并从Controller返回参数以查看

时间:2016-12-07 22:24:14

标签: php codeigniter

这是查看文件。我试图将"$row['ISBN'] . ':SearchByAuthor:' . $Author"- abc:SearchByAuthor:aka -值传递给函数increment_author到控制器文件。

<?php
?>
<tr>
    <td><?php
echo $row['ISBN'];
?></td>
    <td><?php
echo $row['name'];
?></td>
    <td><?php
echo $row['title'];
?></td>
    <td><?php
echo $row['year'];
?></td>
    <td><?php
echo $row['price'];
?></td>
    <td><?php
echo $row['publisher'];
?></td>
    <td><?php
echo $row['number'];
?></td>
    <td> <a href="<?php
echo base_url();
?>/increment_author/<?php
echo $row['ISBN'] . ':SearchByAuthor:' . $Author;
?>">
    Add to cart</a></td>
</tr>
<?php
?>

这是控制器文件,我正在做一些计算,并尝试返回上面的搜索页面,这是视图。但是,它不起作用。我试图将本机PHP代码转换为codeIgniter框架。请帮助我将参数从Controller传递到View,反之亦然。在此先感谢

   public function increment_author($SearchByAuthor)
    {
        session_start();

    $db = new mysqli('localhost','root','','cheapbook') or die('Error connecting to MySQL server.');
     mysqli_set_charset($db, 'utf8');


    if(isset($SearchByAuthor))
        {
    //        echo $_GET['add'];
            $pieces=explode(":", $SearchByAuthor);

            $quantity="SELECT D.ISBN, D.title, sum(D.number) number FROM
            (SELECT A.ISBN, title, number number FROM 
            book A, Stocks B  WHERE A.ISBN='$pieces[0]' and
            A.ISBN=B.ISBN)D
            GROUP BY D.ISBN, D.title";

            $result = mysqli_query($db,$quantity);



            while($quantity_row = mysqli_fetch_array($result))
            {
                if($_SESSION['cart_'.$pieces[0]])
                {
                    $chan=0;
                }
                else 
                {
                    $_SESSION['cart_count']+=1;
                }
                if($quantity_row['number']!=$_SESSION['cart_'.$pieces[0]] )
                {
                        $_SESSION['cart_'.$pieces[0]]+=1;
                        $_SESSION["cartTotal"]+=1;

                }
            }
            $data['SearchByAuthor']=$pieces[0];
        }
        //header("location:search_vi?SearchByAuthor=".$pieces[0]);
        //$data['SearchByAuthor']=$pieces[0];
        $this->load->view('search',$data);

    }

1 个答案:

答案 0 :(得分:0)

您不必使用 session_start ,实际上您应该使用Session Library。 CI中还有一个完整的Database层。

尝试更详细地调试您的问题。检查您的$ data变量是否包含正确的结果,并且在您的视图中,这将通过$ SearchByAuthor变量显示。