GGshow reloaded GGshow reloaded

July 4, 2012

Zend Framework – CLI – Module

  • Create module
    zf create module <moduleName>
  • Create dbTable class in module
    zf create db-table <className> <tableName> <moduleName>
  • Create model in module
    zf create model <mapperName> <moduleName>
  • Create controller in module
    zf create controller <controllerName> index-action-included[=1] <moduleName>
  • Create form in module
    zf create form <formName> <moduleName>
  • Create action in module
    zf create action <actionName> <controllerName>[=Index] view-included[=1] <moduleName>
  • Create view in module
    zf create view <controllerName> <actionName> <moduleName>
Filed under: PHP,Web,Zend Framework — Tags: , , , , , , , , — GG @ 2:50 pm

Zend Framework – View Helper – Placeholder

Example usage for place holders:

  • doctype()
  • headTitle()
  • headMeta()
  • headLink()
  • headStyle()
  • headScript()
  • inlineScript()

DOCTYPE

$view->doctype('HTML5');

Title

$view->headTitle('Site Title');
$view->headTitle('Site Title')
	->setSeparator(' :: ');

Meta

$view->headMeta()->appendName('keywords', 'page, keywords')
	->appendName('description', 'page description')
	->appendName('author', 'author name');

Refresh

$view->headMeta()->appendHttpEquiv('Refresh','30');

Redirect

$view->headMeta()->appendHttpEquiv('Refresh','0;url=http://www.ggshow.com');

Disable client side cache

$view->headMeta()->appendHttpEquiv('expires','-1')
	->appendHttpEquiv('pragma', 'no-cache')
	->appendHttpEquiv('Cache-Control', 'no-cache');

Setting content type and character set

$view->headMeta()->setCharset('utf-8');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
	->appendHttpEquiv('Content-Language', 'en-US');

Favicon with headLink

$view->headLink(array('rel' => 'favicon', 'href' => 'favicon.ico'),'PREPEND');
$view->headLink(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => 'favicon.ico'),'PREPEND');

CSS with headLink

$view->headLink()->appendStylesheet('style.css');

// appendStylesheet, prependStylesheet, setStylesheet, offsetStylesheet, appendAlternative, prependAlternative, setAlternative, offsetAlternative

CSS with headStyle

$view->headStyle->captureStart();
?>
body { margin: 0; }
<?php
$view->headStyle->captureEnd();

JavaScript

$view->headScript()->appendFile(“script.js”);
$view->headScript()->prependFile(“script.js”);
$view->inlineScript()->appendFile(“script.js”);
$this->headScript()->appendFile('script.js', 'text/javascript', array('conditional' => 'lt IE 7') );

Example output (within layout/view)

echo $this->headTitle();
echo $this->headLink();
echo $this->headMeta();
echo htmlentities($view->headMeta()->setPostfix("n"));

Example layout with placeholders

<?php echo $this->doctype() ?>
<html>
	<head>
		<?php echo $this->headTitle() ?>
		<?php echo $this->headScript() ?>
		<?php echo $this->headStyle() ?>
	</head>
	<body>
		<?php echo $this->layout()->content; ?>
		<?php echo $this->inlineScript() ?>
	</body>
</html>

Zend Framework – View

To get the view object

  1. witin view script
    $view = $this;
  2. within action controller
    $view = $this->view;
  3. within bootstrap
    $this->bootstrap(‘view’);
    $view = $this->getResource(‘view’);
  4. within resource plugin
    $this->getBootstrap()->bootstrap('view');
    $view = $this->getBootstrap()->getResource('view');
Filed under: PHP,Web,Zend Framework — Tags: , , , , — GG @ 2:30 pm

Zend Framework – View Helper – Layout

To get layout object

  • within view script
    $layout = $this->layout()
  • within action controller
    $layout = $this->_helper->layout()
    $layout = $this->_helper->getHelper(‘Layout’)->getLayoutInstance()
  • within bootstrap
    $layout = $bootstrap->getResource(‘Layout’);
  • elsewhere
    $layout = Zend_Layout::getMvcInstance();

