Starting with Symfony2 – Troubleshooting number #1
Introduction
So I decided to join the "club" and try Symfony2 finaly.
I have to say that I am not familiar with most of this framework and it's power but from what I saw and read till now it seems to be promising.
I am not going to describe much about Symfony2 as I think there is enough documentation out there regarding to that.
More than that, Symfony2 has a great documentation and examples which make everything straight forward.
Description
I was reading the Doctrine chapter in Symfony's book. While reading and trying the chapter's examples I was having some troubles with an annoying error:
Class "Acme\StoreBundle\Entity\Product" sub class of "" is not a valid entity or mapped super class.
The error occurred after trying the ORM Repository example.
Suggested Solution
I Googled the issue for sometime and found two available websites that were suggesting solutions for the above issue:
- http://wildlyinaccurate.com/eaccelerator-and-doctrine-2
- http://stackoverflow.com/questions/7820597/class-xxx-is-not-a-valid-entity-or-mapped-super-class-after-moving-the-class-i
One of the suggested solution was to make sure that eAccelerator is not running as it might cause problems.
I checked my PHP modules (php -m | grep -i "eaccelerator") and I found out that I was using it and removed it (from php.ini or php.d/eaccelerator.ini).
After doing that I restarted Apache and everything worked as expected
Summary
Basically this issue is related to Doctrine but I was working with Symfony so I preferred to post about both.
Hope I helped,
Shak.
Extend your .properties files while using Phing
Description
First, those of you which don't know Phing I suggest to take a quick look at their website
For sometime I was hoping to get into writing this small task so I would be able to decouple some un-useful code\configuration.
One of the problems when using Phing and it's .properties file is that you have to rewrite your configuration when using more than one configuration file.
Suggested Solution
I have added a new task for Phing and a new Properties class:
- PropertiesFileTask.php - the task itself uses PropertiesFile class instead of the base Properties class.
- PropertiesFile.php - checks if the .properties file extends another file and load it recursively.
[Shaked] >> phing build.xml Buildfile: /var/www/html/phingextendedproperties/build.xml Environment please [dev] ?
dev:
[propertiesfile] Loading /var/www/html/phingextendedproperties/properties/dev.properties
build > default:
[echo]
You are using 'dev'
Dummy is:
'dummy1'
'dummy2'
'dummy3'
Enjoy!
BUILD FINISHED
Total time: 1 minutes 23.49 seconds
stage:
[propertiesfile] Loading /var/www/html/phingextendedproperties/properties/stage.properties
build > default:
[echo]
You are using 'stage'
Dummy is:
${application.dummy1}
'dummy2'
'dummy3'
Enjoy!
BUILD FINISHED
Total time: 1.0277 second
prod:
[propertiesfile] Loading /var/www/html/phingextendedproperties/properties/prod.properties
build > default:
[echo]
You are using 'prod'
Dummy is:
${application.dummy1}
${application.dummy2}
'dummy3'
Enjoy!
BUILD FINISHED
Total time: 8.7317 seconds
Please share your opinion and thoughts about the solution or about other ways to solve this issue.
Shak
Yii Framework – introduction and more
Description
Yii is a high-performance PHP framework best for developing Web 2.0 applications.
Yii comes with rich features: MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc. It can reduce your development time significantly.
Requirements
Yii supplies an easy way to know what kind of modules and such are required to use its power.
Zend Framework, Gmail, SMTP and SSL
Topic says everything, isn't it?
Description
I had a problem sending emails while using Zend Framework with Gmail account. So I had to handle different types of errors:
- "Unable to connect via TLS" - being created by Zend Framework Exception.
- "Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?" - PHP built in error message
Suggestions
PHP Managing zip files with ZipArchive
Requirements
- PHP 5.2 or greater (would be a bit sad to know that someone is still using PHP 4)
- Upgrade PEAR to latest version
- Upgrade PECL to latest version
- Installing PHP ZipArchive library by using PECL's zip package
Installation
I will use pecl to install ZipArchive PHP library.
- Open terminal and execute pecl install zip
- Updating your php.ini:
- Linux: find your php.ini file and add "extension=zip.so"
- Windows: same as one, just add "extension=zip.dll"
- service httpd restart
- apache2ctl restart
- or any other way that you like
Usage Example
There are many different ways to use and build Zip helpers. I will just demonstrate an example for using ZipArchive.
Pastebin: http://pastebin.com/J2M0jjQG
Inline...
How to find your php.ini file
Finding your php.ini is pretty straight forward task:
- open terminal or cmd
- execute php --ini if php is undefined you should add it to your PATH or just execute "/your/path/to/php --ini"
- php.ini has several modes (path is different sometimes...):
- using one file:
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini - using several different files (will help to maintain common settings between cli php.ini and httpd php.ini
Scan for additional .ini files in: /etc/php5/conf.d
Additional .ini files parsed: /etc/php5/conf.d/ctype.ini,
/etc/php5/conf.d/curl.ini,
/etc/php5/conf.d/dom.ini,
/etc/php5/conf.d/gd.ini,
/etc/php5/conf.d/hash.ini,
............more .ini files here............files content could be "extension=gd.so" (unix) or "extension=gd.dll" (windows)
- there are two more options to get your ini files:
- execute in cli mode: "php --i | grep .ini"
- write your own script and check via browser:
<?php phpinfo(); ?>
That's it, now you can just edit your php.ini with anything you think you will need for future PHP programming.
More about php.ini may be found at http://php.net/manual/en/ini.php
Setup\Configure Zend Debugger
Using a debugger is very important while writing code, so lets see how to do it with PHP and Zend Debugger:
- Install Eclipse or Zend Studio
- If you have installed Eclipse, you should install two more things:
- PDT (PHP Development Tools)
- Zend Debugger
- After extracting everything, search for ZendDebugger.so path
- Edit your php.ini or create another ini --> zend.ini which will have to be loaded by your PHP and add:
; Loading Zend Debugger Extension zend_extension=/your/path/to/ZendDebugger.so ; ; use 127.0.0.1 for local host, or you another local network IP zend_debugger.allow_hosts=127.0.0.1 ; ; Expose Zend Debugger ; ; never - do not expose (default) ; always - expose to whoever want to know ; allowed_hosts - expose only if request comes from an IP listed above ; zend_debugger.expost_remotely=always
- Save & Restart Apache
- Verify your phpinfo()
- Download FireFox or Chrome Extension (Chrome extension is not official extension by Zend)
- Configure Eclipse \ Zend Studio settings:
- Configure your extension settings:
- Start debugging!:)
Note for Zend Studio 8.x users:
I suggest that you will update your Zend Studio application by using the following instructions:
http://forums.zend.com/viewtopic.php?f=59&t=10468
Enjoy!
PHP: Insert\Update MySQL BIT(1) field
Today I`v noticed to interested things:
- A nice sentence or a motto that I really liked:
"When you do a search, and it comes back with no results, it’s a sign that you need to write something." (Taken from Here
- Didn't find any straight answer on Google for my question: "How to insert\update a bit field with PHP":
So with MySQL you would use:
INSERT INTO t SET b = b'1'; // Or b'0'
And with PHP you would use boolean type:
//$db instanceof ActiveRecord, that's only for the following example
//you can use other ways to insert\update your MySQL DB.
$db->insert(array('b'=>true,'c'=>false)); //true = b'1' , false = b'0'
$db->update(array('b'=>true,'c'=>false)); //true = b'1' , false = b'0'
Hope I helped,
Shak.
Zend Framework – How to redirect/get application base URL
What is exactly base URL ?
Base URL is sub.domain.end, for example:
if your full URI is <em><strong>http://www.yoursite.com/some/params/id/1</strong></em>, so base URL will be <em><strong>www.yoursite.com</strong></em>
Redirect to application base URL
Sometimes you would want to be able to redirect from one page to your main homepage, for example:
- User A enter Site B.com login page
- User B enter username and password and he had been successfully logged in
- User B is being redirect to Site B.com
As I like to say, if you are reading this post, you would probably need some help about its subject:
There are two ways:
public function loginAction(){
.
.
if (user is logged in successfully) {
$this->_helper->redirector->gotoUrl(); //Option 1
// OR setGotoUrl() uses gotoUrl() when no param is being passed
$this->_helper->redirector->setGotoUrl(); //Option 2
}
.
.
}
How do I get base URL string?
public function loginAction(){
$baseURL = $this->getRequest()->getHttpHost();
/*
When using redirect helper and full URL
you will have to attach http(s)://
which means you will have to use isSSL() method
*/
}
Note:
My suggestion is to create BaseControoler that will handle your current HTTP request & base URL:
class BaseController extends Zend_Controller_Action{
/**
* @var Zend_Controller_Request_Http $_request
*/
protected $_request;
protected function init(){
//Save request
$this->_request = $this->getRequest();
//Save httpHost (base URL)
$this->_httpHost = $this->_request->getHttpHost();
$this->siteInit();
}
protected siteInit(){
/*
You don't really need it
I just prefer to know that if someone creates
another controller he won't have to call parent::init()
*/
}
}
After creating BaseController you have to setup your own controller(s):
//Extend BaseController
class IndexController extends BaseController {
public function indexAction(){
var_dump($this->_httpHost,$this->_request->getParams());
}
}
That it for today,
Shak



