I want to write a WebApp using SproutCore for the client side and PHP
for the backend. Right now I have the sc-server running for the client
and a webserver (on the same machine, just a different port) for the
PHP stuff. This is all very well until I want to use AJAX to get data
from the backend.
AJAX requests only work on the same host and port, so I need a way to
run both on the same server. Either PHP through sc-server (probably
not possible) or my client stuff on the web server.
What I do at the moment is sc-build every time I change something on
the front end (and then I have to manually change paths because
SproutCore wants its files at http://localhost/static/... and the
actual files are in http://localhost/subfolders/static/...), so that's
very inconvenient.
> I want to write a WebApp using SproutCore for the client side and PHP
> for the backend. Right now I have the sc-server running for the client
> and a webserver (on the same machine, just a different port) for the
> PHP stuff. This is all very well until I want to use AJAX to get data
> from the backend.
> AJAX requests only work on the same host and port, so I need a way to
> run both on the same server. Either PHP through sc-server (probably
> not possible) or my client stuff on the web server.
> What I do at the moment is sc-build every time I change something on
> the front end (and then I have to manually change paths because
> SproutCore wants its files athttp://localhost/static/... and the
> actual files are inhttp://localhost/subfolders/static/...), so that's
> very inconvenient.
> Is there any way I can do this more efficiently?
Sproutcore doesn't "want" files at http://localhost/static/. It puts them there because you told it to. Take a look at the settings document sc-config.rb. It controls where files are placed after a build. Change c[:resources_at] = 'static' to what ever you want.
> I want to write a WebApp using SproutCore for the client side and PHP > for the backend. Right now I have the sc-server running for the client > and a webserver (on the same machine, just a different port) for the > PHP stuff. This is all very well until I want to use AJAX to get data > from the backend.
> AJAX requests only work on the same host and port, so I need a way to > run both on the same server. Either PHP through sc-server (probably > not possible) or my client stuff on the web server.
> What I do at the moment is sc-build every time I change something on > the front end (and then I have to manually change paths because > SproutCore wants its files at http://localhost/static/... and the > actual files are in http://localhost/subfolders/static/...), so that's > very inconvenient.
> Is there any way I can do this more efficiently?
I have another question about paths: In my CSS files, how do I
reference an image in my english.lproj folder (that's where shared
resources are supposed to be, right?) correctly so that it shows up
while testing with sc-server and also when I build the project.
> I have another question about paths: In my CSS files, how do I > reference an image in my english.lproj folder (that's where shared > resources are supposed to be, right?) correctly so that it shows up > while testing with sc-server and also when I build the project.
Erich is right. static_url() works in CSS, JS & rhtml templates. IT will search all of your linked bundles (including SproutCore) to find the image you name. You can also leave off the file extension if you want. This way you can change image file types without having to edit your code.
> In that case, it's handled by SproutCore's build tools.
> Best, Erich
> On Jun 19, 2008, at 7:50 AM, jewetz wrote:
>> Thanks to both of you, that's perfect!
>> I have another question about paths: In my CSS files, how do I >> reference an image in my english.lproj folder (that's where shared >> resources are supposed to be, right?) correctly so that it shows up >> while testing with sc-server and also when I build the project.
One thing to add about static_url (though it might be obvious). If will use the first item it finds (I think it searches alphabetically, but I'm not sure). So if you have multiple files of the same name (in different subfolders) you can give it a more specific path to use, i.e., static_url('lores/logo') vs static_url('hires/logo').