To assign variable to layout object

$layout->var = ‘value’;
$layout->assign(‘var’, ‘value’);

To enable or disable layout

$layout->enableLayout();
$layout->disableLayout();

To enable or disable layout using CLI

zf enable layout
zf disable layout
Filed under: PHP,Web,Zend Framework — Tags: , , , , , — GG @ 2:27 pm

Zend Framework – CLI

  • Show info
    zf show < config | manifest | phpinfo | profile | project.info | version >
  • Create project
    zf create project <projectName>
  • Enable layout
    zf enable layout
  • Create dbTable class
    zf create db-table <className> <tableName>
  • Create model
    zf create model <mapperName>
  • Create controller
    zf create controller <controllerName>
  • Create form
    zf create form <formName>
  • Create action
    zf create action <actionName> <controllerName>
  • Create view
    zf create view <controllerName> <viewName>
user@ubuntu:~$ zf ?
Zend Framework Command Line Console Tool v1.11.11
Usage:
    zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts] [provider parameters ...]
    Note: You may use "?" in any place of the above usage string to ask for more specific help information.
    Example: "zf ? version" will list all available actions for the version provider.

Providers and their actions:
 Version
    zf show version mode[=mini] name-included[=1]
    Note: There are specialties, use zf show version.? to get specific help on them.

 Config
    zf create config
    zf show config
    zf enable config
    Note: There are specialties, use zf enable config.? to get specific help on them.
    zf disable config
    Note: There are specialties, use zf disable config.? to get specific help on them.

 Phpinfo
    zf show phpinfo

 Manifest
    zf show manifest

 Profile
    zf show profile

 Project
    zf create project path name-of-profile file-of-profile
    zf show project
    Note: There are specialties, use zf show project.? to get specific help on them.

 Application
    zf change application.class-name-prefix class-name-prefix

 Model
    zf create model name module

 View
    zf create view controller-name action-name-or-simple-name module

 Controller
    zf create controller name index-action-included[=1] module

 Action
    zf create action name controller-name[=Index] view-included[=1] module

 Module
    zf create module name

 Form
    zf enable form module
    zf create form name module

 Layout
    zf enable layout
    zf disable layout

 DbAdapter
    zf configure db-adapter dsn section-name[=production]

 DbTable
    zf create db-table name actual-table-name module force-overwrite
    Note: There are specialties, use zf create db-table.? to get specific help on them.

 ProjectProvider
    zf create project-provider name actions

Related Articles:

Filed under: PHP,Web,Zend Framework — Tags: , , , , , , , , , , — GG @ 2:24 pm

March 24, 2012

Web Development Environment in Ubuntu Linux

PART 1 – Ubuntu
Ubuntu is a computer operating system based on the Debian Linux distribution and distributed as free and open source software, using its own desktop environment.

  1. Download & install Ubuntu Linux.
  2. Update package index and upgrade OS.
    To update package index
    sudo apt-get update

    To upgrade all installed packages

    sudo apt-get upgrade
  3. Installing software packages
    To install a package
    sudo apt-get install <package-name>

    To remove a package

    sudo apt-get remove <package-name>

PART 2 – LAMP
LAMP is an acronym for a solution stack of free, open source software, referring to the first letters of Linux (operating system), Apache HTTP Server, MySQL (database software) and PHP (or sometimes Perl or Python), principal components to build a viable general purpose web server.

  1. Install LAMP
    To install Apache 2, MySQL 5, PHP 5, Apache PHP5 module, PHP MySQL package.
    sudo apt-get install apache2
    sudo apt-get install mysql-server
    sudo apt-get install mysql-client
    sudo apt-get install php5
    sudo apt-get install libapache2-mod-php5
    sudo apt-get install php5-mysql 

    or simply

    sudo apt-get install lamp-server^

    to install all packages below:
    perl-modules apache2 mysql-server-core-5.1 mysql-client-core-5.1 perl libmysqlclient16 libdbi-perl apache2-mpm-prefork apache2.2-common apache2.2-bin apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcap2 ssl-cert libwrap0 mysql-server libapache2-mod-php5 php5-common php5-cli libclass-isa-perl libdbd-mysql-perl libplrpc-perl libhtml-template-perl mysql-common libnet-daemon-perl libpod-plainer-perl libswitch-perl tcpd mysql-client-5.1 mysql-server-5.1 php5-mysql

