Beauty’s where you find it
22 Sep
Ok, so I’m in the mood to write a little bit. I finished my grad school homework a little early, so I’d like to talk about CakePHP. Specifically, updating your user model session data when the user model is edited. Here is the scenario:
Array
(
[Auth] => Array
(
[Model] => Array
(
[id] => 1
[first_name] => Jason
[last_name] => Leveille
)
)
)
If you’re anything like I am, you make use of this data to display information to your authenticated user. For example, in your controller you might set a firstName variable for use in a welcome message.
$firstName = $this->Auth->user('first_name');
$this->set(compact('firstName'));
It’s very likely that you have provided an edit action in your auth userModel controller. It’s also likely that you have provided the user with the ability to modify their first name. In our welcome message, we are pulling our first name data from a session. If we want this data to be accurate, than the change to our user first name in the action will also need will not be reflected in this auth session. The solution of course is to merge $this->data[’$this-Auth->userModel] with our Auth.Model session.
//update the auth userModel data
$authUpdated = Set::merge(
$this->Session->read(
sprintf('Auth.%s', $this->Auth->userModel)
),
$this->data[$this->Auth->userModel]
);
$this->Session->write(
sprintf('Auth.%s', $this->Auth->userModel),
$authUpdated
);
Again, this code would be part of your user model edit action, and would be included after a successful save operation.
26 May
Quite often I find myself overwhelmed by the amount of news I try to consume on a daily basis. Often the result, unfortunately, is that my brain shuts down to some extent and I find it hard to prioritize the things I really want to investigate. For example, ever since the January 2008 edition of PHP | Architect, in which there was an article about The Doctrine Framework, I have been trying to find the time to dig in. On the way into work today I made the decision that, on a weekly basis, I would begin investigating things that interest me. This week of course is devoted to Doctrine.
What is Doctrine? According to the website:
Doctrine is a PHP ORM (object relational mapper) for PHP 5.2.3+ that sits on top of a powerful PHP DBAL (database abstraction layer). One of its key features is the ability to optionally write database queries in an OO (object oriented) SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains a maximum of flexibility without requiring needless code duplication.
Ok, sounds good to me. Let’s get started. (more…)
14 May
I have used http_build_query numerous times in the past and I’ve never had to pay attention to the third parameter before: arg_separator. I am making use of a great Curl wrapper to abstract some of the more mundane setup tasks associated with a Curl request. Initially I had constructed the setup of CURLOPT_POSTFIELDS as follows:
$url = 'http://rest-toolkit/api/users/5';
$response = $curl->post($url,
$vars = array(
'username' => 'baz',
'password' => 'bar'
)
);
...
curl_setopt($handle,
CURLOPT_POSTFIELDS,
http_build_query($vars)
);
Upon receiving the request, my script was showing $_POST variables as follows:
Array
(
[username] => baz
[amp;password] => bar
)
Thanks to a comment on the http_build_query page regarding the use of the third parameter, I quickly realized that my php.ini setting for arg_separator.output was in fact set to &. The quick fix:
curl_setopt($handle,
CURLOPT_POSTFIELDS,
http_build_query($vars, '', '&')
);
And the result:
Array
(
[username] => baz
[password] => bar
)
5 May
This morning I got into work early (6:30am, which is early for me) and decided to add the ability to define special methods to Rest Toolkit (original blog entry). “Special” in this case means adding the ability to call specific methods which allow special processing for a resource. (more…)
28 Apr
Yes, I know, displaying the time with JavaScript. Something that’s been written about since the dawn of time. Following is a trivial bit of code, but one that I thought others might find useful. We are working with a client whose application broadcasts meetings (and screen captures from those meetings) to client computers. A very cool project that I’d like to write about some day. With regard to time, there are 2 requirements:
22 Apr
I’ve had my focus in a lot of other areas for a few weeks, and in that time is seems like quite a bit has happened on the CakePHP front. It seems that there has been a subtle shift in how the framework will evolve from here forward. gwoo puts it much better than I can in his recent bakery article, “After 3 years, looking back and moving ahead“. In the grand scheme of things there are much more interesting things between the lines of what gwoo has written, however the thing that got me most excited was located at the very end:
Stay tuned for more new developments and expect the next 1.2 release in the coming weeks.
21 Apr
Last week Dave and I were trying to figure out the best way to synchronize member data from an asp application with a WordPress installation. I don’t remember how it came up in conversation, but in a flurry of chatter we decided that we should build a RESTful API to allow the applications in question to communicate. In the interest of re-usability we also decided that we should build a generic toolkit. One that could easily be used to expose an API for any supported database, through PHP. So, using this toolkit you should quite easily get your Lasso application talking with your PunBB software, if that’s what you need.
So was born rest-toolkit. We have released an alpha version of the project, so download it and give it a try. I hope you don’t mind a lack of formal documentation. Depending on how things go documentation will follow. (more…)
18 Apr
Recently I worked on a project where all member data was being managed through a third party member management service, provided by a company named Avectra. The product does more than manage member data from the looks of things, but all I cared about was interaction with the member management API.
I had to authenticate against an external data source, as well as query the data source for member information when needed. Avectra does have a web service API which it has named xWeb. Here is a quote from their Wiki:
xWeb is netFORUM’s XML web services application. netFORUM is an enterprise level Association Management System (AMS) developed by Avectra that allows associations to manage their customers and related activities. netFORUM is used by association staff, members, and the public at large.
10 Apr
I recently implemented DFS and Iterative Deepening algorithms to search for a target node in a tree. Initially I thought I would write my program in C++, however after some thought I decided to go the route of JavaScript. I believe the source code is commented sufficiently to give you a glimpse into some of the decisions I made, therefore I won’t be providing any real detail in this post.
DFS and Iterative Deepening Project
I have to give much thanks to Kirupa, as his ActionScript implementation of DFS and BFS gave me the inspiration to go the route of JavaScript. Not only that, but I was able to use much of his work as a model for the direction I took. I hope you find that I did provide sufficient credit in my comments. Enjoy.
NOTE: I stayed up until 1am, two nights in a row to finish this. I don’t work well late at night and that is likely reflected in some of the algorithmic decisions I made. If you have any questions please don’t hesitate to ask. Also, you might be asking, WTH did he use extjs here? Honestly, I don’t know. I originally had grand visions for my node tree, etc, however those didn’t pan out. In it’s current state there is no advantage to using that framework.
Recent Comments