Tuesday, January 10, 2012

Zend Pagination

Get the results in controller and assign to view.

Inside controller 


$users = $user->getAllUsers();
Zend_Paginator::setDefaultScrollingStyle('Sliding');
Zend_View_Helper_PaginationControl::setDefaultViewPartial(
'pagination_control.phtml'
);

$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($users));
$paginator->setView($this->view);

$page = $this->_getParam('page');
if( $page == null || $page == ""){
$page = 1;
}
$paginator->setItemCountPerPage(20);
$paginator->setCurrentPageNumber($page);
$this->view->paginator = $paginator;

Inside View


<?php echo $this->paginator; ?>
//Will render first, page numbers, and last anchor tags
<?php foreach ($this->paginator as $item): ?>
<input type="checkbox" />
<?php echo $item['name'] ?>
<?php echo $item['email'] ?>
<?php endforeach; ?>

Inside Pagination_controller.phtml

<?php if ($this->pageCount): ?>
<div class="pagination">
<?php if (isset($this->previous)): ?>
 
< a href="<?php echo $this->url(array('page' => $this->previous)); ?>" title="Previous Page">« Previous</a>"<?php else: ?>
<span class="disabled">« Previous</span>
<?php endif; ?>

<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
< a href="<?php echo $this->url(array('page' => $page)); ?>" class="number" title="1"> <?php echo $page; ?></a>
<?php else: ?>
<?php echo $page; ?>
<?php endif; ?>
<?php endforeach; ?>

<?php if (isset($this->next)): ?>
< a href="<?php echo $this->url(array('page' => $this->next)); ?>" title="Next Page">Next »</a>
<?php else: ?>
<span class="disabled">Next »</span>
<?php endif; ?>
</div>
<?php endif; ?>

Wednesday, January 4, 2012

Openshift with MySQL PHPMyAdmin

Click here to set up the Openshift server with Ubuntu.

Install Mysql for Openshift

/var/lib/gems/1.8/bin/rhc-ctl-app -a APPNAME -e add-mysql-5.1 -l EMAILID -p PASSWORD

Now Mysql is installed and access details will be obtained after running the above command.

Install PHPMyAdmin 

Download PHPMyadmin 

wget http://superb-dca2.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.8/phpMyAdmin-3.4.8-all-languages.zip

Go to application folder (local) and unzip the downloaded file

cd APP_FOLDER_NAME/phpunzip ../../phpMyAdmin-3.4.8-all-languages.zip

Rename the folder (name will be used to access the mysql [domainname/phpmyadmin_foldername])

mv phpMyAdmin-3.4.8-all-languages phpmyadmin

Update Configuration file for phpmyadmin

cd phpmyadmincp config.sample.inc.php config.inc.phpupdate config.inc.php$cfg['blowfish_secret']     = 'some value'; //COOKIE AUTH$cfg['Servers'][$i]['host'] = 'hostadress'; //host address obtained on mysql installation

Add files to be pushed to the server, and commit the changes

git add -Agit commit -m 'phpmyadmin setup'git push 

After pushing the changes to server, mysql can be accessed through
DOMAINNAME/phpmyadmin
e.g. http://sreejithblog-sreejithblog.rhcloud.com/phpmyadmin

Then login using the credentials obtained on MySql installation

Openshift with Ubuntu

Step 1 :: Install rubygems and openssh

sudo apt-get install git-core openssh-client ruby-full  sudo apt-get install rubygems1.8

Step 2 :: Install gems

sudo gem install --source http://gems.rubyforge.org --source https://openshift.redhat.com/app/repo/ rhc

Step 3 :: Create domain using RHC command

/var/lib/gems/1.8/bin/rhc-create-domain -n DOMAIN_NAME -l EMAILID -p PASSWORD

RHLogin is required
Domain name :: doesnt support non-alphanumeric characters
EMAILID :: registered login id for Redhat or Openshift which has express access
PASSWORD :: Login password 

Step 4 :: Create application ( with valid application type [raw-0.1, php-5.3, jbossas-7.0, rack-1.1, jenkins-1.4, perl-5.10, wsgi-3.2])

/var/lib/gems/1.8/bin/rhc-create-app -a APP_NAME -t php-5.3 -l EMAILID -p PASSWORD

Step 5 :: Repo folder will be created in the local machine also, now the application can be updated and commited to the server using git commands (git push).

Ref Adding Zend Application :: http://jango.posterous.com/deploying-zend-app-on-openshift

Tuesday, January 3, 2012

Zend Render a different Layout

You can add this in action controller.

$this->_helper->layout->setLayout('login');

Fire PHP DB profiler Zend

Add in bootstrap
 

$resource = $this->getPluginResource('db');                $db = $resource->getDbAdapter();                                    $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');                $profiler->setEnabled(true);                $db->setProfiler($profiler);