ReflectionException: Class SomeClass does not exist – Laravel 4

Note: This post was written while Laravel 4 was still in beta.

When you add a new class (controller) in Laravel 4 you will most probably get

ReflectionException: Class SomeClass does not exist

SomeClass is of course the name of your new class.

Why does this happen? The file/controller is there, the class is there – it works in Laravel 3 so why doesn’t it work in Laravel 4?

The reason for this is that because of the performance reasons Laravel 4 (beta) has a static list of all classes that need to be autoloaded. Since you added your new controller Laravel doesn’t know about it yet. Hopefully this will be automated in the future but right now what you need to do is open your command prompt and type this (on Windows):

 >composer dump-autoload

If you get 'composer' is not recognized as an internal or external command error or Could not open input file: composer then use this version (also go to your project directory where composer.phar is located):

 >php composer.phar dump-autoload

Composer will (re)generate autoload files and your new controller will work.

Always displays battery icon in windows 7 system tray

How to move an icon (in my case I wanted to move battery icon) from that “hidden” system tray space so it will always be visible in system tray?

Simple, just click on the up arrow to display that “hidden” system tray area, grab the icon (hold the left mouse button) you would like to move and just move it to  the always-visible system tray area.

system tray windows 7
Pic: System tray on windows 7

‘git’ is not recognized as an internal or external command

If you installed Git from windows.github.com you might get this error while running ‘git’ from windows command prompt(cmd):

‘git’ is not recognized as an internal or external command, operable program or batch file.

What you need to do is add Git path to Windows Environment Variables.

First, search for git.exe with windows search. You will find it in directory similar to this one:

C:\Users\user\AppData\Local\GitHub\PortableGit_76ds5d7f65adsf76as5f7as6f5asdf\bin

Add this to Windows Environment Variables :

  • right mouse-click “My Computer” and select “Properties”
  • if on Windows 7 then click on “Advanced system settings”,
  • open “Advanced” tab and click “Environment Variables”,
  • highlight/click on the “Path” variable under “System variables” and click “Edit”,
  • add your specific path to front of “Variable value” field or at the end, separated by a semicolon from the existing entry. Do not add a space between ; and last entry.Also, do not add ; after the last entry

Let say, just for example, that the Git.exe is in C:\Users\something\somefolder\bin folder. So when you edit your path variable it should look like this (thanks to my super Photoshop skills you can see that we are on Advanced tab, that we are editing Path variable and that I excel at making watermarks):

edit system variable git

Click Ok few times and try running Git again.

Warning: file_get_contents(): Unable to find the wrapper “https” – did you forget to enable it when you configured PHP?

I was installing Composer via CLI terminal for a new Laravel project and got this error:

Warning: file_get_contents(): Unable to find the wrapper “https” – did you forget to enable it when you configured PHP? in Command line code on line 1

The solution is easy: Open php.ini file (mine is located in xammp/php/php.ini ) and add (or uncomment) extension=php_openssl.dll in the list of Dynamic Extensions. Restart Apache and it should work.

Laravel Redirect redirects URL to index.php

One of the first things that I do when I start using a new framework (CodeIgniter, Laravel etc) is to remove the default index.php from the URL.

When you install Laravel and you want to remove index.php from the URL simply do this (If you are using Apache, make sure that mod_rewrite is enabled):

Create .htaccess file in your public directory and add this:

<IfModule mod_rewrite.c>
     RewriteEngine on

     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d

     RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Many developers do this and forget that there is another step. Everything works fine until you use Laravel’s Redirect class, for example:

return Redirect::to ('someurl'); 

This redirects you to index.php/someurl instead of someurl.

What you need to do is to open application/config/application.php file and you will see this on the line 42:

'index' => 'index.php'

Remove index.php so it becomes

'index' => ''

Save the file and now you have a cleaner, nicer URLs without the index.php.

How to embed styled tweets in your posts or pages

A lot of people don’t know that there is an easy way to embed tweets on your site with all the formatting and styling so they look just like on twitter.com. In addition, tweet will also contain avatar, reply,favorite,follow and other buttons so it is also functional.

For example look at this embedded tweet:

Looks nice, doesn’t it? Good news is that it is very simple but you need to go to twitter.com and follow these steps:

1. When you see a tweet in your stream that you would like to embed simply click on the date (when the tweet was posted) link – in our example above that link/date is “22 Mar 06”.

2. When the tweet is displayed click on the “Embed this Tweet” link and pop-up box will appear.

3. Copy the entire HTML code and paste it into the source (HTML) code of your page anywhere you want (inside body tag).

This is how the code for above tweet looks like:

<blockquote class="twitter-tweet">
<p>just setting up my twttr</p>&mdash; Jack Dorsey (@jack) 
<a href="https://twitter.com/jack/status/20" data-datetime="2006-03-21T20:50:14+00:00">March 21, 2006</a>
</blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Keep an eye on this line :

