使用Codeigniter会话库时,我无法理解一个问题.相同的网络用户使用相同的会话(我们与一家大公司合作,他们这样说:当有人登录系统,然后每个人都登录)!这可能吗?如何以及如何解决此问题?
我正在使用Codeigniter核心会话库,它使用数据库.
我是CodeIgniter的新手并完成了我的第一个项目.但是,在我把它放在我的托管网站上之前,我想使用CodeIgniter在config文件夹中提供的routes.php文件来清理URL.
我的网站将使用以下网址加载:
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/home
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/about
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/services
Run Code Online (Sandbox Code Playgroud)
它还将使用以下默认控制器URL加载主页: http://fakehost:8888/TheWorksPlumbing/
但是,我希望网站的每个页面都有一个网址,但无法让它工作.例如,我想:
http://fakehost:8888/TheWorksPlumbing/home
http://fakehost:8888/TheWorksPlumbing/about
http://fakehost:8888/TheWorksPlumbing/services
Run Code Online (Sandbox Code Playgroud)
以下是theWorksPlumbingController控制器文件的代码:
class TheWorksPlumbingController extends CI_Controller {
public function index($page = 'home'){
if ( !file_exists('application/views/'.$page.'.php') ) {
show_404();
}
$this->load->view('templates/header');
$this->load->view($page);
$this->load->view('templates/footer');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的routes.php文件中的代码不起作用:
$route['default_controller'] = "theWorksPlumbingController";
$route['404_override'] = '';
$route['(:any)'] = "index.php/theWorksPlumbingController/index";
Run Code Online (Sandbox Code Playgroud)
我需要添加或更改以使网站只加载/ home或/ about或/ services?
例如,我将加载像(顺便说一句.我认为只有这两个中的第一个,英语将加载其他被忽略的语言):
$this->lang->load('module_messages', 'english');
$this->lang->load('module_messages', 'czech');
Run Code Online (Sandbox Code Playgroud)
但我只能使用这样的东西:
echo $this->lang->line('language_key');
Run Code Online (Sandbox Code Playgroud)
这不起作用:
echo $this->lang->line('language_key', 'english');
Run Code Online (Sandbox Code Playgroud)
知道如何在同一视图中同时回显两种语言翻译,如:
echo $this->lang->line('language_key', 'english');
echo $this->lang->line('language_key', 'czech');
Run Code Online (Sandbox Code Playgroud)
怎么实现这样的事情?
我编写用于上传图像文件的代码.但它始终显示You did not select a file to upload.这是我的代码.
视图
<?php echo form_open_multipart('template/advertisement', array('id' => 'template-add-form', 'class' => 'form-horizontal')); ?>
<?php echo form_fieldset('Add Advertisement', array('class' => '')); ?>
<div class="control-group">
<label class="control-label" for="add_l">Left Advertisement </label>
<div class="controls">
<input type="file" name="add_l"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" name="add" value="Update Advertisement" class="btn btn-primary" />
</div>
</div>
<?php echo form_fieldset_close(); ?>
<?php echo form_close(); ?>
Run Code Online (Sandbox Code Playgroud)
调节器
public function advertisement()
{
$headerData = array();
$headerData['title'] = ucfirst('Advertisement');
$data = array();
if …Run Code Online (Sandbox Code Playgroud) 我使用聚合和管道查询我的数据库,有两个单独的查询:
$groups_q = array(
'$group' => array(
'_id' => '$group_name',
'total_sum' => array('$sum' => 1)
)
);
$statuses_q = array(
'$group' => array(
'_id' => '$user_status',
'total_sum' => array('$sum' => 1)
)
);
$data['statuses'] = $this->mongo_db->aggregate('users',$statuses_q);
$data['groups'] = $this->mongo_db->aggregate('users',$groups_q);
Run Code Online (Sandbox Code Playgroud)
我得到了我想要的东西:
Array
(
[statuses] => Array
(
[result] => Array
(
[0] => Array
(
[_id] => Inactive
[total_sum] => 2
)
[1] => Array
(
[_id] => Active
[total_sum] => 5
)
)
[ok] => 1
)
[groups] => Array …Run Code Online (Sandbox Code Playgroud) 我有这个应用程序具有以下结构

我正在使用rest客户端库 https://github.com/philsturgeon/codeigniter-restclient 连接到MyAPI并使用php api客户端 http://code.google.com/p/google-api-php-client/进行连接到Google API
我的控制器代码如下
function index()
{
if($this->form_validation->run())
{
$logged = $this->rest->get('auth/user',array(
'email'=>$this->input->post('email')
));
var_dump($logged);
}
$this->load->view('layout/login',$this->data);
}
Run Code Online (Sandbox Code Playgroud)
我处理此请求的API代码如下所示,以确保用户存在于我的数据库中并通过Google进行身份验证
function user_get()
{
$response=NULL;
$data=array(
'email'=>$this->get('email')
);
$google_account=$this->google->authenticate();
if( isset($google_account) && $this->user_model->login($data))
{
$response->status='success';
$response->message=$google_account;
}
else
{
$response->status='error';
$response->message='Failed to authenticate user';
}
$this->response($response,200);
}
Run Code Online (Sandbox Code Playgroud)
和Google库函数`Authenticate'如下
function authenticate()
{
$oauth2 = new Google_Oauth2Service($this->client);
if (isset($_GET['code']))
{
$this->client->authenticate($_GET['code']);
$_SESSION['token'] = $this->client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: …Run Code Online (Sandbox Code Playgroud) 我想删除一些像核心PHP中的查询这样的数据
WHERE user_id=$id AND sender_id=$send_id OR user_id=$send_id AND sender_id=$id
Run Code Online (Sandbox Code Playgroud)
所以我在CodeIgniter中尝试使用Active Record,如下所示:
$this->db->where('user_id ', $id);
$this->db->or_where('user_id ', $send_id);
$this->db->where('sender_id ', $send_id);
$this->db->or_where('sender_id ', $id);
Run Code Online (Sandbox Code Playgroud)
但它给了我错误的结果.我究竟做错了什么?
我会在codeigniter中设置会话值
$sess_array = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
'postid'=> $row->Fk_Post_Id,
);
$CI->session->set_userdata('logged_in', $sess_array);
Run Code Online (Sandbox Code Playgroud)
然后如何检索特定(说 - id)会话值.我试过这些
$createdby=$this->session->userdata('id');
$createdby=$this->session->userdata($logged_in['id']);
Run Code Online (Sandbox Code Playgroud)
但失败了.
我正在使用CodeIgniter和PHPExcel来读取和写入excel文件.
在localhost中一切正常,但是当我将我的PHP CodeIgniter应用程序上传到pagodabox中的服务器时,当我尝试从excel文件中读取数据时,我得到了以下消息.
Fatal error: Uncaught exception 'Exception' with message 'ZipArchive library is not enabled' in /var/www/application/libraries/PHPExcel/Reader/Excel2007.php
Run Code Online (Sandbox Code Playgroud) 我不是专业人士,但我知道我的PHP方式,我是Codeigniter的新手.
正在浏览这些教程:http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-5-crud/
好的,所以我有一个列出用户的页面,点击用户名将进入编辑页面,该页面的URL为:index.php/users/edit/1(其中1是用户ID)
在编辑页面上是一个表单,这个表单包含几个部分,每个部分都是从DB中的不同表填充的.所以我的Controller编辑如下:
function edit() {
//load model
$this->load->model('users_model');
//assign user data from DB
$data['data_user'] = $this->users_model->getUser($this->uri->segment(3));
//get users Password, using username from above
$data['data_user_password']= $this->users_model->getUserPassword($data['data_user'][0]->UserName);
$data['page_content'] = 'pages/users_edit';
$this->load->view('template/template', $data);
}
Run Code Online (Sandbox Code Playgroud)
注意:
$data['data_user']包含用户数据,如名称,用户名,电子邮件
$data['data_user_password']包含来自不同表的用户密码
然后我可以填写表单,在users_edit.php上,这一切都正常.我通过执行以下操作来访问此数据:
if (is_array($data_user)) {
foreach($data_user as $user)
{
$userID = $user->id;
$userName = $user->Name;
$userUserName = $user->UserName;
$userMail = $user->Mail;
$userDepartment = $user->Department;
$userWorkPhone = $user->WorkPhone;
$userHomePhone = $user->HomePhone;
$userMobile = $user->Mobile;
}
}
//user password
if (is_array($data_user_password)) { …Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×10
api ×1
file-upload ×1
mongodb ×1
mongodb-php ×1
mysql ×1
pecl ×1
phpexcel ×1
rest ×1
routing ×1
session ×1
web-services ×1
ziparchive ×1