duanhuang7591 2015-12-09 07:58
浏览 40

如何在CakePHP中连接字符串值

I've created a simple shopping cart app that uses ajax, my problem is that I want to pass the value from the session and concatenate it in a single string but it doesn't add the strings it only replaces the old value. Can anyone there have any idea to do this? thanks...

my CartsController.php is

    <?php

App::uses('AppController', 'Controller');

class CartsController extends AppController {

    public $uses = array('Timezone');
    public $helpers = array('Html', 'Js' => array("JQuery"), "Session");
    public $components = array('RequestHandler', 'Session');

    public function beforeFilter() {
        parent::beforeFilter();

        if ($this->request->is('ajax')) {
            $this->layout = 'ajax';
        }
    }


    public function viewcart() 
    {
            $this->loadModel('Cart');
            $data = $this->Cart->find('all');
            $this->set('dbdata',$data);
    }

    public function ajax_get_cart() 
    {
        $this->request->onlyAllow('ajax'); 

        //$content = '<div class="alert alert-warning" role="alert">Something unexpected occured</div>';
        if ($content = "")
        {   
            $tempcontent = "";
        }   

        if ($this->request->is('post')) 
        {       
            $this->Timezone->set($this->request->data);
            $ccode = $this->request->data['Cart']['code'];
            $cname = $this->request->data['Cart']['name'];
            $cprice = $this->request->data['Cart']['price'];

            $cartcode[0] = '1';
            $cartcode[1] = 'cart.code2';
            $cartcode[2] = 'cart.code2';

                $this->Session->write(1, $ccode);
                $this->Session->write(2, $cname);
                $this->Session->write(3, $cprice);

                $content .= $this->Session->read(1) . $this->Session->read(2) . $this->Session->read(3);

        }
        else
        {
            $content = "";
        }

        $this->set(compact('content')); 
        $this->render('ajax_response', 'ajax'); 

    }

    public function view()
    {   
            $this->loadModel('Cart');
            $data = $this->Cart->find('all');
            $this->set('dbdata',$data);

    }
}   
?>
  • 写回答

1条回答 默认 最新

  • douran9707 2015-12-09 10:47
    关注

    You are using numeric type instead of strings or arrays to store your session data.

    The CakeSession::write() function is defined as follows:

    write( string|array $name , string $value null ) 
    

    Try using strings instead:

    $this->Session->write('ccode', $ccode);
    $this->Session->write('cname', $cname);
    $this->Session->write('cprice', $cprice);
    
    $content .= $this->Session->read('ccode') . $this->Session->read('cname') . $this->Session->read('cprice');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答