| Latest |Kites |Pictures |Programming |Life |
![]() [filed under Programming]C# silverlight and all that shit ![]() [filed under life]Blair ![]() [filed under Programming]PHP code style ![]() ![]() [filed under Programming]NuSphere PHPeD firefox debug toolbar ![]() Tags: NuSphere PHPeD firefox debug toolbar There is an open source Firefox toolbar for NuSphere PHP IDE (NuSphere PHPeD firefox toolbar). It was written by a kind chap called Ian Flory. Firefox 3.5 beta 99 Preview is out and I use it, but the toolbar is locked to Firefox versions 3.0.* and lower. The toolbar needed an update, so a little hacking later and here is the new version: DBGbar: phpdebugger.xpi Fixed: Changed the min version to 3.5.* Comments: This Firefox add-on build script was useful. If you find this useful leave a comment :) Open source (LGPL), flash charts (pie, bar, line, scatter, etc): open flash chart 2. Tooltips, animation and JSON friendly.
![]() [filed under Programming]zend framework jeditable ![]() Tags: zend framework jquery.jeditable.js JSON jeditable does not accept JSON in response to the AJAX call. So how can you get this to work with Zend Framework? Like this: Your view will need the the .js files: <?php In your controller you'll need to add a context swtich to return JSON, not HTML: public function init() You action will look like this: function myEditableAjaxAction()
The URL you need to paste into the editable config will need the JSON context switch in it: $(".edit_area").editable("<?= $this->url(array('action'=>'my-editable-ajax', 'format'=>'json')) ?>", { Hope that helps.
![]() [filed under Programming]zend framework sql error reporting adapter ![]() This post is about Zend Framework, sql error reporting. Problem: Lets fix it so it shows the whole query. I found this neat class that reports the SQL, it work by extending the Zend_Db_Adapter_Pdo_Mysql class. I use MySQLi, so I adapted it so it works for me: class MyCompany_Db_Mysqli extends Zend_Db_Adapter_Mysqli
{ public function query($sql, $bind = array()) { try { return parent::query($sql, $bind); } catch (Exception $e) { if( $this->getProfiler()->getEnabled() ) { echo '<span style="color: red; font-size: 20px;">MyCompany_Db_Mysqli adapter Error</span>';
echo '<div style="font-family: monospace; padding: 10px; margin: 10px; border: 2px solid pink;">'; echo nl2br($sql); echo '<hr>'; echo '<pre>'; echo var_dump($bind); echo '<pre>'; echo '</div>'; } else { // no profiler throw $e; } } } } The whole thing is a little bit quick and dirty. I wanted to see if it worked and post a blog entry about if it did. You need to save the file into your library code (replace MyCompany with your library directory name) in the Db directory. To use it you want to find where you load your database adapter, I do this in my controller init() function. My init() looks like this: class ProjectsController extends Zend_Controller_Action
{ // // this is called from __construct // public function init() { parent::init(); $config = new Zend_Config_Ini('/var/www/ZF-apps/config.ini', 'general'); //$db = Zend_Db::factory($config->projects->db); $db = new Guava_1_Db_Mysqli($config->projects->db->params); $db->getProfiler()->setEnabled(true); Zend_Db_Table::setDefaultAdapter($db); ... ... Note how I have commented out how I used to get my adapter. Also see how the params are loaded from an .ini file and used slightly differently. How to use it: You'll want to add your own logic into the adapter so it emails off the error report (or pasts it into an RSS feed or something)
![]() [filed under Programming]XUL Firefox add on sidebar open close events ![]() Tags: Firefox 3.x add-on sidebar. What this post is about I am coding a FIrefox add-on. It is fun. I am making a sidebar that you can drag and drop stuff onto. I need to know when the user has opened it or closed it (so I can persist the data) so after a lot of googling I figured it out. The code This is how you can watch the open and close events of a sidebar. In your sidebar javascript file put this in: var skratch = { Hope that helps someone. Use this with 'save to file' to persist data in your add-on - happy days. Happy fuckin days, man. Here is some save to file goodness (note: the code is GPL): ![]() [filed under Programming]MySQL compare sub query null ![]() Hey, this is cool. I had a query like so: SELECT stuff And the sub query was returning NULL sometimes. So I wanted the rows from table where col is null. But the syntax to do that would be: SELECT stuff Now this query isn't going to work when the sub query returns a number. The answer is to use this funky operator thatsolves this problem SELECT stuff Smooth :-) ![]() [filed under Programming]Zend Framework MySQL DB Pagination Tutorial ![]() Tags: Zend Framework 1.7 Pagination MySQL SQL Pages Paged Page Next Prev Previous Just a quick how-to-make a MySQL table paginatior in Zend Framework.You'll need these as a reference, zend.paginator.usage and zend.db.select. First in your controller make a link to MySQL and make an SQL select() object (I find this disgusting syntax, but hey ho)... So, in the following code I am in my controllers action method: public function myTableAction() $db = Zend_Db::factory( $this->config->db ); So you have passed the MySQL syntax object to the paginator. This will add the LIMIT to the SQL and run it. The LIMIT syntax is built up from the page you are on and how many items per page you are displaying, this information is grabbed from the URL. Next you need to make your view show this data and the:<prev 1 2 3 4 5 next >HTML. The paginatior object we passed to the view in the above code (the second to last line) is an iterator, so we can just loop over it: <table class="my_table">
<thead> <tr class="table_head"> <th>People</th> </tr> </thead> <tfoot> <tr class="table_foot"> <td colspan="4"><?= $this->paginationControl($this->paginator, 'Sliding', 'partials/search-pagination.phtml'); ?></td> </tr> </tfoot> <tbody> <?= $this->partialLoop('partial-loops/people.phtml', $this->paginator) ?> </tbody> </table> OK, so the bit that builds the table is the partialLoop, we pass our pagination object that contains our table rows to the partialLoop iterator. This builds each <tr> row from the paginatior, the paginatior got the data from the MySQL table (after it manipulated your SQL adding a LIMIT 10,10) and got the item count from your table (it altered your query adding a COUNT() and re-queried the DB) The loop partial looks like this (partial-loops/people.phtml): <tr> Note how we have access to the two columns from MySQL as object properties. BTW I keep my view .phtml files in views/scripts and my partials in views/scripts/partials and my loop partials in views/scripts/loop-partials. You don't have to follow what I do, just make sure your paths make sense. The style of the:<prev 1 2 3 4 5 next >HTML is in the partials/search-pagination.phtml view, this you can copy from this page (zend.paginator.usage -- Example Paginations Controls (at the end of the page)) and save it in the correct script view directory. Mine is a modified version (partials/search-pagination.phtml): <?php if ($this->pageCount): ?> </div> That's it really. You'll need a bit of CSS to style the links. For more info take a look at the Zend Framework wiki: Zend_Paginator Job done.
![]() [filed under Programming]Zend Framework Menus Navigation ![]() Tags: Zend Framework, menus, controller, action, navigation, template, menu.phtml, This is how to put menu logic in your web page. OK, from the get go, this is hard. You may need to read it a couple of times or do more research. What we want is a web page with a menu system (a list of items) on the left of the page. The menu will be different for each controller and action. What usually happens in ZF is the ApplicationController class is created and the method indexAction is called. indexAction then uses the model to get data and passes info to the view (for example using $this->view->data = 99; ). The view is then rendered as a string, which is appended to the Layout content. It took me a while to figure that out. To make the menu we need a seperate controller, the MenuController will decide what to show on the menu. The the menu view will render it and we capture the output of the view into a layout variable. The menu HTML is used later in the layout.phtml template. In our application controller we push the "menu" onto the actionStack which makes ZF run MenuController::applicationAction next.
MenuController.php The MenuController changes the layout response segment to 'menu', all the HTML in the menu view is saved to this variable. This HTML to make the menu is then merged into the web page in layout.phtml. More notes on Zend Framework Menu Navigation. |
| Server Grind [0.2474 seconds] |