EllisLab text mark
Advanced Search
     
codeigniter with knockoutjs
Posted: 23 May 2012 01:50 PM
Joined: 2012-05-17
38 posts

hi.  i’m trying to incoporate knockoutjs into my ci app.
right now, i’m just trying to do a simple test. in one of my views, i want to create some controls that are bound to values defined in my viewModel in javascript.
the page fails when it comes to displaying the data bound fields with an error that “ko” is not defined.
I’m wondering if it’s because my include file is not being picked up.
with CI, can i do something like this in my view:

<html>
<
head></head>
<
body>
<?php
..
some logic
..
?>

[removed][removed]
</body>
</
html

It seems like the editor in this forum removes any javascript tags… but basically before the body ends, i have a script tag to include the knockoutjs file.  the src property is set to “js/knockout.x.x.js”.  ko is defined in this js file.

I’ve create my js folder in the same folder as the actual view.  so for example:
c:\wamp\www\myapp\application\views\myview\js>

is this ok?

 
Posted: 23 May 2012 01:56 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-05
169 posts

.htaccess won’t let you access the js files where you have them now
follow @insiteFX file structure:
http://ellislab.com/forums/viewthread/217657/

 
Posted: 23 May 2012 03:02 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-05-17
38 posts
weboap - 23 May 2012 01:56 PM

.htaccess won’t let you access the js files where you have them now
follow @insiteFX file structure:
http://ellislab.com/forums/viewthread/217657/

Thanks.  I read that post…and i did the following:
1. specified a base url in my config.php
2. loaded the url helper in my controller’s constructor
3. moved my js folder to c:\wamp\www\myapp\js
4. changed the [removed] tag’s src to be src=’<?php echo base_url();?>js/knockout.x.x.x.js’

That seems to have fixed the problem.
But what if i want to have a js file folder per view?
is that bad design?
for example if i have the following directory structure:

c:\wamp\www\myapp\application\views\myview1>
c:\wamp\www\myapp\application\views\myview2>
c:\wamp\www\myapp\application\views\myview3>

If i wanted to, could i create my views & viewModels(knockoutjs view/viewModels) and then save them in each view’s respective folder like…:
c:\wamp\www\myapp\application\views\myview1\js\view1customjs.js
c:\wamp\www\myapp\application\views\myview2\js\view2customjs.js
c:\wamp\www\myapp\application\views\myview3\js\view3customjs.js

Thanks.