I am fairly new to Codeigniter and am trying to call in a function from my model but I cannot get it to work. Can anyone see what I am doing wrong here?
Related
A project I'm updating was written in CodeIgniter. I am trying to pull information from the database using the standard CI methods of...
$this->db->select('myfield')...
However, $this is not defined in my ajax page. It is a separate simple PHP page that is just going to pull the info I need and return a HTML table of the contents.
How can I access $this from the ajax script? I have a function in my model file too, and I have tried to access it from the ajax script using
$this->my_model->myfunction();
but that fails as well. CodeIgniter is version 2.1.2
The easiest way to access CodeIgniter's methods and its $this object is to be inside of a controller function.
Don't make a standalone PHP page, instead make a controller (or a new function in an existing controller) and send your AJAX request to there. You can send POST variables and access then via $this->input->post('var').
My situation is: I have a Spring MVC project is running now, I need to include a file in normal form object to submit to server side to handling.
I did quite lots research recently, I found there is no way to submit a file in a regular form as file upload submit form has to configured to support file encode (enctype="multipart/form-data"). it is impossible in regular form.
Ajax provides a way to do the file uploading in javascript by javascript function call, but they need a individual servlet to listen to the javascript call. My project already did everything in modelandview controller to handle form object and model object logic.
My question is: May I add a file upload method in my modelandview controller to listen to my Ajax function call? If it is true, what's looks like?
Please help!!
After a while works on this issue, I found some thing is very interesting. If I want to use some thing else in my Spring MVC controller. I have change my controller class to "extends MultiActionController", which means make the controller to support multiAction, and then you can add other class and action in Spring MVC modelandview style controller, even you can use "webservlet" or "ResponseBody" style controller functions in your MVC controller, you don't need create other new controller to support Ajax controller, you only need update your existing controller by adding some functions. it is much easy to manage you existing code too.
URL Helper in CI is so bad thing, i dont know what to do :(
I have called
$this->load->helper('url');
And on view i have called
echo current_url();
I got something like this ??
http://www.example.com/?druga
The real url is
http://www.example.com/druga.html
I think CI is not doing proper way, is there any help?
Greeting to the community. This is my very first question.
I had in mind to add Livezilla live support in my MVC website, but I realised that there are some problems.
First of all, it is written in php and mysql, so is it possible to comply with MVC and sql server?
Does anybody know a similar solution (like livezilla) in my case?
PS. Excuse my poor english...
you could even look into using an iFrame to run livezilla inside of an mvc3 page if you wanted.
or, you could roll your own. if you wanted to try implementing a live response mvc3 page look into jquery and ajax asynchronous calls such as $.post and also look into the extension for controller AsyncController, and [AsyncTimeout(XXX)]. you will also have to read up on sending and receiving json objects in ajax and from a controller to the view.
Simple psuedo:
View:
setTimeOut calls a javascript function every X milliseconds
the javascript function uses json to wrap page data and pass it to the controller inside a $.post() call
Controller:
recieves page data as an model object in a post
determines if page is out of sync or not
returns relevant sync data in a json object back to the view
View:
the same javascript function receives the json object from controller
updates the page based on relevant sync data
Problem solved. I just uploaded the folder given from livezilla in the root folder of my website. Then the only need to met is to have a Mysql server to create the database for livezilla. After that php and mvc runs together with no problem.
I just started using CodeIgniter after using Zend for a while. My new site has a feature where you register through Ajax. In Zend I could use this to check if the incoming POST was through AJAX, and therefore from my site:
if(!$this->getRequest()->isXMLHttpRequest())
Is there a piece of code in CodeIgniter that does the same thing? If I don't make sure it's an AJAX call, someone could theoretically register anything they wanted by creating a form to post to my controller.
Thanks!
Since CodeIgniter 2.0, there is an easier way of checking for an ajax request.
Use: $this->input->is_ajax_request();
Doc: https://codeigniter.com/user_guide/libraries/input.html
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {}
But since you are using codeigniter, its better to use their input class . See how to do it below.
if($this->input->is_ajax_request()){
//Execute Your Code
}
you can check it using
$this->input->is_ajax_request();