Latest Entries »

If there’s somewhere a mystery bug contest I’m probably winning the race. Here’s a new one : try to get a view helper to work with javascript. Anyone has a solution ? Here’s my unworking code :

  1. class Zend_View_Helper_Loginbox extends Zend_View_Helper_Partial
  2. {
  3. public function loginbox()
  4. {
  5. $this->view->headScript()->appendFile(‘/scripts/js/myfile.js’);
  6. // this doesn’t work, the file never gets included
  7. $this->view->dojo()->javascriptCaptureStart();
  8. // neigher the content of my javascript function after this
  9. ?>
  10. dojo.addOnLoad(function(){
  11. alert(“it s working”);
  12. });
  13. view->dojo()->javascriptCaptureEnd(); ?>
  14. <div id=”box” class=”box”>test</div>
  15. <div id=”blockme” class=”blockme”>
  16. <form method=”post” action=”/user/login” id=”loginform”>
  17. <label for=”email”>Email:</label>
  18. <input type=”text” name=”email”>
  19. <label for=”password”></label>
  20. <input type=”password” name=”password”>
  21. <input type=”submit” id=”loginButton” value=”login”>
  22. <div id=”loginerrors”></div>
  23. </form>
  24. </div>

Javascript never get to be on the client server. Any idea why ?

Advertisements

I’m so bored about this kind of errors :

  1. www# svn commit
  2. svn: Commit failed (details follow):
  3. svn: Directory ‘/var/trunk/trunk/’ is missing
  4. svn: Directory ‘/var/trunk/trunk/’is missing
  5. www#

Damn i wish there was a simple solution out of this, than to re-chechout each time your svn rep and re-delete your directory ! Hell with svn I say !

It’s very unclear, both in the Zend documentation and the Dojo one, how it is possible to order a JsonRest server (the Zend one while we’re at it!) to reply to JsonRest client (dojo…). I’ve tryied to make this happen for 2 days now… Here’s the client side :

  1. <b style=”color:black;background-color:#ffff66″>dojo</b>.addOnLoad(function(){
  2. store = new dojox.data.JsonRestStore({target:”/test/m”});
  3. var newItem = store.newItem(
  4. {
  5. post_id: 123
  6. });
  7. store.save();
  8. (…)

Then, on the server side : x First modify the router :

  1. $route = new Zend_Controller_Router_Route(‘test/m/:id/*’, array(‘controller’=>’test’, ‘action’=>’m’));
  2. $front->getRouter()->addRoute(‘test’, $route);

x Then add a a function in a custom class :

  1. /*
  2. * returns hello world
  3. * @return string
  4. *
  5. */
  6. public static function addmyitem($item){
  7. // custom code
  8. return “Item added”;
  9. }

=> But, how am I supposed to map this function to the action controller in order to reply to the Rest POST request dojo is executing ??? That’s not getting me anywhere…

  1. // Disable auto-rendering and layouts
  2. $this->_helper->viewRenderer->setNoRender(true);
  3. $this->_helper->layout->disableLayout(true);
  4. $id = $this->getRequest()->getParam(‘id’);
  5. $server = new Zend_Json_Server();
  6. $server->setClass(‘RpcTest’);
  7. if(‘GET’ == $_SERVER[‘REQUEST_METHOD’]){
  8. $server->setTarget(‘/test/m’)
  9. ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
  10. $smd->setDojoCompatible(true);
  11. header(‘Content-Type: application/<b style=”color:black;background-color:#99ff99″>json</b>’);
  12. echo $smd;
  13. return;
  14. }
  15. $server->handle();

Finally I’m questionning the use of the Zend Json server : would’nt it be simpler to get rid of the server and directly reply using :

  1. if(‘GET’ == $_SERVER[‘REQUEST_METHOD’]){
  2. $data = get_item_data_by_id($this->getRequest()->getParam(‘id’));
  3. sendToJson($data);
  4. }

Now : how are we supposed to make this work ?

I was wondering how to read the entire content of a datastore. I often query here or there one item, but it’s the first time I wanted to read the entire stuff.

My idea was to send the entire content back to the server. So how do you do that ?

store.fetch({
onComplete: function(items, request){

console.log(items);
}

});

The most simple way possible I’d say 😉

I’m sure there’s a better way to do this but here’s my simple solution that works to enhance a web form ; the problem I wanted to solve was that I wanted my users to see messages when onmouseovering different fields of a form (to get detailed explanations).

Here are 2 simple functions that does the job :

/*
* These 2 function show/hide hints on the form
*/
function ShowP(id){
dojo.query(‘#’+id).style(‘display’,’block’);
}
function HideP(id){
dojo.query(‘#’+id).style(‘display’,’none’);
}

And this can be used to call the functions :

<div onmouseover=”ShowP(‘P2’);” onmouseout=”HideP(‘P2’);”>

Simple but not beatifull. Well at least it works !

Hey, I tend to forget that all the time but a good method to add a dojo widget programmatically is…

new dijit.form.Button({}).placeAt(dojo.body());

I don’t know about you but I alwayse forget about this thing, so I thought I’d put this on my blog !

Running talk on freebsd

I came up with a problem using talk under freebsd I thought this might be usefull to newcommers. The solution is simple but few docs is laying arround so one might need a little digging. In order to run talk on freebsd you need to uncomment this line on inetd.conf : “ntalk dgram udp wait tty:tty /usr/libexec/ntalkd ntalkd” Once this is done you’ll be able to run it easely…

One fun thing with Zend framework is to build your own authentication provider. It’s needed for exemple if you do not plan to use a database or if you want to use a highly secure authentication provider like a smartcard, or a one time pad. In that scenario you might want to use authentication via a webservice to make sure your servers a in different compartiments. Here’s the base of a simple authentication provider :

  1. class MyAuthenticationAdapter implements Zend_Auth_Adapter_Interface
  2. {
  3. private $email ;
  4. private $password;
  5. public function __construct($email,$password)
  6. {
  7. $this->email = $email;
  8. $this->password = $password;
  9. }
  10. public function authenticate()
  11. {
  12. $Users = new Users();
  13. if($Users->Authenticate($this->email, $this->password))
  14. $authResult[‘code’] = Zend_Auth_Result::SUCCESS;
  15. else
  16. $authResult[‘code’] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
  17. return new Zend_Auth_Result($authResult[‘code’],$this->email);
  18. }
  19. }

Not so hard after all !

Hey, I’m trying to have a little fun with SimpleDB. In order to play with data (delete, mostly) I needed to write a simple function to get my informations. Now be warned, it’s very poor code, but it’ll allow you to see and delete your data easely. Anyone willing to write phpSimpleDBAdmin ? Here it is :

  1. $this->_helper->viewRenderer->setNoRender(true);
  2. $this->_helper->layout->disableLayout(true);
  3. echo “<h2> Current domains </h2>”;
  4. // Build a link to show all domains
  5. $Admin = new Admin();
  6. $domains = $Admin->ListDomains();
  7. foreach ($domains as $key=>$value)
  8. {
  9. echo “<a href=”showdomain?d=$value”> $value</a> “;
  10. }
  11. if(isset($_GET[‘d’]))
  12. {
  13. echo “<h2> “.$_GET[‘d’].” data</h2>”;
  14. echo “#ADD a pre HERE”;
  15. $data = $Admin->getDomainData($_GET[‘d’]);
  16. print_r($data);
  17. foreach ($data as $k=>$v)
  18. {
  19. foreach ($v as $items=>$array)
  20. {
  21. echo “<br>Item id : $items actions : <a href=”\”/admin/deleteitem?d=”.$_GET[‘d’].”&i=$items\””>delete</a>”;
  22. }
  23. }
  24. }

Now, this function uses 2 other functions :

  1. public function ListDomains()
  2. {
  3. $request = new Amazon_SimpleDB_Model_ListDomainsRequest();
  4. $response = $this->service->listDomains($request);
  5. if ($response->isSetListDomainsResult()) {
  6. $listDomainsResult = $response->getListDomainsResult();
  7. $domainNameList  =  $listDomainsResult->getDomainName();
  8. foreach ($domainNameList as $domainName) {
  9. $data[] = $domainName;
  10. }
  11. }
  12. return $data;
  13. }
  14. public function getDomainData($d)
  15. {
  16. $request = new Amazon_SimpleDB_Model_QueryWithAttributesRequest();
  17. $request->setDomainName($d);
  18. $response = $this->service->queryWithAttributes($request);
  19. $data = array();
  20. if ($response->isSetQueryWithAttributesResult()) {
  21. $queryWithAttributesResult = $response->getQueryWithAttributesResult();
  22. $itemList = $queryWithAttributesResult->getItem();
  23. foreach ($itemList as $item) {
  24. $attributeList = $item->getAttribute();
  25. foreach ($attributeList as $attribute) {
  26. $attribs[$attribute->getName()] = $attribute->getValue();
  27. }
  28. $data[] = array($item->getName() => $attribs);
  29. $attribs = “”;
  30. }
  31. return $data;
  32. }
  33. }

Note : replace #Add a pre here# by the pre tag in html.

I installed an apache on a FreeBSD 7 today and had this problem “Failed to enable the ‘httpready’ Accept Filter”. The solution is straigh ahead : “kldload accf_http”. Don’t forget to load the module in /boot/loader.conf: accf_http_load=”YES” That’s it !