我是新手来构建数据库,而我正在尝试基于拥有三个数据库表来进行JOIN.
Table A = ID, Name, etc
Table B = ID, Name, etc
Table C = ID, TableAId, TableBId
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚的是使用活动记录如何进行此选择.我试图尽可能少地提出请求,但是如果不进行三次单独的调用就应该写下这些请求.
我有ExtJS从combofield发布数据到CodeIgniter.CodeIgniter读取发布的数据并运行db-> insert以更新mssql数据库.
问题是,如果用户没有从组合框中选择一个选项,它将被发送到CodeIgniter,则Codeignighter会将这条发布的数据作为空字符串读取并尝试将其写入数据库中的int字段,从而导致错误.
我相信我需要CodeIgniter将字符串视为NULL(如果它为空)和数字(如果是空的话).我已经尝试使用php类型juggling(int)来转换它但它使它为0.这是一个无效的值,因为它与我的数据库中我的一对多int字段中的任何选择都不匹配.
有没有办法让CodeIgniter将空字符串视为NULLS而不是空字符串?
[编辑添加代码]
{
//ExtJS combo object
xtype: 'combo',
id: 'Referrer',
store: new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/referrals/index.php/referrers/read',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
root: 'results',
fields: [
{name: 'ID'},
{name: 'Referrer'}
]
})
}),
displayField: 'Referrer',
valueField: 'ID',
value: 1,
typeAhead: true,
hiddenName: 'Referrers_ID',
mode: 'remote',
triggerAction: 'all',
fieldLabel: 'Referrer',
selectOnFocus: true,
anchor: '100%'
}
//CI CODE TO GRAB FROM POST INTO AN ARRAY THEN OUT TO THE DB
public function create(){
$data = array( …Run Code Online (Sandbox Code Playgroud) 我可以在codeigniter中打印会话值print_r($this->session->userdata);
我如何在codeigniter中打印cookie?我刚刚设置了一个cookie:
$cookie = array(
'name' => 'test_cookie',
'value' => 'test',
'domain' => '/',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
Run Code Online (Sandbox Code Playgroud)
我该如何打印上述cookie?
我正在为我的项目使用codeigniter,我有这个类模型,我称之为Genesis,如下所示:
class Genesis_model extends CI_Model {
function __construct() {
parent::__construct();
}
function get() {
return 'human soul';
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个模型,存储在同一目录中,扩展了Genesis_model
class Human_model extends Genesis_model {
function __construct() {
parent::__construct();
}
function get_human() {
return $this->get();
}
}
Run Code Online (Sandbox Code Playgroud)
Human_model由Human控制器使用
class Human extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('human_model');
}
function get_human() {
$data['human'] = $this->human_model->get_human();
$this->load->view('human/human_interface', $data);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我执行代码,它将产生一个错误,指向返回$ this-> get().它显示"致命错误:在第2行的......\application\models\human_model.php中找不到类'Genesis_model'".
我使用这种方法是因为几乎所有模型都共享几乎相同的结构.我在Genesis中收集了类似的功能,而其他模型仅作为它们所代表的表所特有的数据供应商.它在我的asp.net(vb.net)中运行良好,但我不知道如何在codeigniter中执行此操作.
有没有办法让Human_model继承Genesis_model.我不认为我可以使用include('genesis_model.php').我不知道它是否有效.
提前致谢.
如何将一些ajax数据发布到控制器功能并将其恢复?因为我想将一个整数发布到函数中,并获得另一个整数(对于发布ID的项目的总投票数),并且在成功时我想要回显该投票计数.我不知道如何将"id"发布到控制器功能.请看我的代码:
//post this integet
the_id = $(this).attr('id');
$.ajax({
type: "POST",
data: the_id,
url: "http://localhost/test/index.php/data/count_votes",
success: function(){
//the controller function count_votes returns an integer.
//echo that with the fade in here.
}
});
Run Code Online (Sandbox Code Playgroud) 我已经成功实现了Ignited-Datatables.但是,在输入数据库时,输入"非拉丁"字符,如"İ,ş,ğ,.."
POST http://vproject.dev/module/user/ign_listing 500 (Internal Server Error)
细节是:
Illegal mix of collations for operation 'like' while searching
... (u.id_user LIKE '%İ%' OR u.first_name LIKE '%İ%' OR u.last_name LIKE '%İ%' OR ue.email LIKE '%İ%' OR u.last_login LIKE '%İ%' ) ...
Run Code Online (Sandbox Code Playgroud)
%İ% 部分根据您输入的非拉丁字符而变化.
有什么想法解决这个问题?
我正在阅读这个问题: mysql扩展已被弃用,将来会被删除:使用mysqli或PDO代替
它让我觉得我应该从mysql改为mysqli.这是CodeIgniter中的一个字符更改所以它不是很难:)
但有什么我应该注意发现可能发生的任何错误?某些查询是否有不同的处理方式?
我尝试unlink使用CodeIgniter中的图像,但该unlink函数显示:
notice未定义的索引:userfile
这是我的代码
<?php
function get_from_post(){
$data['logo_name'] = $this->input->post('logo_name',TRUE);
$data['logo_thumb'] = $_FILES['userfile']['name'];
return $data;
}
function deleteconf($data){
$data= $this->get_from_post();
$update_id=$this->uri->segment(3);
@unlink(base_url.'image/logo_thumb'.$logo_thumb);
$query= $this->_delete($update_id);
}
?>
Run Code Online (Sandbox Code Playgroud) 我一直在尝试从我的php文件中检索JSON数据.它让我很难.这是我的代码
我的视图中的代码:
var productDetails = {'id':ISBNNumber,'qty':finalqty,'price':finalprice,'name':bookTitle};
var base_url = '<?php echo site_url() ?>';
$.ajax({
url: "<?php echo base_url() ?>index.php/user/Add_to_cart/addProductsToCart",
type: 'POST',
data:productDetails,
dataType:'JSON',
});
Run Code Online (Sandbox Code Playgroud)
试图在我的控制器中检索:
echo $this->input->post("productDetails");
Run Code Online (Sandbox Code Playgroud)
输出什么都没有.
这是我的标题:
Remote Address:[::1]:80
Request URL:http://localhost/CI/index.php/user/Add_to_cart/addProductsToCart
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,fr;q=0.6
Connection:keep-alive
Content-Length:52
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:ci_session=3E5SPro57IrJJkjs2feMNlmMrTqEXrTNN8UyEfleeothNnHwNxuCZDSx4a7cJZGjj7fyr2KLpj%2BPNJeGRSzSPVmcFHVEdhSk4D47ziOl4eZcTUAZlQrWa3EYIeQJVWxMpiGZS26MEfbSXNmfel9e8TcsJTreZHipvfisrJovbXEAW4Uv%2BwrJRep1KCi1MMaDCVJb9UEinRVcDtYe%2F86jhn7kOj4kraVmVzx%2FsOaO0rAxLyAUtez%2Feaa4zBwpN3Td153sAoIb3WxVHoEj2oKyH5prVHigbIhIBR6XZqjBkM6hjBuoD2OSZ2wgLbp9DEENMoqui4WYyHROBuS2DYiJajblcS0KiFga5k%2FQOODvE7p6n%2BozN5ciDliVjJ4PnJ5PD1GaPEmec5%2FbQSlOHYWZk%2F2Blzw3Nw0EtLL7wKDzzQY%3Df645c36bb3548eb8de915b73f8763d97a47783ce
Host:localhost
Origin:http://localhost
Referer:http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/5
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36
X-Requested-With:XMLHttpRequest
**Form Dataview** sourceview URL encoded
id:234
qty:1
price:0.00
name:dasdadsd2q3e!@!@@
Run Code Online (Sandbox Code Playgroud)
我在Developer工具中可以看到的响应:
Array
( …Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×8
jquery ×2
mysql ×2
activerecord ×1
ajax ×1
cookies ×1
database ×1
datatable ×1
extends ×1
extjs ×1
inheritance ×1
join ×1
json ×1
model ×1
mysqli ×1
post ×1
setcookie ×1
sql-server ×1
unlink ×1