codeigniter & node js integration with now js - how to access view files
Asked Answered
W

1

4

i want to integrate codeigniter and node.js but i am having confusion that how to execute both node.js and codeigniter.

I have successfully installed and ran the nowjs sample: http://nowjs.com/doc/example

how to access view files of codeigniter(or any php framework) into node.js.

i have confusion because codeigniter executed with url http://localhost/xyz while node.js executed with http://localhost:8080/xyz

so which url i have to write in browser from which i can use both node.js & codeigniter?

Wicketkeeper answered 31/8, 2012 at 9:58 Comment(0)
A
9

Here is how ii made codeigniter and nodejs talk to each other.

i have my codeigniter app running on http://mydomain.com/controller/function/ and i have my nodejs(nowjs) running on http://mydomain.com:8080 ,

users will use codeigniter URL and when open the page, i have this script on my CI view page that connects to my Nodejs app, something similar to this :

<script src="http://mydomain.com:8080/nowjs/now.js"></script>

<script>
$(document).ready(function(){
    now.receiveMessage = function(name, message){
        $("#messages").append("<br>" + name + ": " + message);
    }

    // Send message to people in the same group
    $("#send-button").click(function(){
        now.distributeMessage($("#text-input").val());
        $("#text-input").val("");
    });

    now.name = prompt("What's your name?", "");

    // on establishing 'now' connection, set server room and allow message sending
    now.ready(function(){
        // Pick up list of available chatrooms from server and populate dropdown 
        setServerRoomFromList(now.serverRoomsList);

        // By default pick the first chatroom 
        now.changeRoom($('#server-room').val());
        // Connection established and room set; allow user to start sending messages
        $("#send-button").removeAttr('disabled');
    });

    // On change of drop down, clear text and change server room
    $('#server-room').change(function(){
        $("#messages").html('');
        now.changeRoom($('#server-room').val());
    });

});

// populate the #server-room dropdown 
function setServerRoomFromList(roomList){
    $('#server-room').empty();
    $.each(roomList, function(key, value)
    {   
         $('#server-room').
              append($("<option></option>").
              attr("value",key).
              text(value)); 
    });
}

</script>

ant they can talk to each other very well !!

Arguelles answered 11/9, 2012 at 17:55 Comment(3)
Very helpful.! Do you have any sample(integrated) any app ?Pamalapamela
Sorry mate, this post is pretty old and i couldnt find my test files. but in few days im gonna launch another app with same structure, if i did i will let you know.Arguelles
Yeah, this is the way i am planning to doCorydon

© 2022 - 2024 — McMap. All rights reserved.