Welcome Guest, Not a member yet? Register   Sign In
[Plugin] CodeIgniterPhp5 (Autoloader, Modularity, Fast Coding)
#21

[eluser]Dewos[/eluser]
Hello. I've just finished to full convert a medium size project with the plugin, without errors (but now much better efficiency, and much much slim code), so it's safe to say that the plugin can be used in production with no regrets.

Version 1.7.2 Stable Changelog:
* Stable: can be used in production
* isset() instead in_array() where possible (faster)
* Much much better Database loading algorithm (faster)
* Fix Langs and Configs Checks
#22

[eluser]Dewos[/eluser]
Version 1.8:
* Refactor to single static class mode (much much faster). See new Userguide
* methods names === to codeigniter standard functions
#23

[eluser]Dewos[/eluser]
A quick code for use ZEND framework on similar Syntax in Codeigniter

Code:
//Zend
class ZF
{
    private static $zend;

    // Library
    public static function library($library = '', $params = NULL)
    {
        require_once '/zend/Loader.php';

        $prefix = 'Zend_';
        $library_name = $prefix.str_replace('/', '_', $library);
        
        if ( ! isset(self::$zend->$library_name))
        {
            Zend_Loader::loadClass($library_name);
            self::$zend->$library_name = ($params !== NULL) ? new $library_name($params) : new $library_name() ;// TODO: multi params
        }

        return self::$zend->$library_name;
    }
}

Example Usage

Code:
$rss_url = CI::config('rss')->item('url');
$feed_result = ZF::library('feed/rss', $rss_url);

foreach ($feed_result as $rss)
{
    echo $rss->description();
}
#24

[eluser]Dewos[/eluser]
sorry, double submit :|
#25

[eluser]Phil Sturgeon[/eluser]
I STILL don't see the point here dude.

Code:
CI::library('session')->userdata('id')
$this->session->userdata('id')

It's longer!

What does this offer other than lazy-loading?
#26

[eluser]Dewos[/eluser]
[quote author="Phil Sturgeon" date="1259849739"]I STILL don't see the point here dude.

Code:
CI::library('session')->userdata('id')
$this->session->userdata('id')

It's longer!

What does this offer other than lazy-loading?[/quote]

Hi Phil,

Yeah, sometimes it's longer. In Codeigniter, this->load offers only normal-load resources as this simple plugin lazy-loading resources and give you the ability to use procedural resources on the fly (like CI::plugin('name')->do_some()). This's all.

Maybe you can think that is not worth the the effort, but defer initialization of an object until the point at which it is needed is far far far better that put Autoloading on ci's autoload.php (brrr) or in Controller::__construct (brr), or sometimes even on top on you code. If you think that you need certain resources globally throughout your application, in (many cases) you really DON'T.

Code:
## application/congif/autoload.php

$autoload['libraries'] = array('database','session');

## Controller

if ($action =='add')
{
//code
//code
$this->db->get('table');
//code
}
else
{
//code
//code
$this->session->set_userdata('action', 'some');
//code
}

Yes, you can check check check check check... everytimes that everything is loading in the most efficently way (but you're only a "maybe-check-fails" human Smile )... Or you can use this plugin.

By the way i'm open to discussion, so why can't you convert some of your scripts and see?
#27

[eluser]the_yk[/eluser]
Hi dewos, that's a great plugin you made there. I've been using it. And for the long "library" name, I just change it to "lib". So it's shorter ;-)

Btw, I got an error message when trying to load a library which has a capital letter in its name.

Eg:
Code:
CI::this->library('SomeLibrary')->someFunction();

So I add the following line in the library function before the return statement. It fix the problem.
Code:
$library_name = strtolower($library_name);

Anyway, thank's for this great plugin :-)
#28

[eluser]Dewos[/eluser]
[quote author="the_yk" date="1260214112"]Hi dewos, that's a great plugin you made there. I've been using it. And for the long "library" name, I just change it to "lib". So it's shorter ;-)

Btw, I got an error message when trying to load a library which has a capital letter in its name.

Eg:
Code:
CI::this->library('SomeLibrary')->someFunction();

So I add the following line in the library function before the return statement. It fix the problem.
Code:
$library_name = strtolower($library_name);

Anyway, thank's for this great plugin :-)[/quote]

Hi The_yk. Thanks you for the reply Smile
By the way, in your code the "CI::this->" thing is not necessary.
Just do CI::library()...

Code:
CI::library('somelibrary')->someFunction();

Ah, once loaded you can access your class using simple the lower case version. This's a convention from codeigniter's core. Ci LOAD class checks capitalized or lower case anyway, so strtolower is useless.

Good luck Smile
-Dew
#29

[eluser]the_yk[/eluser]
haha, my bad. yeah, the code should be

Code:
CI::library('SomeLibrary')->someFunction();

well, in Windows machine it might not be necessary to use strtolower. But in Linux server, the filename is case sensitive. I happened to have a file named "HtmlDoc.php". If I use CI::library("htmldoc") or CI::library("Htmldoc"), it won't find the file.

If use CI::library("HtmlDoc"), the file is loaded fine. But here's the problem. The class and function name in php isn't case sensitive, but the variable name is. So, using CI::library("HtmlDoc") will return something equivalent to $this->HtmlDoc. Since CodeIgniter's Loader use the lower case version, it should be $this->htmldoc, coz $this->HtmlDoc will generate an error.

Of course I can just change the "HtmlDoc.php" to "htmldoc.php", but if there's so many files like that, it won't be efficient to change every filename to lower case. That's why I think you should consider adding strtolower. Just if you see it fit.

my regards,
~yk~
#30

[eluser]AgentPhoenix[/eluser]
I ran in to a problem with the plugin using it with the User Agent class. The library is loaded by using the string 'user_agent' but the object name is 'agent', so it would throw an error whenever I tried to do something like this:

Code:
CI::Library('user_agent')->browser()

CI's Loader class allows you to assign a new object name to the library, so in order to get it to work properly, you need to do this:

Code:
CI::Library('user_agent', '', 'user_agent')->browser()

Of course, that's incredibly verbose to be using on every line, so I've added a switch statement to the library method of the plugin to take these kinds of things into account.

Code:
switch ($library_name)
{
    case 'user_agent':
        $lib_name = 'agent';
        break;
            
    default:
        $lib_name = $library_name;
}




Theme © iAndrew 2016 - Forum software by © MyBB