Monday, March 21, 2011

Reminder: Zend Framework Route Regex

If you want to make the route / optional
'archive(?:/(\d+))?' 

A note about the above regular expression. It uses one of the "expression syntax" which uses ?:
This means that every digit inside (?:) will NOT be group and outputted separately.

Consider this:

$t = 'archive/1234';
preg_match('#archive(?:/(\d+))?#', $t, $matches);
//outputs
array(
[0] => archive/1234
    [1] => 1234
)


Whereas without ?:

$t = 'archive/1234';
preg_match('#archive(/(\d+))?#', $t, $matches);
//outputs
Array
(
    [0] => archive/1234
    [1] => /1234
    [2] => 1234
) 
 
notice that if you include ?: that the "/1234" did not get outputted.

Wednesday, March 16, 2011

Tip: change MySql's next Autoindex

If some row got deleted and you want to change your next autoindex:

ALTER TABLE `table_name` AUTO_INCREMENT = 1

Also usefull, if you want to find the current table's AUTOINDEX:

SHOW TABLE STATUS LIKE 'table_name'

Monday, March 14, 2011

Notes: Two usefull templating functionality in Zend Framework

If you do templates and use the Zend Framework there are 2 useful functionality that you can utilize (maybe there is more but I only looked at these two):

Zend_Filter_PregReplace
http://framework.zend.com/manual/en/zend.filter.set.html#zend.filter.set.pregreplace.options

and

Zend_Markup
http://framework.zend.com/manual/en/zend.markup.parsers.html

I am not going to explain anything about these two classes since it pretty well documented in ZF Docs but if you are a big template user who likes to mess with placeholders, the above functions would work great.

Sunday, March 13, 2011

Tip: Retrieve your server url with Zend_View_Helper_ServerUrl

This helper is badly documented in the Zend Framework site.

Works as:
//controller
print $this->view->serverUrl();
// prints http://yoururl.com

Wednesday, March 9, 2011

Tip: Get an Action Helper within an MVC

$url = Zend_Controller_Action_HelperBroker::getStaticHelper('url');

Monday, March 7, 2011

Tip: Get MVC instance throughout the site

A very useful functionality of the Zend Framework:
Zend_Layout:getMvcInstance()

If you want to retrieve the View instance from an Action plugin you can do something like:

    public function dispatchLoopShutdown()
    {
        $layout = Zend_Layout::getMvcInstance();
        $view = $layout->getView();
        // now you can mess with the view object!!
        $view->getHelper('redirector');
    }

Friday, March 4, 2011

Tip: search word in a file then print result

This will search for a whole word (-w) in a file, print the filename (-H) and print the line number (-n)
find . -exec grep -nwH 'searchString' {} \;

Notes: Eclipse method/function searching

Another thing I like about eclipse.

If you want to search for example a method/function name in PHP and want to look for its declaration and any occurrences of this method do this:

If its your first time running the search, setup the Working Set first by doing step 1:
Step 1.
option 1)
CTRL + H -> Scope section -> Click Choose -> Click New -> Select PHP -> Type a working set name -> choose your desired working set to search.

The step above will store your working set to search for for future searches.

option 2)
IF you dont want to bother with storing working sets. Right Click on your working set on your left panel -> Select Search


Step 2:
CTRL + H -> PHP Search (Tab) -> Search For: (Method name) option -> Limit to: (All occurences) option -> Then click Search button

A thing to note. If you are searching for a class name you need to change the "Search For" option to "Type" or your search will not work!

Thursday, March 3, 2011

NOTES: allowEmpty

There is an "allowEmpty" parameter in the Zend framework form elements where if set to false (allowEmpty = false), it means that it will always validate the element and if the "required" parameter is also set to false.

Wednesday, March 2, 2011

Tip: Linux terminal freeze when pressing Ctrl + S

Sometimes I accidentally press CTRL + S in a linux editor such as VI. This causes the terminal to freeze or lock.
To unfreeze you need to press CTRL + Q