EllisLab text mark
Advanced Search
     
External v2 - Route Based Asset Management
Posted: 17 February 2011 02:09 PM
Avatar
Joined: 2008-08-19
340 posts

Greetings! I’ve been off the forums for a while, but I’m back, with a vengeance. I recently rewrote my External library (see previous version).

Here is the link to the new library. https://github.com/darkhouse/External

There were a lot of things I wanted to incorporate into it so I’ve rewritten it from scratch. Version 2 is based on the same principle that you can specify assets for certain routes, but with some new, I think cool, features. I’ve explained them in more detail on the wiki, but here’s a summary.

Groups - Everything is group based now (inspired by tonydewan’s Carabiner) so you can load only assets from a specific group if you want. You can also load assets in more than one place on a page, so you can target different assets for different parts of your page.

Inheritance! - You can specify assets for a route, but also inherit assets from another route.

Exclusions - when inheriting, you can tell it to ignore certain groups.

Weights - you can load the assets in whatever order you want.

LESS.js - I use LESS.js myself, so I’ve added support for that.

Pretty Output - There is a tabs param so that the output matches the indentation of the rest of your code.

There are more details on the wiki, and some usage code. Also, I’ve added a sample config file that has the settings I used for a site recently. That should give you a pretty good idea how to setup your config file.

Thanks to everyone who used my original, and I hope this new version helps make things even better.

 
Posted: 21 February 2011 10:56 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-02-21
2 posts

Not sure if i’m doing something wrong, but on PHP 5.3 i get the following error/warning:

Severity: Warning
Message: Parameter 1 to array_multisort() expected to be a reference, value given
Filename: libraries/External.php
Line Number: 325

I think it is related to this: http://bugs.php.net/bug.php?id=43568

 
Posted: 21 February 2011 11:19 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-02-21
2 posts

This code change worked for me (starting on line 311 of the External.php file):

private function _multisort(){
        $args 
func_get_args();
        
$data array_shift($args);
                if (!
is_array($data))
                    return 
false;

                
$multisort_params = array();
        foreach (
$args as $n => $field{
            
if (is_string($field)) {
                ${
"tmp_$n"= array();
                foreach (
$data as $key => $row){
                    ${
"tmp_$n"}[$key] $row[$field];
                
}
                $multisort_params[$n] 
= &${"tmp_$n"};
            
}
        }
        $multisort_params[] 
= &$data;
        
call_user_func_array('array_multisort',$multisort_params);
        return 
array_pop($multisort_params);
    
 
Posted: 22 February 2011 12:26 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-19
340 posts

Thanks, I’ll make this change - I grabbed that multisort code from php.net, I didn’t modify it, and it was working fine for me on v5.3.5

 
Posted: 22 February 2011 02:20 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-19
340 posts

I’ve changed this, and modified the cachebusting system based on CroNiX’s suggestion. Thanks guys. I’ve also added some better documentation, added a markdown readme file which goes over the config file in pretty good detail (I think). As always, if anyone has any questions, please feel free to ask.  Thanks!

 
Posted: 17 July 2011 08:39 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-07-17
8 posts

I have issues with sub pages.  i have a controller search/advanced with the url http://mydomain.com/search/advanced but the css is being loaded as follow

search/advanced/includes/styles.css

where the link should be just

includes/styles.css

any thoughts on this one?

Thanks

 
Posted: 17 July 2011 11:47 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-19
340 posts

dchankhour: are you using a <base> tag?

 
Posted: 19 July 2011 01:24 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2010-03-14
24 posts

might just be use this in my next project, beats hard-coding in controllers thanks for posting.

 
Posted: 21 July 2011 03:45 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-07-17
8 posts

Sorry darkhouse, i’m not sure what you meant by <base>. 

I basically have my site in a subfolder.  in the site i have a search folder and i have home.php and an advanced.php controller in the search folder.  when i view the /search/home every thing works fine but when i view search/advanced it does not load any css files.

it basically try loading http://localhost/mysite/search/includes/styles.css

instead of http://localhost/mystie/includes/styles.css

thanks for your assistance.

 
Posted: 21 July 2011 09:49 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2008-08-19
340 posts

dchankhour: Right, you need a <base> tag. Put this in your <head>

<base href="<?php echo base_url(); ?>"></base

If you’re not already loading the url helper, I would autoload it. Just add ‘url’ to the helper array in application/config/autoload.php and then base_url() will work.

 
Posted: 23 July 2011 06:06 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2011-07-17
8 posts

Thanks a lot.

That worked.

 
Posted: 27 July 2011 09:31 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-27
173 posts

hi

i set external and external config to autoload
when i try to use $this->external->get(‘admin_login’, ‘head’, false, 4);
i get

A PHP Error was encountered
Severity
Warning
Message
Missing argument 1 for CI_External::__construct(), called in D:\server\www\qpshop\system\core\Loader.php on line 996 and defined
Filename
libraries/external.php
Line Number
26 

this is my config file

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
$config['routes'= array(
    
'all' => array(
        
'css' => array(
            array(
'data' => 'assets/css/reset.css''group' => 'head''weight' => 1),
            array(
'data' => 'assets/css/final.css''group' => 'head''weight' => 999),
        ),
        
'js' => array(
            array(
'data' => 'assets/js/libs/less.js''group' => 'head''weight' => 10),
            array(
'data' => 'assets/js/libs/modernizr.js''group' => 'head''weight' => 10),
            array(
'data' => 'assets/js/libs/jquery.js''group' => 'foot''weight' => 1),
            array(
'data' => 'assets/js/libs/apprise.js''group' => 'foot''weight' => 2),
            array(
'data' => 'assets/js/libs/fancybox.js''group' => 'foot''weight' => 3),
        )
    ),
    
'admin' => array(
        
'css' => array(
            array(
'data' => 'assets/css/admin/common.less''type' => 'less''group' => 'head''weight' => 1),
        ),
        
'inherit' => array(
            
'parent' => array('assets' => 'all')
        )
    ),
    
'admin_login' => array(
        
'css' => array(
            array(
'data' => 'assets/css/admin/login.less''type' => 'less''group' => 'head''weight' => 1),
        ),
        
'inherit' => array(
            
'parent' => array('assets' => 'admin')
        )
    )
);

$config['default_cache'true

what i’m doing wrong ?

Edit 1
if i don’t autoload the config file i don’t get any error but no results

my folder structure is
-application
-assets
—css
—js
-system

Edit2
if i call $this->external->get(‘all’, ‘head’, false, 4); it works

so i think i don’t understand how inheritance works
if i call the route admin_login i want to get admin and from admin it should get all
but i get nothing

Edit3
ok now i got it by route you really mean route like in controller/function/
but i have a new problem i use languge uri identifier
so my urls are like this site.com/language/controller/function
how can i make external to ignore the language ?