I was recently introduced to the Picora framework by the great guys and my new employers over at Applied Solutions Group. If you fit the following then this might be a good one to checkout.
- Don’t like the HUGE frameworks that get all the attention, talking about you CakePHP
- Really don’t care for being forced to use strict MVC and prefer to have the choice
- Really aren’t super experienced with frameworks and need to get started in a forgiving way
While I do care for and support strict MVC and not straying from it, other wise what is the point, I can see how some people don’t want to spend their development time worrying about what should and shouldn’t be done in a certain way. So to get started you may be asking yourself why I would need an article on how to setup a framework that is not as in depth as the large ones. Well the thing is that there isn’t much documentation to Picora. To me this isn’t a huge problem because as I have said before, if you learn one of these then you know them all. But setup can be frustrating when there is no README and you need to create a few files to get this thing up and running. So lets get started and remember that once we get these files made before you start playing make yourself a copy of the working framework so you can just be ready to get going each time you need it.
Step One – Download
First of all we need to get the core files so head on over to Picora and download the files. I will assume you know how to get a site installed on a server. So now we have our server pointing to and serving our Picora install. Open your install in your browser and you will more than likely see the following.
WOW that is impressive huh? Well the problem is that in addition to not including all the file you need to get started it also doesn’t include a stock .htaccess file, the “.” is important so don’t forget it. So lets start by identifying the problem, hey I ain’t doing all the work for you without teaching you something.
Step Two – Find our Errors
In the root of your Picora install create a file names .htaccess, in other words it should be at the same level as the controller folder, etc… Now in that file you want to type the following:
php_value display_errors on
Remember that little line right there because it will save you many hours of heartache. Anytime php doens’t work for you just add that into your .htaccess file, just make sure to comment it before launch for obvious reasons. So lets take another look at our browser. Refresh your page and you should have the following.
Step Three – Fix our Broken Download
WOW again, ok now we at least have something to work with. Looks like the index.php file is trying to require a file called config.php that….doens’t exist huh? I think this is kind of crappy for the download not to include a default one that can be modified to show the ropes some but either way easy enough to figure out what is going on. In true step by step fashion lets create config.php, the file it wants, and see what we get.
Well again we get errors and it wants the base url so lets add some stuff to the config.php and see what happens next. We are going to add some stuff that is required for this work and move a bit quicker now because fixing every error one at a time is going to take up 8 pages here and I know you don’t want to read it and I don’t want to type it.
define('BASE_URL','http://picora.local/'); require_once('classes/PicoraAutoLoader.php'); PicoraAutoLoader::addFolder($path.'/classes/'); PicoraAutoLoader::addFolder($path.'/controllers/'); PicoraAutoLoader::addFolder($path.'/models/'); $routes = array( '/' => array('Application','welcome') );
Ok so now we got a config.php file that does a few things. We are defining a base url which is used by the system for many things, for instance flash messages and redirects usually rely on the base url. Either whoo, the require we have here could also be done inside a different file such as your index.php but I choose to separate it because I am calling in a class that will be required for the next few statements and because this is the config, don’t clutter your index.php file with a bunch of crap, but if you do, do it everytime so you know where to find it. Next up is something that since you will probably want to play with it isn’t a bad thing. We load everything class we have. In a release version we would narrow this down to only the classes that we are using and even at that you could argue, with good reason, to only loading these classes as need as part of the top of a controller. Either way I will stay out of influencing you to properly use conventions.
Well we added this here so now we need to clean up our index.php file a bit so we can get the rest of this working. Again I will give you a full dump of my index.php so you can copy paste and then read more to understand what it does.
$path = dirname(__FILE__); require_once($path.'/config.php'); PicoraDispatcher::addRoute($routes); print PicoraDispatcher::dispatch($path,BASE_URL,(isset($_GET['__route__']) ? '/'.$_GET['__route__'] : '/'));
Almost all of these things were already in there so we basically just took a few of them out to clean up our file and make it easier to understand. First off we get our path for use in config, and other places I am sure. Next we require our config.php. The next one is new though, we are calling the PicoraDispatcher that we loaded in the config, by loading all those classes, so that we can add in our routes. In every framework routes are always a huge and powerful option that any developer will gladly take advantage of. Last of all is the same line that was already there just calling that dispatcher to get our right routes. Now we want to refresh our browser again and see what we get. I get the following but you may not, if you do not then use the PHP error that gets printed or the Picora error message, won’t be much help, or finally post a comment here and maybe I can help you.
Step Four – Play with your Picora
Well that heading sounds retarded and kind of sexual but it is true, the only way to learn any framework is to use it. When I started programming I had a teacher tell me one time to try to NOT remember everything. Remember the basics and the conceptual side of programming and everything will always be possible. Syntax can be learned in a couple hours IF you know the concepts. It makes sense if you think about it, in the computer world if you know Java you can learn C, if you know Java and C then you can obviously learn anything because you know the concepts. If you just repeatedly repeat syntax then you will never understand it.
I will probably write a tutorial, or rather tutorials, soon and we will maybe build a blog application or some other stupid intro project with Picora just to show you around and let you see how you can extend classes in PHP so you don’t have to repeat yourself. I am in no way an expert with this system, I have around 10 minutes working in it and it took me about an hour to figure out all the weirdness with setting it up so take advantage of that and as I said before, save your working copy and use it to start new projects.








2 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Hi,
nice article.
I have to make a small project an I have choosen picora for it.
I will get back with some tips and may be a short demo
regards
Hey wiz,
that would be great, i have gotten busy with a few other projects and not had the time to make any tutorials at all. It looks like a nice choice for a lightweight small framework, i was a fan of a lot of other frameworks and still am but I definitely see the draw to these really tiny frameworks, I like CI for some of the same reasons and it is also pretty small and open. If you post up some stuff make sure to let me know and I will link to it.