用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2830|回复: 28
收起左侧

求助,除了默认控制器,其他控制器给视图传参数无效

[复制链接]
发表于 2015-1-5 10:02:49 | 显示全部楼层 |阅读模式
本帖最后由 woody8378 于 2015-1-5 10:37 编辑

试过了,默认控制器可以的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class file2db extends CI_Controller
{
        function file2db()
        {
                parent::__construct();
        }

        public function index()
        {
               $data['qqq'] = "asda";
                $this->load->view('file2db_view' , $data);
        }
}
?>
视图:
<!DOCTYPE html>
<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<div id="container">
<?php
echo $qqq;
?>
</div>

</body>
</html>




而且表单数据也传不了

nginx1.4.7的 path_info什么的都设置好了

就这么简单,把不相关的代码删掉了,还不行
 楼主| 发表于 2015-1-5 11:15:21 | 显示全部楼层
本帖最后由 woody8378 于 2015-1-5 11:20 编辑

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class file2db extends CI_Controller
{

        function file2db()
        {
                parent::__construct();
      
                $this->load->helper('form');
                $this->load->model('file2db_model');
        }

        public function index()
        {
                $this->load->view('file2db_view');
        }

        public function modify_db()
        {
                $data['qqq'] = $this->input->post('path');
                //$this->file2db_model->new_db();
                $this->load->view('file2db_view', $data);
        }
}
?>

<!DOCTYPE html>

<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
</head>
<body>

<div id="container">
<?php
        echo $qqq;
        echo form_open('file2db/modify_db');

?>
<input type='text' id='path' name='path' />
<input type='submit' id='new' name='new'/>
</form>

</div>

</body>
</html>

提交了之后,echo一下,是空的
 楼主| 发表于 2015-1-5 10:52:13 | 显示全部楼层
可以了已经,控制器调用有点问题,不过表单传不了
view:
<!DOCTYPE html>

<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<div id="container">

<?php
        echo form_open('http://localhost/query_sys/index.php/file2db');
?>
<input type='text' id='path' name='path' />
<input type='submit' id='new' name='new'  />
</form>

</div>

</body>
</html>

控制器:
class file2db extends CI_Controller
{

        function file2db()
        {
                parent::__construct();

                $this->load->helper('form');

        }

        public function index()
        {
                $handle = fopen($this->input->post('path'), 'r');
        }

}
发表于 2015-1-5 10:52:26 | 显示全部楼层
你把我的"全部代碼"複製貼上你的控制器試試

PHP复制代码
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class File2db extends CI_Controller {
 
        function __construct() {
                parent::__construct();
        }
 
        public function index(){
                $data['qqq'] = "asda";
                $this->load->view('file2db_view' , $data);
        }
 
}
?>
 
复制代码
发表于 2015-1-5 10:23:43 | 显示全部楼层
把你不行的控制器程式碼全部貼上來
 楼主| 发表于 2015-1-5 10:36:11 | 显示全部楼层
错误显示:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: qqq

Filename: views/file2db_view.php

Line Number: 10
发表于 2015-1-5 10:38:25 | 显示全部楼层
本帖最后由 Closer 于 2015-1-5 10:40 编辑

class File2db extends CI_Controller
第一字碼要大寫
手冊的命名規則有提到

而且你第一個方法名也寫錯了
一般都是
PHP复制代码
 
class Test extends CI_Controller {
 
        function __construct() {
                parent::__construct();
        }
 
        public function index(){
 
        }
 
}
 
复制代码


 楼主| 发表于 2015-1-5 10:40:44 | 显示全部楼层
本帖最后由 woody8378 于 2015-1-5 10:42 编辑

改过了还是不行默认控制器 就没大写 就可以用
发表于 2015-1-5 10:43:32 | 显示全部楼层
woody8378 发表于 2015-1-5 10:40
改过了还是不行默认控制器 就没大写 就可以用

默認的有大寫好不?
class Welcome extends CI_Controller {
发表于 2015-1-5 10:45:01 | 显示全部楼层
你改貼錯誤訊息好了...
這樣跟你雞同鴨講也不是辦法
 楼主| 发表于 2015-1-5 10:45:16 | 显示全部楼层
本帖最后由 woody8378 于 2015-1-5 10:46 编辑
Closer 发表于 2015-1-5 10:43
默認的有大寫好不?
class Welcome extends CI_Controller {

默认我已经改掉了,不是welcome,
而且我改配置把默认变成file2db就好了,一点问题没有

错误信息:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: qqq

Filename: views/file2db_view.php


发表于 2015-1-5 10:47:34 | 显示全部楼层
woody8378 发表于 2015-1-5 10:45
默认我已经改掉了,不是welcome,
而且我改配置把默认变成file2db就好了,一点问题没有

那你的 route 檔
除了預設還有多寫甚麼嗎?
PHP复制代码
 
$route['default_controller'] = "welcome";
$route['404_override'] = '';
 
复制代码

本版积分规则