Yii ported to JavaScript

I ported Yii to JavaScript so that it can run in the browser and you have access to most of Yii’s features. It’s not complete yet but some of you might find it interesting,

github.com/phpnode/YiiJS

Wow… I’ve only had a cursory look but this looks awesome. How long have you been working on this?

this is an awesome amount of Js code … wow!

Can you explain a bit more, what this could be used for?

It took about a week, after I’d spent a few days writing this mess: //github.com/phpnode/YiiJS/blob/master/protected/commands/js/phpToJS.php

It’s a semi-automatic conversion of the PHP to JavaScript, Yii is one of the few PHP frameworks that are suited to this because of its clean design.

What you can use this for:

MVC in the browser, so you get proper separation of business logic in your JavaScript code, just like YiiPHP.

URL routing is fully compatible with YiiPHP, so you can use Yii.app().createUrl(’/user/view’,{id: 123}) and get a friendly URL like example.com/users/123.html

Translation, e.g. Yii.t(‘category’, ‘Message to be translated’)

Profiling, logging straight to console etc

Caching using sessionStorage, so you can grab data and cache it for a certain time in the browser, or according to certain dependencies etc.

Note: because JavaScript doesn’t support magic getters and setters I had to take a slightly different route to avoid very very verbose code, so:

Yii.app().getRequest().getHostInfo()

can also be written as

$app(‘request.hostInfo’)

or as

Yii.app().get(‘request.hostInfo’)

or as $app(‘request’).get(‘hostInfo’)

not quite as nice as in PHP but better than nothing.

Ok, thanks. Not sure if that will be useful for me but still impressive amount of work :)

Very, very impressive the amount of code you have been written in just one week!

I do not know if it is a good idea to have an MVC at the client… think they are a couple out there and I never had a closer look to it but have lot of respect to your work

Would be nice to see some examples running with it.

Cheers

It’s surely interesting but… why should somebody use the JS port instead of PHP Yii?