안녕하세요, 제 젠드 응용 프로그램에서 백본 응용 프로그램/자산 폴더를 만들고 싶습니다. 어디에 배치 할 것입니까? 백본 응용 프로그램 폴더는 간단히 말해서 Javascript,Stylesheets and Templates
Backbone.js와 함께 Zend Framework
구성 백본 레일 URL이에있는 경우
class EntriesController < ApplicationController
respond_to :json
def index
respond_with Entry.all
end
end
백본 수집은 단순히 이해 항목/지표/항목에 대한
routes.rb
resources :entries
레일 컨트롤러를 작동하는 방법이다 이 코드로
class Blog.Collections.Entries extends Backbone.Collection
url: '/entries'
백본 라우터
class Blog.Routers.Entries extends Backbone.Router
routes:
'': 'index'
'entries/:id': 'show'
initialize: ->
@collection = new Blog.Collections.Entries()
@collection.fetch()
index: ->
view = new Blog.Views.EntriesIndex(collection: @collection)
#alert 'hi'
$('#container').html(view.render().el)
show: (id) ->
alert "Entry #{id}"
는 그 다음
<h1>Blog</h1>
<ul>
<% for entry in @entries.models: %>
<li><%= entry.get('name')%></li>
<% end %>
</ul>
마지막으로 자산/자바 스크립트와 응용 프로그램을 초기화하기
index.jst.eco/자산/템플릿/항목을 렌더링하기 위해Backbone.View
class Blog.Views.EntriesIndex extends Backbone.View
template: JST['entries/index']
initialize: ->
@collection.on('reset',@render,this)
render: ->
$(@el).html(@template(entries: @collection))
this
템플릿 렌더링/blog.js.coffee
window.Blog =
Models: {}
Collections: {}
Routers: {}
Views: {}
initialize: ->
new Blog.Routers.Entries()
Backbone.history.start()
$(document).ready ->
Blog.initialize()
위의 Backbone.js의 MVC 패턴은 흥미 롭습니다.하지만 Zend Framework로 구현하고 싶습니다. 그래서 어떤 설정을 레일스에서 사용하는 것처럼 변경해야합니다. 또한 뷰를 렌더링하기 위해 템플릿을 처리하는 방법 ? 감사합니다
질문이 명확하지 않습니다. Backbone은 RESTFul 서비스와 함께 작동하도록 설계된 클라이언트 측 라이브러리입니다. 백엔드에서 REST 서버를 구현하는 것은 불가 지합니다. 정확히 무엇을 요구하고 있습니까? –
Zend Application에서 어떻게 사용합니까? 나는 자바 스크립트가 클라이언트 측이라는 것을 알고 있지만, 모두 스크립팅 언어 내에서 구현 방법을 가지고있다. 대부분 Backbone.js는 Rails와 함께 사용됩니다. 하지만 젠드 프레임 워크에 어떻게 포함 시켰는지 알고 싶습니다. – d3bug3r
.. 그리고 레일즈에서 어떻게하는지 설명하는 이유는 무엇입니까? – tasmaniski