CodeIgniter - accessing $this scope from ajax - codeigniter

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').

Related

Pre-populate Ember DS.Store via ajax

Reading the Ember guide about the data store it's not clear how you pre-populate the store with your data. I see you can set up the RESTadapter with the host name, and the 'store.find' method will trigger a 'get' request if the data is not cached, but how can I initialize a DS.Store with JSON data via ajax before ever doing a find?
Ember guide model HTTP
The context for this is, a single page app that on page load gets a blob of json, which is used to model out the rest of the site. The end result gives the illusion that the site contains multiple pages.
Sounds like you want this.store.pushPayload(..)
http://emberjs.com/api/data/classes/DS.Store.html#method_pushPayload
Note that you only have access to the store inside Routes and Controllers. Consider putting this inside the activate hook of App.ApplicationRoute
http://emberjs.com/guides/routing/defining-your-routes/#toc_initial-routes
http://emberjs.com/api/classes/Ember.Route.html#method_activate

How to add a fileupload method in my existing mav controller to accept ajax file upload submit

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.

Add ajax calls to a folder in Zend

Is there a way to create an Ajax folder inside application, so that I can then add each controllers ajax as a seperate controller in that ajax folder?
For instance, say I have IndexController, EmployeeController, MemberController. Inside Ajax folder, I want to have the same three names as well.
Then If I want to call an ajax action, I could refer to /ajax/member/whatever.
Is this possible with zend?
You could set up routes to create urls like that, but I wouldn't duplicate the controllers as you're suggesting. One controller can handle both html and ajax requests. You could include a format parameter in your url like this: /member/21/format/ajax
Then the member viewAction can check the format variable. If it's ajax, you can disable your layout and return the ajax response.

PHP session and Ajax

I've created a session variable and stored a value "123456" in it.
I need that value on another page that is called using ajax. I cannot access the session variable when making the ajax call. session_start() is in top of both pages. I even tried to write the actual session value to a txt file from the page that the ajax function calls, but the file turned out blank.
What to do?
You cannot access PHP session info from Javascript (I'm assuming that this is what you're trying to do). You can pass it in as a hidden field or in the JS (dynamically added with PHP) to the second page, add it to a regular cookie, or provide it from PHP as a response to an AJAX request, but I think those are your only options.

Add Live Support section to mvc 3 project

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.

Resources