嘿所以我一直在尝试创建一个RESTful API使用codeigniter 2.1.4.
我是一名中级php程序员,最初辩论从头开始创建API.
然而,经过一些研究,在这里和谷歌上查看旧问题,我选择了几个教程和第三方库.
我在nettuts +上发现的最简单的一个.
这看起来是一个很好的解决方案,因为它使用了philsturgeon/codeigniter-restserver第三方库,但是它自己的教程是在2010年编写的.
经过进一步检查,我意识到使用这些库的大多数教程至少有2到3年的历史.这会引发任何问题吗?
我还可以在nettuts上关注教程+或者我应该编写自己的RESTful API吗?
我想请一些帮助.我创建了一个动态菜单导航栏,显示符合我设置顺序的菜单项.我正在使用这个nestedsortable插件,来订购我的菜单项,但目前我的菜单只有2个级别,所以基本上它是这样的:
Item1
Item2
> Subitem2.1
> Subitem2.2
Item3
etc etc.
Run Code Online (Sandbox Code Playgroud)
我想做的是用n级制作它,所以基本上是这样的:
Item1
Item2
> Subitem2.1
>> Subitem2.1.1
> Subitem2.2
Item3
etc etc.
Run Code Online (Sandbox Code Playgroud)
并且每个项目都可以达到n级深度.问题是,如果我将新订单设置为超过2级深度的菜单项,则会出现错误,订单不会存储在数据库中.我该怎么办呢?
数据库结构是这样的:
table: Menu
id (pk)
menu_item
parent_id // it is the id of the parent menu item
order
Run Code Online (Sandbox Code Playgroud)
这是我的主要(模型)功能:
// save the order of the menu items
public function save_order($items){
if (count($items)>0) {
foreach ($items as $order => $item) {
if ($item['item_id'] != '') {
$data = array(
'parent_id' => (int)$item['parent_id'],
'order' => $order
); …Run Code Online (Sandbox Code Playgroud) 我几乎完成了一个使用codeigniter和ion_auth进行身份验证的项目.我无法弄清楚这个小问题:
当用户想要更改密码时,我有字段OLD_PASSWORD和NEW_PASSWORD.OLD_PASSWORD必须匹配数据库的密码(DB_PASSWORD).但我无法弄清楚密码是如何加密存储在数据库中的.所以OLD_PASSWORD显然永远不会匹配DB_PASSWORD.
我没有更改ION_AUTH库的任何默认加密.我尝试了sha1()函数,它与加密不匹配.同样适用于md5(),不建议再用于加密密码.
任何人都可以为我照亮这个吗?
我正在编写一个自定义的post_controller钩子.我们知道,codeigniter uri结构是这样的:
example.com/class/function/id/
Run Code Online (Sandbox Code Playgroud)
和我的代码:
function hook_acl()
{
global $RTR;
global $CI;
$controller = $RTR->class; // the class part in uri
$method = $RTR->method; // the function part in uri
$id = ? // how to parse this?
// other codes omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
我浏览了核心的Router.php文件,这让我很困惑.
谢谢.
我知道如何在核心PHP中创建会话,我已经了解如何在codeigniter中执行此操作,但我无法理解如何检查,如果会话已设置?我试图通过View检查这个,但它总是给我meesage Please Login.
请告诉我如何检查会话是否设置
调节器
if ($user_type=='Student')
{
if ($LoginData= $this->loginmodel->studentLogin($username,$password))
{
foreach($LoginData as $UserId)
{
$currentId= $UserId->StudentId;
}
//[[session]]
$data['students_data']= $this->loginmodel->student_profile($currentId);
$this->session->userdata('$data');
$this->load->view('students',$data);
}
else
{
//$data['message']= array('Invalid Username or Password');
$this->load->view('Login');
echo "Invalid Username or Password";
}
}
elseif ($user_type=="Faculty")
{
if($data['faculty_data']=$this->loginmodel->faculty_admin($username, $password))
{
$this->session->userdata('$data');
$this->load->view('faculty');
}
else
{
$this->load->view('Login');
echo "Invalid Username or Password";
}
}
Run Code Online (Sandbox Code Playgroud)
视图
<?php
if (!$this->session->userdata('$data'))
{
echo "Please Login";
}
else
{
}
?>
<!DOCTYPE
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用account/verify_credentials和statuses/updateAPI.我总是收到错误202,请看下面返回的错误:
{"errors":[{"code":220,"message":"您的凭据不允许访问此资源."}]}
我正在开发一个类别模块,我正在使用CI验证规则.当验证规则失败时,我希望表单具有用户输入的相同值.我已经使用set_value函数在验证规则失败后加载表单中的值.但每次验证失败时,该值都将设置为空白.
这是我的代码.我在构造函数中设置了验证规则.
$this->form_validation->set_rules($this->validation_rules);
if ($this->input->post()) {
$db_array=array(
'CategoryName' => $this->input->post('CategoryName'),
'ParentID' => $this->input->post('ParentID'),
'Status' => $this->input->post('Status')
);
if($this->form_validation->run() != false){
if($id)
{
$result = $this->category_m->update($db_array,$id);
if(isset($result['error'])&& count($result['error']>0))
{
foreach($result['error'] as $error)
{
$this->session->set_flashdata('error',$error);
}
}
if($result['success'])
{
$action['class'] = 'success';
$action['msg'] = 'Data added successfully.';
$this->session->set_flashdata('success',$action);
}
else
{
$action['class'] = 'error';
$action['msg'] = 'Invalid values to the form!';
$this->session->set_flashdata('error',$action);
}
}
else
{
$result = $this->category_m->insert($db_array);
if(isset($result['error']) && count($result['error']>0))
{
foreach($result['error'] as $error)
{
$this->session->set_flashdata('error',$error);
}
}
if($result['success'])
{ …Run Code Online (Sandbox Code Playgroud) 在我的数据库中,它是一个表:tab_companies和一个company_phone(大整数)列,其中defalut值设置为NULL.
当有人填写表单并将电话号码字段留空时Code Igniter应该向数据库添加NULL值,但我总是将值设置为'0'.
public function add_company()
{
$data = array(
'company_short-name' => $this->input->post('company_short-name'),
'company_full-name' => $this->input->post('company_full-name'),
'company_phone' => $this->input->post('company_phone'),
'company_address' => $this->input->post('company_address'),
);
return $this->db->insert('tab_companies', $data);
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我正在使用带有数据表的codeigniter,我想按列排序选择.
我怎样才能做到这一点 ?
$this->datatables->select('col_1, col_2, col_3');
$this->datatables->from('table');
....$this->datatables->order ?!?
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在使用PHP中的搜索系统,它将搜索到的文本添加到数组中,并使用json_encode()将其放入cookie中.
问题是:我需要检查cookie是否已经存在,如果没有,则创建它.
我正在使用以下代码来验证它是否存在但没有成功:
{
$search = $this->input->post('search_text');
$types = $this->input->post('search_type');
$checkboxes = "";
if(!empty($types))
{
foreach($types as $v)
$checkboxes = $v.",";
}
//cookie
$this->load->helper('cookie');
//cookie's array
$search_history = array();
array_push($search_history, $search);
//cookie check 1
if(get_cookie('search')!=''){
echo "cookie exists";
}else
echo "cookie doesn't exist";
// set cookie
$cookie = array(
'name' => 'search',
'value' => json_encode($search_history),
'expire' => time()+86500
);
set_cookie($cookie);
//cookie check 2
if(get_cookie('search')!=''){
echo "cookie exists";
}else
echo "cookie doesn't exist";
//echo get_cookie('search');
//redirect('search/'.urlencode($search).'/'.urlencode($checkboxes));
}
Run Code Online (Sandbox Code Playgroud)
我可以创建cookie并获得它的价值,但我似乎无法找到一种方法来检查它是否已经在PHP代码中创建.
已经尝试过:
if(get_cookie('search')!='')
Run Code Online (Sandbox Code Playgroud)
, …
codeigniter ×10
php ×9
mysql ×2
cookies ×1
database ×1
datatables ×1
forms ×1
hook ×1
html ×1
ion-auth ×1
navigation ×1
nested ×1
pyrocms ×1
rest ×1
session ×1
setvalue ×1
twitter ×1
validation ×1