PART 3 – Optional Packages

  1. Zend Framework Zend Framework is an open source, object oriented web application framework for PHP 5.
    To install Zend Framwork CLI
    sudo apt-get install zend-framework-bin
  2. PHPUnit PHPUnit is a unit testing software framework for PHP.
    To install PHPUnit
    sudo apt-get install php-pear
    sudo pear channel-update pear.php.net
    sudo pear channel-discover pear.phpunit.de
    sudo pear channel-discover pear.symfony-project.com
    sudo pear update-channels
    sudo pear upgrade-all
    sudo pear install --alldeps phpunit/PHPUnit
    sudo apt-get install phpunit

    or

    sudo apt-get install php-pear
    sudo pear update-channels
    sudo pear config-set auto_discover 1
    sudo pear install --alldeps pear.phpunit.de/PHPUnit
    sudo apt-get install phpunit
  3. Xdebug
    Xdebug is a PHP extension which provides debugging and profiling capabilities.
    To install Xdebug
    sudo apt-get install php5-xdebug

    Add the following lines into etc/php5/conf.d/xdebug.ini if it does not exist.

    zend_extension = “/usr/lib/php5/20090626-lfs/xdebug.so”
    xdebug.remote_enable=on
    xdebug.remote_handler=dbgp
    xdebug.remote_host=localhost
    xdebug.remote_port=9000
  4. Optional PHP extensions
    To install PHP extensions
    sudo apt-get install php5-cgi php5-cli php5-curl php5-gd php5-idn php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-mysql php5-pgsql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

    * install only which needed.

  5. MySQL GUI tools
    1. Install MySQL Administrator and MySQL Query Browser
      sudo apt-get install mysql-admin
      sudo apt-get install mysql-query-browser

      and/or

    2. Install MySQL Workbench
      sudo apt-get install mysql-workbench
      sudo apt-get install mysql-query-browser

      and/or

    3. Install phpMyAdmin
      sudo apt-get install phpmyadmin

      Add the following line into /etc/apache2/apache2.conf

      Include /etc/phpmyadmin/apache.conf
  6. Integrated Development Environment
    1. Eclipse
      Install Eclipse IDE
      sudo apt-get install eclipse

      Install PHP Development Tools (PDT)

      sudo add-apt-repository ppa:yogarine/eclipse/ubuntu
      sudo apt-get update
      sudo apt-get install eclipse-pdt

      and/or

    2. Netbeans IDE
      Download & install Netbeans IDE
      Install Java
      sudo apt-get install sun-java6-jdk sun-java6-jre

      Download & install Netbeans

      sudo sh ./netbeans-7.1.1-ml-php-linux.sh

      Install Netbeans

      sudo apt-get install netbeans

      Or download & install the Java SE and NetBeans Cobundle

      sudo sh ./jdk-7u3-nb-7_1_1-linux-ml.sh
  7. Web browser debugging tool
    1. Firebug Install Firebug. or
    2. Developer tools in Chromium Browser Install Chromium Browser
      sudo apt-get install chromium-browser

      Press Ctrl+Shift+I to open Developer Tools

  8. Install version control system
    1. Subversion
      Subversion (SVN) is a software versioning and revision control system distributed under an open source license.
      Install Subversion
      sudo apt-get install subversion
      sudo apt-get install libapache2-svn
    2. Git
      Git is a distributed revision control and source code management (SCM) system with an emphasis on speed.
      Install Git
      sudo apt-get install git-core
      sudo apt-get install git-doc
      sudo apt-get install git-svn
      sudo apt-get build-dep git-core git-doc git-svn

PART 4 – Packages version
To check installed packages version

apache2 -v
php -v
mysql -V
phpunit --version
git --version
svn --version
java -version
zf show version
Filed under: Linux,MySQL,PHP,Web,Zend Framework — Tags: , , , , , — GG @ 10:26 pm

