Laravel, another php framework to explore

Laravel is a framework in the same class as Codeigniter. However, at first glance it implements a couple of annoying missing features I’ve waited a longtime for CI to add but have yet to do it: full unit-testing and ORM. For ORM, there have been many third party addons/sparks that would add the functionality but not from base install. Unit testing is a much bigger problem in CI. There is no good way to integrate php-unit or simpletest to test your code. So we are left trying to unit test with the joke implementation of unit testing library from CI.

I’m hoping Laravel will prove to be as amazing as what people have been raving about in the blogsphere. Can’t wait to give it a shot.

Codeigniter header already sent error using json header

Getting this error when moving from development server to staging server and getting this error.

Severity: Warning –> Cannot modify header information – headers already sent

The error shows up if you are doing all of the following.

1. Change header using

$this->output->set_content_type(‘application/json’);

2. Outputting using echo (which is not recommended by Codeigniter).

3. In php.ini, have output_buffering set very small, like 0.

Solution

There are two solutions to this issue.

1. Increase the output_buffering enough so to buffer your echo. (this is a hack)

2. Recommended solution is to replace echo with CIs built in $this->output->set_output(‘content’) method.

Android making https requests with SSL from GoDaddy – No peer certificate error

Another hair pulling session that all ended well.

Task:

Make a secure call to a server using a httprequest and get the httpresponse for further processing.

Android http request and response:

HttpClient client = new DefaultHttpClient();
HttpGet req = new HttpGet("https://www.example.com");
HttpResponse res = client.execute(req);

Error:

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

Problem:

The issue is that cert from GoDaddy was installed but not installed completely. An Intermediate cert is required for the server/domain in order to have a fully installed cert.

Reference:

http://community.godaddy.com/help/5238

Codeigniter running into some major growth issues

I have been using Codeigniter for a while on many projects and it had been very useful as it is non-intrusive. Its very small footprint also allows for the extremely good performance on page loads. However, these projects were simply using just the CI core and not implementing any plugins. Some base classes have been extended, but purely specifically for the individual project so not causing any conflict with other code.

Recently, I started building a startup project using CI and would like to employ more plugins do speed up development. Pleasantly surprised, I found that CI had implemented Sparks for searching and installing plugins to CI. Great right! So I implemented an ORM called DataMapper and it was brilliant.

Here comes the reality check. After upgrading from CI 2.0.2 to 2.0.3, everything broke. Why? Because CI changed a lot of methods within its core classes from public to protected. That of course is not actually a bad thing as it was in fact incorrectly implemented before allowing a developer to mess with core functionality too much. However, through researching into these issues, I came to a huge realization that I missed about CI before. CI only allows plugins and developers to modify core classes by extending them into MY_core_class.php. If multiple plugins need to extended the same class, even if they need to overload different methods, it requires some code merging by the developer. If the plugins need to overload the same method in the same core class, that becomes a huge undertaking for the developer to understand what each plugin is trying to do and write merged code that works for both in the same overloaded method.

After that realization, I have determined that CI is fine for applications that are going to use mainly the core classes. If you intend to implement plugins, be very careful understanding what core classes each one will extend. Choose wisely. If those requirements cannot be met, look for another framework.

Code debt accumulating interest

I get into this trap a little too often. I know there is some code that is not written correctly but for the sake of moving along, I ignore it temporarily with the intention of going back to refactor later on. Of course it is not something that is broken, but just poor convention and naming type of stuff. As I build more on top of that, whatever mess that was there before begins to infiltrate into new code through the use of those classes. If I extend upon them, it opens even a greater can of worms.

A friend had talked about code debt before and it speaks so true to these situations. Code debt will incur interest over time if not paid up. The longer you wait, the more expensive the payoff becomes. So just how I like to be financially debt-free, I should strive for code debt-free also.

Running stored procedures on MSSQL via any language on Linux

If you need to run store procedures on Microsoft SQL Server on perl, php, ruby, etc., you need to configure /etc/freetds/freetds.conf with the server connection information. Specifically, specify the tds version to be 8.0. Something like the following.

/etc/freetds/freetds.conf

[Server80]
host = domain.com
port = 1433
tds version = 8.0

Connection to the server via php would look like this.

$link = mssql_connect("Server80", "user", "pass");

Google maps info window size problem with images

One strange thing when using Google Maps API with pictures in the info window is that sometimes the window is not tall enough to enclose all the content. It overflows the white info window background. The problems is because Google maps API tries to calculate the height of all the content while the photos are being pulled by other http requests. They are asynchronous and the photos might take longer to load than it takes for Google Maps API to determine what the height of the info window should be. It has been said that setting the height of the element would give Gmaps a hint as to how tall the photos might be and adjust accordingly. So doing something like the following would help.

<img src=”pic.jpg” height=”80″ />

Also, if you are using any sort of table or div containers for the image, it would also help to specify the height of the container element to make sure Gmaps knows to account for it.

<table>
<tr height=”80″>
<td>
<img src=”pic.jpg” height=”80″ />
</td>
</tr>
</table>

Hope that helps you solve this little problem.

asp.net formview problem updating data

Very strange behavior with formviews on asp.net.  For some reason, if I declare the SqlDataSource on the page source but then do the binding of the SqlDataSource to the formview in code behind, no error are shown but the data does NOT get updated on edit.

So instead of doing this in code behind

summary.DataSourceID = "summaryDS";
summary.DataBind();

I need to do this on the page

<asp :FormView ID="summary"
runat="server"
DataSourceID="summaryDS">

A previous problem I encountered with formview