These are just the first of many planned video tutorials on the Zend web application framework for PHP.
These particular videos require a little more background
knowledge from the viewer, in terms of overall php development
experience.
Source: http://www.killerphp.com/zend-framework/videos/
1. Setting Up an MVC Structure with the Zend Framework - Part 1
2. Setting Up an MVC Structure with the Zend Framework - Part 2
3. Setting Up Zend Development - Part 1
4. Setting Up Zend Development - Part 2
5. Zend Controller and Zend View
Tuesday, January 31, 2012
Thursday, January 26, 2012
Zend Framework: partial() and render()
partial() will render a view script, and render() will render a view script. So… which one do I have to use?
All depends on the variable scope.
All depends on the variable scope.
Render()
The render() function will render the given view script within the variable scope of the script is was called from.$this->render('controllername/actionname');
Partial()
partial() will also render the given view script, but you can define a special variable scope: you can pass all requested parameters in an array.$this->partial('controllername/actionname', array('var1' => 'value 1', 'var2' => 'value 2'));
If you want to render a script from another module, for example( if ypu are in a frontend module, and for some reason you want to render a view from background cms module )
$this->partial('controllername/actionname', 'cms_module_name', array('var1' => 'value 1', 'var2' => 'value 2'));
Wednesday, January 18, 2012
3 Jquery plugins To Deal With Image Cropping
Jcrop
- Attaches simply to any image in your HTML page
- Supports aspect ratio locking
- Callbacks for selection done, or while moving
- Keyboard support for nudging selection
- Support for CSS styling
- Advanced API including animation support
- Firefox 3
- Safari 3
- Opera 9.5
- Google Chrome Beta
- Internet Explorer 6+
GitHub : https://github.com/tapmodo/Jcrop
jQuery PhotoShoot Plugin 1.0
The jQuery PhotoShoot plugin gives you the ability to convert any div on your web page into a photo shooting effect, complete with a view finder. You can check out the demonstration above, or a nice tutorial on how to use it here.
The plug-in depends on version 1.3.2 of jQuery, but will work fine with newer versions as well.
Demo : http://demo.tutorialzine.com/2010/02/photo-shoot-css-jquery/demo.htmlOfficial site : http://tutorialzine.com/2010/02/jquery-photoshoot-plugin/
Download link : demo.tutorialzine.com/2010/02/photo-shoot-css-jquery/photoShoot-1.0.zip
imgAreaSelect
imgAreaSelect is a jQuery plugin for selecting a rectangular area of an image. It allows web developers to easily implement image cropping functionality, as well as other user interface features, such as photo notes (like those on Flickr).
Plugin features:
- Highly configurable
- Customizable with CSS styling
- Handles scaled images
- Keyboard support for moving and resizing the selection
- Supports callback functions
- Provides API functions for easier integration with other application components
- Lightweight — the packed version is less than 8KB
Official site : http://odyniec.net/projects/imgareaselect/
Examples : http://odyniec.net/projects/imgareaselect/examples.html
Download link : odyniec.net/projects/imgareaselect/jquery.imgareaselect-0.9.8.zip
Wednesday, January 11, 2012
Firebug and Logging
Having a fancy JavaScript debugger is great, but sometimes the fastest
way to find bugs is just to dump as much information to the console as
you can. Firebug gives you a set of powerful logging functions that you
can call from your own web pages.
Url: http://getfirebug.com/logging
Url: http://getfirebug.com/logging
Monday, January 9, 2012
How to print_r() Zend_Session_Namespace?
$session = new Zend_Session_Namespace('default');
foreach ($session as $index => $value) {
echo "session->$index = '$value';<br />";
}
Wednesday, January 4, 2012
Zend db examine SQL query -- Profiler
You can use Zend_db_profiler to capture and examine the sql queries
or statements that Zend db adapter forms and executes. example:
source: http://stackoverflow.com/questions/1009639/zend-db-framework-examine-query-for-an-update
$db->getProfiler()->setEnabled(true); $db->update($data, array('id = ?' => $Posts->id)); print $db->getProfiler()->getLastQueryProfile()->getQuery(); print_r($db->getProfiler()->getLastQueryProfile()->getQueryParams()); $db->getProfiler()->setEnabled(false);
it's important to set the profiler's enabled property to false (last
line) after using it as it uses up resources and slows down database
transactions.source: http://stackoverflow.com/questions/1009639/zend-db-framework-examine-query-for-an-update
Simple Zend Router example
The default routing setup for Zend is ':module/:controller/:action/*'
The following example will create a route that will only be triggered if the first directory after the public directory (normally used to specify the controller) contains an underscore.
Create a new ini file named route.ini and save it where you save your ini files:
Url's that contain fit the defined regex pattern (\w+_\d+) will be handled by the categoryAction in the indexControler.
Other url's will be handled normally by the defaut routing system.
The following example will create a route that will only be triggered if the first directory after the public directory (normally used to specify the controller) contains an underscore.
Create a new ini file named route.ini and save it where you save your ini files:
routes.popular.route = :catid/:articleid routes.popular.defaults.controller = index routes.popular.defaults.action = category routes.popular.defaults.catid = 52 routes.popular.defaults.articleid = 1 routes.popular.reqs.catid = \w+_\d+
Now add a method to your bootstrap class:public function _initRouter() { $frontController = Zend_Controller_Front::getInstance(); $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/route.ini'); $router = $frontController->getRouter(); $router->addConfig($config,'routes'); }
Done.Url's that contain fit the defined regex pattern (\w+_\d+) will be handled by the categoryAction in the indexControler.
Other url's will be handled normally by the defaut routing system.
Access view inside custom view helper
To access the view instance from your homemade view helper you just
need to create a setView method and view property. This will be
automatically called upon instantiation, setting the view variable to
point at the view instance.
Example:
Example:
class Zend_View_Helper_Navigate { public $view; function setView($view){ $this->view = $view; } function navigate(){ //more helper code } }
Change layout file
To choose another layout file inside your controller all you need to do is call the layout helper like so:
Now the layout file is second.phtml
$this->_helper->layout->setLayout('second');
Now the layout file is second.phtml
Zend image captcha
This is just a quick example of Zend Framework Captcha image component in a form.
This is the action inside the controller :
This is the action inside the controller :
function captchatestAction(){ if (isset($_POST['cid'])){ $capId = trim($_POST['cid']); $capSession = new Zend_Session_Namespace('Zend_Form_Captcha_'.$capId); if ($_POST['captcha'] == $capSession->word) { //success $this->view->human = 1; return; // end action execution here } } $captcha = new Zend_Captcha_Image(); $captcha->setImgDir(APPLICATION_PATH . '/../public/img/captcha/'); $captcha->setImgUrl($this->view->baseUrl('/img/captcha/')); $captcha->setFont(APPLICATION_PATH . '/../public/css/Arial.ttf'); $captcha->setWordlen(5); $captcha->setFontSize(28); $captcha->setLineNoiseLevel(3); $captcha->setWidth(90); $captcha->setHeight(64); $captcha->generate(); $this->view->captcha = $captcha; }
This is the view code (captchatest.phtml) :
<?php if (isset($this->captcha)){ ?><form method = "post" action = "<?= $this->baseUrl() ?>/index/captchatest/"> <input id="captcha" type="text" name="captcha" /> <?php echo $this->captcha->render($this, null) ?> <input type="hidden" name="cid" value="<?php echo $this->captcha->getId() ?>" > </form> <?php } if (isset($this->human)){ echo 'human'; }?>
Subscribe to:
Posts (Atom)