Jul 22
ZF 1.8 Bootstrap
icon1 admin | icon2 technical | icon4 07 22nd, 2009| icon31 Comment »

ok i have been playing with zend at home to increase my knowledge, and i have run across this, i think its pretty handy, and gave me much insight in zend’s 1.8 bootstrapping method. i didnt use any of the dojo stuff, mainly because i plan to use jquery for all my dynamic javascripting needs.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    /**
     * Bootstrap autoloader for application resources
     *
     * @return Zend_Application_Module_Autoloader
     */

    public static $root = ;
    public static $registry;  
    public static $db;  
   
    public function getRoot(){
        $path = $_SERVER[‘DOCUMENT_ROOT’];
        if (substr($path,strlen($path) -1,strlen($path)) == ‘/’){
            $path = substr($path,0,strlen($path)-1);
        }
        return $path;
    }    
    protected function _initAutoload() {
        $autoloader = new Zend_Application_Module_Autoloader ( array (‘namespace’ => ‘Default’, ‘basePath’ => dirname ( __FILE__ ) ) );
        Zend_Session::setOptions(array(‘remember_me_seconds’ => 7200));
        Zend_Session::start();
        self::$root = $this->getRoot();
        self::setConfig();
        self::setRegistry();
        self::setTimeZone();
        self::setupDatabase();
        return $autoloader;
    }
    //Date time setting will be done here
    public static function setTimeZone()
    {
        date_default_timezone_set(‘Europe/London’);
    }
    //Configuration file reading & setting up configuration will be done using following.
    public static function setConfig(){
       
        $config = new Zend_Config_Ini(
            self::$root . ‘/../application/configs/application.ini’,APPLICATION_ENV);
            self::$registry->configuration = $config;
            self::$db = self::$registry->configuration->resources->toArray();
    }
   
    public static function setRegistry()
    {
        self::$registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS);
        Zend_Registry::setInstance(self::$registry);
    }

    /*DB setup done here.
    Read configuration, create db instance & set in registry to use in other part of application.*/
 
    public static function setupDatabase()  
    {  
        $config = self::$db;
        $db = Zend_Db::factory($config["db"]["adapter"], $config["db"]["params"]);  
        $db->query("SET NAMES ‘utf8′");  
        self::$registry->database = $db;  
        Zend_Db_Table::setDefaultAdapter($db);  
    }  
   
    protected function _initView() {
        // Initialize view
        $view = new Zend_View ( );
        //$view->doctype(‘XHTML1_STRICT’); /* Quick Change out depending on project */
        $view->doctype ( ‘XHTML1_TRANSITIONAL’ );    /* Quick Change out depending on project */
       
        $view->env = APPLICATION_ENV;
       
        Zend_Dojo::enableView ( $view );
        Zend_Dojo_View_Helper_Dojo::setUseDeclarative ();
        $view->dojo ()->setLocalPath ( "/js/prod/dojo/dojo.js" )
                ->setDjConfigOption ( ‘usePlainJson’, true )
                ->setDjConfigOption ( ‘parseOnLoad’, true )
                ->addStylesheetModule ( ‘dijit.themes.soria’ )
                ->addStylesheet ( ‘/js/prod/dojox/grid/resources/soriaGrid.css’ )
                ->enable ();
        // Add it to the ViewRenderer
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper ( ‘ViewRenderer’ );
        $viewRenderer->setView ( $view );
        // Return it, so that it can be stored by the bootstrap
        return $view;
    }
}

more can be read here i give credit to the guy who wrote this up originally and shared with the rest of the world.

Your Ad Here
Jul 15
fun proof
icon1 admin | icon2 technical | icon4 07 15th, 2009| icon3No Comments »

when i used to work at sperka int’l a while back i wrote a block of javascript for one of our clients, discounttirecenters.com

here are my shenanigans.

it was simple old style ajax image fetcher.
shows how much i love the matrix i guess.

function getimage (matrix, neo, zion, anderson) {
       
        var nebuchadnezzar = document.getElementById(matrix)
        var entermatrix = matrix
        if(window.XMLHttpRequest)
        req = new XMLHttpRequest();
                else if (window.ActiveXObject)
                        req  = new ActiveXObject(‘Microsoft.XMLHTTP’);
                req.onreadystatechange = function()
                { if(req.readyState == 4)
                        { if(req.status == 200){
                                        the_redpill = req.responseText;
                                        nebuchadnezzar.style.display = ‘block’;
                                        if (the_redpill == ) {
                                        nebuchadnezzar.innerHTML = ‘<div><a href="product_detail.php?c=’+anderson+‘&prodID=’+neo+‘"><img src="images/images_products/’+ zion+‘/normal/notire.png" width="150" /></a><br />click for more details<br />’;
                                        } else {
                                        nebuchadnezzar.innerHTML = ‘<div><a href="product_detail.php?c=’+anderson+‘&prodID=’+neo+‘"><img src="images/images_products/’+ zion+‘/normal/’+the_redpill+‘" width="150" /></a><br />click for more details<br />’;
                                        }
                               
                                       
                                }else {
                                        document.getElementById(‘errors’).innerHTML="Error: returned status <br />code " + req.status + " " + req.statusText;
                                }
                        }
                };
                req.open("GET", "option_populater.php?imagecheck=" + neo + "&whichDB=" + zion, true);
                req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                req.send(null);
}

Your Ad Here
Jun 30

for some reason there are lot of tutorials coming out of the UK. this is just one of them. good read on OO javascript.

nefariousdesigns.co.uk

Your Ad Here
Jun 27
bash loops part 2
icon1 admin | icon2 technical | icon4 06 27th, 2009| icon3No Comments »

so in a previous post i put up a how to do on renaming files in a for loop and string replacing. here is another example for taking files and renaming them all with lovely counts as well.

here is the line of code. that we will execute.

james@lappy2000:~/ count=1; for i in *.mp3; do mv "$i" "myband_${count}.mp3"; : $((count=count+1)); done

lets break it down for more details.
first off here is the count, we shall start with 1, you can start with any number you wish.

count=1;

your for loop, niotice we are putting the count in ${count}, now you can do this, or $count. either way is correct.

do mv  for i in *.mp3; do mv "$i" "myband_${count}.mp3";

you now see this. the colon basically says im a new command in this “do” section. and the double parens basically mean treat the insides like a variable.

: $((count=count+1));

thats basically it.

Your Ad Here
Jun 17

this is my jquery-ui dialog resizer.
ever have a dialog box that you wanted to re-size dynamically?
for instance, you have a form and w/in the form you have some additional items that are hidden and only want them to display if the user selects a certain parameter. well you can hide the items, and then when you want to show it, have the dialog magically re-size to accomodate

you can grab the code over at google docs.
http://code.google.com/p/jquerydialogresize/

if you have any questions on use. point your comments to the google groups.

I’ll have a demonstration here soon.

Your Ad Here

« Previous Entries