求助,除了默认控制器,其他控制器给视图传参数无效
本帖最后由 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什么的都设置好了
就这么简单,把不相关的代码删掉了,还不行
本帖最后由 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一下,是空的 可以了已经,控制器调用有点问题,不过表单传不了
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');
}
} 你把我的"全部代碼"複製貼上你的控制器試試
<?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);
}
}
?>
把你不行的控制器程式碼全部貼上來 错误显示:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: qqq
Filename: views/file2db_view.php
Line Number: 10 本帖最后由 Closer 于 2015-1-5 10:40 编辑
class File2db extends CI_Controller
第一字碼要大寫
手冊的命名規則有提到
而且你第一個方法名也寫錯了
一般都是
class Test extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index(){
}
}
本帖最后由 woody8378 于 2015-1-5 10:42 编辑
改过了还是不行默认控制器 就没大写 就可以用
woody8378 发表于 2015-1-5 10:40
改过了还是不行默认控制器 就没大写 就可以用
默認的有大寫好不?
class Welcome extends CI_Controller { 你改貼錯誤訊息好了...
這樣跟你雞同鴨講也不是辦法 本帖最后由 woody8378 于 2015-1-5 10:46 编辑
Closer 发表于 2015-1-5 10:43
默認的有大寫好不?
class Welcome extends CI_Controller {
默认我已经改掉了,不是welcome,
而且我改配置把默认变成file2db就好了,一点问题没有
错误信息:
A PHP Error was encounteredSeverity: NoticeMessage: Undefined variable: qqqFilename: views/file2db_view.php
woody8378 发表于 2015-1-5 10:45
默认我已经改掉了,不是welcome,
而且我改配置把默认变成file2db就好了,一点问题没有
那你的 route 檔
除了預設還有多寫甚麼嗎?
$route['default_controller'] = "welcome";
$route['404_override'] = '';