Showing posts with label Zend Framework Tutorial. Show all posts
Showing posts with label Zend Framework Tutorial. Show all posts

Wednesday, 22 May 2013

How to create session in zend framework 1.12?

Hi All,

Use following script to create session:

$mysession = new Zend_Session_Namespace('mysession');   
$mysession->counter = 1000;

Regards,

Monday, 19 April 2010

What are the components in Zend Framework?

The following are components zend including:
  • Zend_Acl (both Roles and Resources)
  • Zend_Auth provides an API for authentication
  • Zend_Cache provides a flexible approach toward caching data
  • Zend_Controller and Zend_View
  • Zend_Rest_Client and Zend_Rest_Server (Web Services)
  • Zend_XmlRpc
  • Zend_Feed, Zend_Filter and Zend_Validate
  • Zend_Gdata (Zend Google Data Client): Google Data APIs provide read/write access to such services hosted at google.com as Spreadsheets, Calendar, Blogger, and CodeSearch.
  • Zend_Json, Zend_Memory
  • Zend_Pdf (Can create or read PDF documents on the fly, without the need to call utilities from the shell. Zend_Pdf can modify existing PDF documents.)
  • Zend_Registry
  • Zend_Search_Lucene

Tuesday, 6 April 2010

How __autoload() does?

Autoload is a new feature introduced in PHP5 that you don't have to explicitly require or include a PHP script file that contains the class being used any more but it will be automatically loaded or included when needed.

For example, with PHP4 you would have to write something like this:

require_once("foo.php"); // foo.php contains the class Foo
myFoo = new Foo();

Every time you need to create an object of some class you have to include/require the particular PHP file
that contains that class.
It can be a challenge to manage the whole lot of include or require lines as well.
That's where the autoload feature of PHP5 kicks in.

Instead of including a particular PHP script every time we need it, we create a very simple function at the beginning of the current file so that PHP automatically knows what file to include when we need a particular class.
For example:
function __autoload($className)
{
    require_once 'includes/classes/'. $className. '.php';
}

$obj1 = new MyNewClass1(); // PHP automatically requires 'includes/classes/MyNewClass1.php'
$obj2 = new MyNewClass2(); // PHP automatically requires 'includes/classes/MyNewClass2.php'

Friday, 26 March 2010

How to setup zend framework?

mysite
    /application
        /controllers
            IndexController.php
        /models
            IndexModel.php
        /forms
            LoginForm.php
        /views
            /scripts
                /index
                    index.phtml
    /libaray
        /Zend
/js
    /css
    /images
    /index.phtm
 
 <?php
define('ROOT_DIR', dirname(__FILE__));

set_include_path('.'
. PATH_SEPARATOR . ROOT_DIR . '/library'
. PATH_SEPARATOR . ROOT_DIR . '/application/models'
. PATH_SEPARATOR . ROOT_DIR . '/application/forms'
. PATH_SEPARATOR . get_include_path()
);

require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();

$frontController = Zend_Controller_Front::getInstance();

$frontController->throwExceptions(true);

$frontController->setControllerDirectory(ROOT_DIR.'/application/controllers');
$frontController->dispatch();
?>
 
 <?php
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
    }
}
 
 Now if you browse
http://localhost/mysite/

You will see
Hello World 
If you don’t see “Hello world” printed, read the above guide lines again.
As
we have now successfully created directory structure and bootstrap
file, its time to make other necessary configuration for database.

4. Configuration for working with database
How
a web application can be completed without usage of database. Different
web application uses different database. Some uses Mysql, other SQLite,
SQL server and Oracle. One of the nice thing about Zend Framework is
that it support multiple database servers. 
Here we are going to making configuration for Mysql server.
For database configuration, first create config.ini in mysite/application/ and write the following code in it.
 
 [general]
db.adapter = PDO_MYSQL
db.params.host = localhost
db.params.username = root
db.params.password = 
db.params.dbname = zend_framework
 
<?php
define('ROOT_DIR', dirname(__FILE__));

set_include_path('.'
. PATH_SEPARATOR . ROOT_DIR . '/library'
. PATH_SEPARATOR . ROOT_DIR . '/application/models'
. PATH_SEPARATOR . ROOT_DIR . '/application/forms'
. PATH_SEPARATOR . get_include_path()
);

require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();

$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);

$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory(ROOT_DIR.'/application/controllers');
$frontController->dispatch();
?>