<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

This JavaScript,which is fetched from twitter website, makes your tweet embed look all nice like in our example above. If you forget to copy it your embedded tweets will not be styled properly.

If you embed only one tweet per page then you can include this line after blockquote. If you embed several tweets then include this line only once, somewhere at the bottom of the page or inside meta tag.

How to Fix – WordPress: Briefly unavailable for scheduled maintenance. Check back in a minute

WordPress update stuck in maintenance mode

In some cases the message “Briefly unavailable for scheduled maintenance. Check back in a minute” doesn’t disappear after you update your WordPress, despite the update being successful. Even worse – you are locked out of admin because both admin and your site display this message.

How to fix the WordPress maintenance mode problem? The solution is simple. Use your FTP program to connect to your server and delete the .maintenance file from your server (it is in the WordPress root directory, same as .htaccess). In most cases this will fix it. If the update did not finish then loginto admin and try to reinstall WordPress updates.

Stylesheets / CSS not or partially loading, site partially loaded

Every now and then I encounter a problem where several sites that I visit fail to displays CSS. It looks something like this  (Gizmodo website):

css not loading, website partialy loaded gizmodo

The problem appears when something goes wrong while you are deleting browser cache,cookies etc. In my case it usually happens when I use CCleaner (free tool for cleaning your Windows PC) and I accidentally open Firefox (or other browser) while CCleaner is deleting the cache.  Websites start to look like above screenshot and refreshing the page doesn’t help.

The solution is to refresh the page with CTRL + F5, which forces browser to redownload the entire site from internet and not from local cache. This solves problem only for that site so what I do is close all browsers and run CCleaner again.

Missing XML tag This required tag is missing. Please add it and resubmit ror.xml

Why do I need sitemap?

Sitemaps are a very useful way to  allow a webmaster to inform search engines about URLs on a website that are available for crawling. If you are using WordPress or some other CMS you can simply install a plugin (or maybe XML sitemap generation is already inbuilt module) and it will automatically create a sitemap for you. But sometimes you want to create a sitemap by yourself. There are several free services that allow you to create sitemaps for free, like xml-sitemaps.com , rorweb.com and so on. After you create a sitemap you should upload it to your website and submit to to Google,Yahoo etc.

That was a little sitemap introduction and now to the problem I encountered.I am not going to go into discussion if ROR sitemaps are better than Google/XML sitemaps or even needed (I don’t really use it but some people might find it useful). I am just describing solution to a possible problem you might encounter when making a ROR sitemap.

Google Webmaster Tools and ror.xml error

I built a ROR sitemap using xml-sitemaps.com site,uploaded to my site  and added it in Google Webmaster Tools admin and Google showed me this error:

Missing XML tag
This required tag is missing. Please add it and resubmit.

Parent tag: channel
Tag: description

At first I thought that xml-sitemaps.com ROR generator is outdated so I used one at rorweb.com/rormap.htm but I got the same error.  After searching the net I found the solution is very simple:

Open the ror.xml file in your text editor and find this (the beginning of the document,it might look a little different)

<channel>
<title>ROR Sitemap for http://www.yoursite.com/</title>
<link>http://www.yoursite.com/</link>
<item>

and paste the description line between the title the link lines so it will look like this:

<channel>
<title>ROR Sitemap for http://www.yoursite.com/</title>
<description>ROR Sitemap for http://www.yoursite.com/</description>
<link>http://www.yoursite.com/</link>
<item>

Save the file,reupload to your server and resubmit to Google Webmaster Tools (refresh the page) and the ‘Missing XML tag This required tag is missing. Please add it and resubmit’ error should disappear.

Sublime Text 2 opens “instant file search” instead of printing left square bracket in Windows

This problem only appears on certain keyboards and languages where left and right square brackets are placed on letters F and G. Even if you have similar problem with different keyboard or key binding /letters you can still use this solution.

I was using Sublime Text 2, which is really fantastic editor, on Windows 7 and encountered a weird problem. When I pressed AltGr+F Sublime Editor 2 didnt print “[” (left square bracket) – it opened Instant File Search tool instead.

The reason for this is that Windows sees AltGr as Ctrl+Alt, and therefore AltGr+F will be understood as Ctrl+Alt+F, which is a default keymap for Instant File Search tool.

To fix this you need to override the default Ctrl+Alt+F shortcut so it will insert the desired character by inputting that shortcut in user key-bindings.

Do this:
1. Select “Preferences > Key Bindings – User” in Sublime Text 2 menu
2. Paste the following code there:

[
{ "keys": ["ctrl+alt+f"], "command": "insert", "args": {"characters": "["} }
]

If your Key Bindings – User file is not empty then just add the code without the square brackets (line 1 and 3) and dont forget to add comma at the end or at the begging of the line.