codeigniter

how not to hard-code codeigniter link in js file

旧时模样 提交于 2019-12-22 10:25:03
问题 i wrote the routine below to retrieve city based on selected country for my codeigniter application. $(document).ready(function() { $("select#cbo_country").change(function() { $.post("http://localhost/main/index.php/city/get_data_by_country", { int_country_id : $(this).val() }, function(data) { // some code here },'json'); }) }); as you can see, i hard-coded the url (http://localhost/main/index.php/city/get_data_by_country) and i know it's a bad practice but i can't help it. is there a nice

Mysql codeigniter php asc desc order by count result using php

老子叫甜甜 提交于 2019-12-22 10:23:57
问题 I have three tables named: at_category: cat_id name at_category_taxonomy: cat_taxonomy_id cat_id taxonomy at_shop: shop_id shop_category I want to join those three tables by counting result. For example the category named as Electronic Shops in at_category table and the value will be stored in at_category_taxonomy table and the this category id's are having two shops in at_shop table. same as for remaining categories aaa, bbb, ccc etc...it may be having one or two shops else zero shops.

jQuery AJAX call to PHP Controller

二次信任 提交于 2019-12-22 09:56:48
问题 I am calling a controller (Codeigniter) through jQuery. My dataString variable contains a simple string, which I'm trying to pass through to my controller, so I can pass it into the model. However, I'm getting an error that indicates that my $test_var is undefined. What am I doing wrong? $('a.test').click(function (event) { dataString = $(this).attr('name'); $.ajax({ type:"POST", url:"<?php echo base_url(); ?>controller_name/", data:dataString, success:function (data) { alert('test'); } });

Load different language from class CI_Controller in codeigniter

坚强是说给别人听的谎言 提交于 2019-12-22 09:52:39
问题 I am developing multilingual website. I wrote following code in CI_Controller class file so that I don't have to load language to each controller file. $this->lang->load('english'); Problem is when I have to change other language for example: let's say spanish. $this->lang->load('spanish'); How to I load between these two language when I choose Language > English / Spanish from menu option? 回答1: Checking and Loading place this code in controller constructor $this->load->library('session');

codeigniter, get the maximum value in mysql table column

感情迁移 提交于 2019-12-22 09:50:56
问题 i'm using codeigniter 2. i've a mysql table column storing the time taken for each student. eg. 1.2327, 0.6547, 1.9876 i want to get the max. value that column. This is my code: $this->db->select_max('time_taken', 'time'); $result = $this->db->get('students'); echo $result->row()->time; when i echo the result, it give me a value of 2(correct value should be 1.9876). What is the correct way to get this value i need, thanks? 回答1: Try: $this->db->select_max('time_taken AS time'); $result = $this

CodeIgniter call same function for all controllers

て烟熏妆下的殇ゞ 提交于 2019-12-22 09:48:36
问题 I'm developing an application, where the same function I'm writing for some controllers. So I wanted one common function for all controllers. Please help me out I've stucked up with this. The work would be more appreciated. 回答1: You can develop a helper or library. codeigniter version 2 : https://codeigniter.com/userguide2/general/creating_libraries.html codeigniter version 3 : https://codeigniter.com/user_guide/general/creating_libraries.html?highlight=library 回答2: You can create MY

How to upload file and insert data with php jquery ajax

隐身守侯 提交于 2019-12-22 09:47:02
问题 I cannot send via ajax to php file upload and data with ajax. This my code just send file upload . data not send to my php code. I create form and the function send on click using ajax to post on php. I'm using codeigniter This my form: <form action="<?php echo site_url('home/send_chat');?>" method="post" enctype="multipart/form-data"> <input name="message" id="message" type="text" class="form-control input-sm" /> <input type="file" id="file" name="file" /> <br /> <span class="input-group btn

What is the proper way to test CodeIgniter session variable?

半腔热情 提交于 2019-12-22 09:36:24
问题 Take the following code snippet. What is the best way to test to make sure the session variable isn't empty? <?php if ($this->session->userdata('userID')) { $loggedIn = 1; } else { $loggedIn = 0; } ?> If later in my script, I call the following, the first prints properly, but on the second I receive Message: Undefined variable: loggedIn <?php echo $this->session->userdata('userID')); echo $loggedIn; ?> I've tried using !empty and isset , but both have been unsuccessful. I also tried doing the

Set dropdown input default value based on third parameter in Grocery CRUD

为君一笑 提交于 2019-12-22 09:24:09
问题 Code sample below, function product($parameter){ $crud = new grocery_CRUD(); ... $crud->callback_add_field('dropdown_field_name',array($this,'_add_field_callback')); ... $output = $crud->render(); } Can I do something like this ? function _add_field_callback($parameter){ //load db model //call the result and return as dropdown input field with selected selection when value = $parameter } 回答1: Actually this is easy to do it by using the controller. For example you can simply do: function

Manage Login Redirection in Pyrocms

谁都会走 提交于 2019-12-22 09:19:47
问题 I need to manage login in such a way that it should redirect the control after successful login to the page which call login method in pyrocms. By default it return control to Home Page. for example i want to go gallery page but it require user to be logged in so it will redirect control to the login page and now i want to redirect the control back to the gallery page once the user successful logged in. 回答1: Finally, i have come with the exact solution which is working correctly for me.