Categories
PHP

Using mail() in PHP on Windows

Are you a PHP developer? Do you develop your solutions on Windows? Have you always looked for a solution to get mail() function working on Windows? Today while browsing the internet, I noticed a cool tool that listens to the standard SMTP port (25) and stores the email messages instead of sending them online. Isn’t it cool?

Just grab the MSI package from it’s CodePlex repo: http://smtp4dev.codeplex.com/. Install it. They provide a nifty UI for configuration option. Play with it.

When “smtp4dev” is up and running, check your PHP settings. If you’re using WAMP Server or any other pre-configured packages, it’s most likely that you already have port 25 configured for outbound emails (and for the mail function of course).

If everything is okay, go ahead and execute the mail() function in PHP. smtp4dev should popup a notification on email acceptance.

The tool is small in size, lightweight and actually it’s loads better than filling up my gmail inbox 🙂

Categories
PHP

Zend Framework: Template Inheritance, Layout Place Holders or Whatever You Call It

In Django and many other frameworks or templating systems, we see template inheritance. Where you can put the static parts of the template in a single template and then extend that template to work out the dynamic parts. At my first look at the Zend Framework, it has “views” and “layout”. The “layout” is the master view. If you enable it, the corresponding views will be mashed up with the “layout” before the output is sent out to the browser.

In the zend layout, there is a part:

Whatever is in the view file, it will be inserted at the position of this code in the layout file. Then the question rises, how do we modify other parts of the layout? Can we define some dynamic blocks in the layout?

The answer is YES. We can. It took me a while to find out. But it’s very simple.

# Any variable you define in the view file is available in the layout.
# You can use Placeholders for capturing large block of HTML contents or small texts.

While the first one is obviously simple, we shall have a look at the second one.

In your layout file, you can define a block or placeholder by using this piece of code:

Later, from the view files, we can define the content of the place holder:

The capturing technique is specially good for capturing large block of content. While you can also set small text:

For a thorough overview, I would suggest you to have a look at the (messy) docs from the Zend Framework Manual: http://framework.zend.com/manual/en/zend.view.helpers.html 😉

Categories
PHP

Zend Framework : Session Handling, URL Routing, URL Helper and Redirecting

Some basics of Zend Framework, I am documenting in case I forget these in the future 😉

Session Handling

URL Routing
Add in Bootstrap:

URL Helper

URL Helper is available via the method – url() in a view object. The method takes an array of options as its first parameter. The second parameter is optional where you can pass a route object name (eg. ‘category’ from the above url routing example). This comes in handy when you want to construct routed URLs.

By default the helper takes the following options: “action”, “controller” and “module”. If anyone of them is not provided, default one is used. It can also take in GET params which will be appended to the URL in a SEO friendly manner. If you pass a route object, you can simply pass the dynamic parts, no need to pass the entire action, controller or anything.

Note that: In the second case, “id” itself is passed to the URL. But in the first case, the URL routing rule has been honored.

Inside a view script, you can directly use:

Since it is a member of the View object, you can also access it from an action like this:

Handling Redirection
Zend has a Redirector helper which provides advanced features when it comes to redirections. But for most cases, the built in _redirect() method of an action will do the job if used wisely with the URL helper.

That’s it! Zend Framework is verbose and usually has more than one way to achieve something. It’s up to you to decide what suits your needs!