• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Advanced URI routing etc

#2
(05-26-2015, 08:57 PM)Sashk Wrote: Advanded URI routing (like this http://yiiframework.ru/doc/guide/en/topics.url) instead of filesystem-based routing with overriding in config/routes.php. It's a good and modern practice nowadays - more securely, less pages-based (so I would give names like "Rest_Api" for my controllers, and call it with a whole bunch URLS in Django/YII way).

Since I haven't used Yii, I'm not 100% sure what I'm looking at in that documentation, but it really just looks like the CUrlManager and the parseUrl() method handle some of the same functionality as CI's router, while the createUrl() method handles some of the same functionality as CI's URI methods/URL Helper. I'm not really sure what's available in Yii in this respect which might be missing in CI, but I'm sure the addition of the ability to disable automatic routing and, maybe, a 3rd party library to add additional routing features would take care of it.

Quote:Form-validation system is amazing, but very out-of-date stuff in AJAX/SPA era.

I honestly think that most web developers would really benefit from learning not to depend on a server-side framework to generate client-side code for them. In most cases, AJAX code is going to depend on a JavaScript framework to support the range of browsers most web applications require (though this is becoming less necessary with time, as fewer users are running browsers with compatibility issues in this area), making it easier to let people develop/find libraries to generate this code if they don't want to write the JavaScript themselves.

Quote:Also I see a lack of things linked with js/css minification and so on. I see it like this:

Instead of <head>....</head> I offer to make some library-based system enabled by default. When your're in controller code, you may do something like this:

1 $this->load->library('Layout');
2 $this->Layout->title = 'My simple web page';
3 $this->Layout->meta->description = 'Info about this page'
4 $this->Layout->meta->keywords = 'codeigniter is alive';
...and other meta, .og sttff. etc
5 $this->Layout->js->add_url('http://13.storage.com/js_min12.js');
6 $this->Layout->js->remove_url('http://13.storage.com/js_misc_min12.js'); //if auto-loaded, but not needed on specific page
7 $this->Layout->css->add_css('style.css');
8 $this->Layout->css->add_css('bootstrap.css');
9 $this->Layout->css->remove_css('bootstrap.css');
10 $this->Layout->js->add_text('some google analytics snipper');
11) $this->Layout->js->add_var('foo', "['bar','baz','bad']");

Afterwards you just put <?=$this->library->generat_head_code()?> between <HEAD> and </HEAD>, before that all js and css files had glued and minified and gziped. There's a lot of things to work with Layout class - caching, cache lifecycle...

I refactor some of my new CI project this way to get rid of spaghetti code. Any criticism to this approach is recommended>

I use Bonfire's Assets library to manage my CSS/JS/images, so my template's head element contains a call to Assets::css(), which outputs all of the CSS which has been added to the library up to that point, with options for minification/combination of files set in the application config. Most of my JS assets are output at the bottom of the page, though, via Assets::js().

My biggest concern with a method like
Code:
$this->library->generate_head_code()
is that it may not support all of the permitted content for the head element, so people would just end up not using it. Otherwise, there would probably have to be a method in the library to allow the addition of arbitrary text (including HTML) to the head element's content. This also comes down to the question of which content is the responsibility of the View vs. the Controller.
Reply


Messages In This Thread
[split] Advanced URI routing etc - by Sashk - 05-26-2015, 08:57 PM
RE: [split] Advanced URI routing etc - by mwhitney - 05-28-2015, 08:38 AM
RE: [split] Advanced URI routing etc - by Sashk - 07-09-2015, 02:25 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.