February 3, 2012

Duplicated placeholder output

Issue:

  • Zend Framework placeholder (headTitle, headMeta, headLink, headScript, headStyle, inlineScript) creates twice or multiple title/meta/link/script tags in HTML.
  • Duplicated title/meta/link/script tags generated from Zend Framework placeholder.
  • e.g.:

    source:

    <?php echo $this->headScript()->appendFile("/scripts/global.js") ?>
    <?php echo $this->headScript()->appendFile("/scripts/main.js") ?>

    output:

    <script src="/scripts/global.js" type="text/javascript"></script>
    <script src="/scripts/global.js" type="text/javascript"></script>
    <script src="/scripts/main.js" type="text/javascript"></script>

Reason:

  • Echo will output all elements in a placeholder.

Solution:

  • Echo only once for each placeholder.
  • e.g.:
    <?php $this->headLink()->appendStylesheet('/styles/global.css') ?>
    <?php $this->headLink()->appendStylesheet('/styles/main.css') ?>
    <?php echo $this->headLink() ?>
    
    <?php $this->headScript()->appendFile("/scripts/global.js") ?>
    <?php $this->headScript()->appendFile("/scripts/main.js") ?>
    <?php echo $this->headScript() ?>
Filed under: CSS,JavaScript,PHP,Web,Zend Framework — Tags: , , — GG @ 11:15 am

Resource matching “view” not found

Issue:

  • [error]
    [client 127.0.0.1] 
    PHP Fatal error:  Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "view" not found' in /home/user/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/BootstrapAbstract.php:694
    Stack trace:
    #0 /home/user/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/BootstrapAbstract.php(629): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('view')
    #1 /home/user/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap('view')
    #2 /home/user/ZendFramework-1.11.11/bin/jquery/application/Bootstrap.php(7): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap('view')
    #3 /home/user/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initDoctype()
    #4 /home/user/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('doctype')
    #5 /home/user/ZendFramework-1.11.11/library/Zend/Appli in /home/user/ZendFramework-1.11.11/library/Zend/Application/Bootstrap/BootstrapAbstract.php on line 694

Reason:

  • Resource matching “view” not found.

Solution:

  • Add the following line to application.ini
    resources.view[] =
Filed under: PHP,Web,Zend Framework — Tags: , , — GG @ 11:02 am

January 15, 2012

Double/Multiple execute of bootstrap

Issue:

  • bootstrap is being executed twice.
  • specified action is being called twice.
  • counter increased twice per hit.

Reason:

  • Web browser loads a file which is not exist, either through src or href attribute with invalid or empty value (e.g. favicon.ico, global.css, & etc.), web server treats it as “Page not found” error (404).
  • Default configuration for Zend application, the default application (index.php) will handle error 404, an error message “Invalid controller specified” will be displayed, indirectly causing code in bootstrap.php also being executed.

Solution:

  • Create a favicon.ico in DocumentRoot. and
  • Prevent loading any file which is not exist. or
  • Modify web server configuration (httpd.conf or .htaccess),
    rewrite rule to exclude paths for specified file type.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} (.*).(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt|swf)$
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
Filed under: PHP,Web,Zend Framework — Tags: , , — GG @ 1:43 am

Call to undefined function token_get_all()

Issue:

  • Unable to create action using Zend Framework Command Line Tool.
    Fatal error: Call to undefined function token_get_all() in C:Program FilesZend
    ZendServershareZendFrameworklibraryZendReflectionFile.php on line 301

Reason:

  • PHP tokenizer extention has not been enabled.

Solution:

  • If PHP compiled without tokenizer (–disable-tokenizer), recompile it with tokenizer (–enable-tokenizer).
  • If PHP configuration has not enabling tokenizer, edit php.ini, add or uncomment the tokenizer extension.
    extension=tokenizer.so

    or

    extension=php_tokenizer.dll
Filed under: PHP,Web,Zend Framework — Tags: , , , — GG @ 1:21 am
Older Posts »

© 2017 GGSHOW | Powered by WordPress