I have a function that retrieves all tags from a table:
function global_popular_tags() {
$this->db->select('tags.*, COUNT(tags.id) AS count');
$this->db->from('tags');
$this->db->join('tags_to_work', 'tags.id = tags_to_work.tag_id');
$this->db->group_by('tags.id');
$this->db->order_by('count', 'desc');
$query = $this->db->get()->result_array();
return $query;
}
I have another table called 'work'. The 'work' table has a 'draft' column with values of either 1 or 0. I want the COUNT(tags.id) to take into account whether the work with the specific tag is in draft mode (1) or not.
Say there are 10 pieces of work tagged with, for example, 'design'. The COUNT will be 10. But 2 of these pieces of work are in draft mode, so the COUNT should really be 8. How do I manage this?
I'm trying to send a post request using the ajax jquery function and return some data into a window asynchronously. Here's what I have so far. It doesn't seem to be working.
in the view:
$.ajax({
url: '/dashboard/presskits/media/get_video_link/',
type: 'POST',
dataType: 'json',
data: { encoded_link : encoded_link },
cache: false,
success: function(output_string){
// $('#edit_video_info').append(output_string);
alert(output_string.url_data);
} // End of success function of ajax form
}); // End of ajax call
});
in the controller:
public function get_video_link()
{
$temp_url = $this->input->post('encoded_link');
$output_string = json_encode(array('url_data' => $temp_url));
return $output_string;
}
Hey,
Is it possible to call a function which is located in a controller from a view.
This is what i have in my controller, as an example
function checkKeyExists($userid, $key){
}
Then inside my view i have the following
if(checkKeyExists($row->id, $role->key)){
}
But when i run it, it says that checkKeyExists is not defined.
If anyone can let me know how i could do this, that would be great.
Cheers
Previously i installed CI in xampp. After that i installed wamp on for xampp but the project don't run accurately. It shows the following error-
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Please give me a solution.....
I am working on a project. I am implementing the Search functionality in my System.
I will have to show the search record from two tables base on the current use login. I have tried the following code:
function searchActivity($limit,$offset,$keyword1,$keyword2,$recruiter_id)
{
$q=$this->db->select('*')->from('tbl_activity')->limit($limit,$offset);
$this->db->join('tbl_job', 'tbl_job.job_id = tbl_activity.job_id_fk', 'left outer');
$this->db->order_by("activity_id", "ASC");
$this->db->like('job_title',$keyword1,'both');
$this->db->or_like('job_title',$keyword2,'both');
$this->db->or_like('activity_subject',$keyword1,'both');
$this->db->or_like('activity_subject',$keyword2,'both');
$this->db->or_like('activity_details',$keyword1,'both');
$this->db->or_like('activity_details',$keyword2,'both');
$this->db->where('tbl_activity.recruiter_id_fk',$recruiter_id);
$ret['rows']=$q->get()->result();
return $ret;
}
I want to show search results based on the current user id, which is currently store in $recruiter.
Thanks in advance.
I'm trying to get a cron job to run every 5 min on my localhost. Using the Cronnix app I entered the following command
0,5 * * * * root curl http://localhost:8888/site/ > /dev/null
The script runs fine when I visit http://localhost:8888/site/ in my browser. I've read some stuff about getting CI to run on Cron, using wget and various other options but none make a lot of sense.
In another SO post I found the following command
wget -O - -q -t 1 http://www.example.com/cron/run
What is the "-O - -q -t 1" syntax exactly?
Are there other options?
I have an array
$user = array([0]=>1 [1]=>2 [2]=>3)
which contains id's of certain users.
I need to get the countries of these users from database.
foreach($userid as $user){
$this->db->select('country');
$this->db->where('user_id',$user);
$this->db->from('company');
$usercountry = $this->db->get();
$count = $usercountry->row();
$country = $count->country;
}
Suppose user1 has country ES, user2 has IN, user3 has US, user4 has UK. then if array contains 1,2,3. Then i need to get the countries ES,IN,US.
It says , you must use the “set” method to update an entry. Pls help
My model is
$this->db->where('id', $this->uri->segment(3));
$this->db->update('mytable', $data);
My controller is
$data = $this->db->select('mytable', $_POST);
$this->contact_model->model_update_function($data);
I have a list of posts and an edit link for each. When clicking edit it goes to a page where I can edit the specific post I clicked on. For this I will have to pull from the db the id of the post.
Would this be the correct way to do it?
<a href="<?php echo site_url("post/edit/$row->id"); ?>">Edit</a>
post is my controller, edit is my function, and $row->id should pull the id of the post.
There's a way to get which fields were modified after a update query?
I want to keep track what field XXX user modified... any ways using active records?
I’m coding an application with server resources in mind, so I don’t want to use too much so that this application scales in the future. I don’t mind writing my own queries. So, is ActiveRecord resource intensive for my application? Or does it not make a difference?
Thanks!
Hello.
I've been searching for a solutions for this problem a while but haven't seen any "valid mvc" solution for this.
I hope I can explain my problem clearly enough for you guys.
I need to create a dynamic block of HTML on my website. (eg. a block containing user's latest blog comments).
I have a template view file (a file containing header, content container and a footer) where I need to add some content AND this block element.
The problem is that I don't want to duplicate this block code on every controller. It just feels stupid and I'm sure there's a better way to do this than just duplicating same stuff all over again on all the controller files?
I can add view inside another view just fine, but what bugs me is how to actually generate that dynamic content to this block's view-file.
I can't call controller from view file, controller from controller filem or model from view file because what I understand that just isn't the "mvc" way?
Anyone got any tricks or tips for this?
I'm trying to redirect all routs to one main controller. Here is my routes.php
$route['default_controller'] = "main";
$route['scaffolding_trigger'] = "";
//$route['(\w{2})/(.*)'] = '$2';
//$route['(\w{2})'] = $route['default_controller'];
$route['(en|ge)/(:any)'] = $route['default_controller']."/index/$1";
$route['(:any)'] = $route['default_controller']."/index/$1";
I need language id to be passed with every link (like: http://site.com/en/hello-world)
Here is my main controller:
class Main extends Controller
{
function __construct()
{
parent::Controller();
}
function index($page_type=false, $param=false)
{
die($page_type.' | '.$param.'| Aaa!');
}
}
I want to check if predefined file type exists (like: http://site.com/en/archive/05-06-2010 - here predefined type would be archive) then do something. If not then search in the database for slug. If not found then go to 404.
The problem is that I can't get index function parameters ($page_type, $param). Thanks for help.
Hello everyone,
I am wondering if there is any other configuration options for a default controller.
For example - if I have a controller called "site" and I set the default controller in the following file: application/config/routes.php to:
$route['default_controller'] = "site";
I should be able to go to http://localhost and that brings up the index(); function in the site controller.
However, if I try to do go to http://localhost/index.php/index2 to load the index2(); function I get a 404 error. If i change the URL to http://localhost/index.php/site/index2 it works fine - but I thought already set the default controller. Is there any way around this?
Any thoughts?
Hi,
I have just started my first CI app. I have a view that displays some posts. Each post can have multiple comments and I want to display the total number of comments next to each post.
So far all my db call are in my controller (will be changing this).
function index(){
$data['query'] = $this->db->get('posts');
$this->load->view('blog_view', $data);
}
In my view:
<?php foreach($query->result() as $row):
<div class="post-box">
<p><?php echo $row->body; ?><small> added by <?php echo $row->username; ?> on <?php echo date ('d/m/Y',strtotime($row->created)); ?> <a href="<?php echo base_url(); ?>blog/comments/<?php echo $row->id; ?>"><img src="<?php echo base_url(); ?>images/comments_icon.png" /> 0</a></small></p>
</div>
<?php endforeach; ?>
I want to get the total number of comments where comment.post_id = the current record's id. and display it next to the comments icon.
Any help with this most appreciated,
Billy
I am using a simple join to pull data from two databases. This is the join in the model
function com_control(){
$this->db->select('*');
$this->db->from('comments');
$this->db->join('posts', 'comments.entry_id = posts.id');
$query = $this->db->get();
return $query->result;
}
My desired method of display is going to be in a table so I am starting out to use like this
foreach($comm_control as $row){
$this->table->add_row(
$row->entry_id,
$row->comments.id,
$row->comment,
$row->title
);
}//end of foreach
My problem is the display of data from comments.id. What is the proper format to add the comment.id into the table rows? I need the ID from both tables for display, edit and delete further on in the table. The only display I get at this time for "comment.id" is the word id.
The
Any help would be appreciated.
Wildcards are cool.
I am trying to do this:
$route["(:any)/controller"] = "controller";
basically, I want to put the wildcard in the front. It doesn't quite work, and I don't know any work around.
Hello all i having a problem that it only get 1 value in my database and its my title and i want to show content and username from the same table to.
here is my JSON kode
<script type="text/javascript">
$.getJSON(
'ajax/forumThreads',
function(data) {
alert(data[0].overskrift);
alert(data[0].indhold);
}
);
</script>
my controller
<?php
class ajax extends Controller
{
function forumThreads() {
$this->load->model('ajax_model');
$data['forum_list'] = $this->ajax_model->forumList();
if ($data['forum_list'] !== false) {
echo json_encode($data['forum_list']);
}
}
}
my model fle
<?php
class ajax_model extends Model
{
function forumList()
{
$this->db->select('overskrift', 'indhold', 'brugernavn', 'dato');
$this->db->order_by('id', 'desc');
$this->db->limit(5);
$forum_list = $this->db->get('forum_traad');
if($forum_list->num_rows() > 0)
{
return $forum_list->result_array();
} else {
return false;
}
}
}
Hi
In my mode I am selecting a field as
$query1 = $this->db->query("SELECT dPassword
FROM tbl_login
WHERE dEmailID='[email protected]'");
How to return dpassword as a variable to my controller
I tried this way return dpassword;
I want to generate multiple pdf reports on click of single print button and zip all the pdf's and store it in a folder.
Any help please. I need this functionality in my project.
Hi i am creating table using table helper, but in every row i want to add form, in html like this :
<table>
<form action="">
<tr>
<td><input type="text" name="name2"></td>
</tr>
</form>
<form action="">
<tr>
<td><input type="text" name="name2"></td>
</tr>
</form>
</table>
But i want in table helper:
I have tried this one:
$this->table->add_row(
form_open('myAction').
form_input('name'.$i),
form_submit('Submit')
form_close()
);
And I use firebugs to inspect element produces, like this:
<table>
<tr>
<form action="myAction">
<td><input type="text" name="name1"></td>
</form>
<td><input type="submit"></td>
</tr>
</table>
why tag doesn't show at the last tag , but show at the first tag .
Thanks
I know this question has been asked over and over again, but I still haven't found the perfect answer for my liking, so here it goes again...
I've been reading lots and lots polarizing comments about CI's xss_filter. Basically majority says that it's bad. Can someone elaborate how it's bad, or at least give 1 most probable scenario where it can be exploited? I've looked at the security class in CI 2.1 and I think it's pretty good as it doesn't allow malicious strings like document.cookie, document.write, etc.
If the site has basically non-html presentation, is it safe to use global xss_filter (or if it's REALLY affecting performance that much, use it on per form post basis) before inserting to database ? I've been reading about pros and cons about whether to escape on input/output with majority says that we should escape on output only. But then again, why allow strings like <a href="javascript:stealCookie()">Click Me</a> to be saved in the database at all?
The one thing I don't like is javascript: and such will be converted to [removed]. Can I extend the CI's security core $_never_allowed_str arrays so that the never allowed strings return empty rather than [removed].
The best reasonable wrongdoing example of this I've read is if a user has password of javascript:123 it will be cleaned into [removed]123 which means string like this document.write123 will also pass as the user's password. Then again, what is the odds of that to happen and even if it happens, I can't think of any real harm that can do to the site.
Thanks
I am beginner for CI so don’t have good knowledge.
My problem is:
I am not using any database. All the records are fetched from JSON.
Therefore I don’t think I need to configure database…
As said by CI, it doesn’t necessarily ask for database.
So my database.php configuration is :
$active_group = ‘default’;
$active_record = FALSE;
$db[‘default’][‘hostname’] = ‘’;
$db[‘default’][‘username’] = ‘’;
$db[‘default’][‘password’] = ‘’;
$db[‘default’][‘database’] = ‘’;
$db[‘default’][‘dbdriver’] = ‘mysql’;
$db[‘default’][‘dbprefix’] = ‘’;
$db[‘default’][‘pconnect’] = TRUE;
$db[‘default’][‘db_debug’] = TRUE;
$db[‘default’][‘cache_on’] = FALSE;
$db[‘default’][‘cachedir’] = ‘’;
$db[‘default’][‘char_set’] = ‘utf8’;
$db[‘default’][‘dbcollat’] = ‘utf8_general_ci’;
$db[‘default’][‘swap_pre’] = ‘’;
$db[‘default’][‘autoinit’] = TRUE;
$db[‘default’][‘stricton’] = FALSE;
It works in my local system but doesn’t work in live server. I am so surprised.
Then I provided hostname, username, password and dbdriver, it works.
My question is that, is that necessary to provide all the details if I am not using database?
Thank you for your suggestion.
I have quite a few libraries and models that get loaded into a controller, and each library/model creates an instance of CI using $this->CI =& get_instance(); in the __construct function.
Are there any performance issues with this and is there a better way?