Posts Tagged ‘php’

Clean URLs in PHP Yii Framework

Wednesday, November 18th, 2009

Here is a quick tip to save some trouble. The goal here is to get clean urls like http://localhost/site/test/5 or http://localhost/site/contact without having a query string variable and also not having the filename index.php show up.

My configuration:
EasyPHP (apache/php/mysql combo for windows)
Yii PHP framework

In the Yii main.php configuration file you need:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
),

Inside the ‘components’ array area.

In the primary directory where the index.php file is you need a .htaccess files with this in it:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

If you have problems, check your httpd.conf file for these items:
<directory c:\easyphp\www>
Inside that directory section, make sure the rules don’t disallow the removal of index.php or the other rewrite rules.

Make sure this line is un-commented:
LoadModule rewrite_module modules/mod_rewrite.so

I think that’s about it…

EasyPHP, Wordpress, and Permalinks

Friday, July 17th, 2009

I’m creating a website as a favor to a friend. To save effort, I’m just doing the development on my Windows computer. While doing that, I ran into a little issue with permalinks that seems to be unique to how EasyPHP is configured.

While I won’t go into much detail on the subject, I re-affirmed the fact that Wordpress is as close to as ideas as one can get when wanting to setup a basic website. I tried out probably 10 open source CMS systems and found them too complex (the admin back-ends) or too buggy to be used. Keep in mind that the website I am setting up requires only basic functionality (informational pages, a image gallery, good admin, stable code), which is what I am basing my opinion off of.

What brings me to my post today is that I used EasyPHP(a simple Apache, MySql installer and admin) to act as the local web server for testing.

I was having issues with getting permalinks working. There was one gotcha that doesn’t apply to other webserver installers.

What I did to make it work:
Edit the Apache httpd.conf file (right click on the tray icon, select Configuration and then Apache):

Uncomment this line by removing the # in front of it:

LoadModule rewrite_module modules/mod_rewrite.so

Search for <Directory /> and then make sure that “AllowOverride All” is “All” and not “none.”  Also make sure that “Allow from All” is not “Deny from All”

<Directory />
  Options FollowSymLinks
  AllowOverride All
  Order deny,allow
  Allow from all
</Directory>

For whatever reason that Deny from all is set, which took me a while to figure out and change. All of the related guides on the internet were using different installers, that don’t have the same issue.

Edit: I noticed that changing that makes some of the EasyPHP functionality inoperable… might be looking for a different setup.

PHP, IIS, and NetBeans

Tuesday, March 10th, 2009

It’s been while since I have used the language, so I thought it would be fun to try making a few new ideas with it.

I did a quick search to see what PHP IDEs were available.  I’ve used Eclipse quite a lot, but I’m not particularly fond of it, so I wanted to try something else.

I plan on giving NetBeans a chance to see how it fairs.
http://www.netbeans.org/features/php/

Seeing as I am currently using Vista Ultimate 64-bit, I decided to just use IIS. I had a few quips getting it working.

I had modified IIS beforehand when I was doing some old VbScript coding, so needless to say when I tried installing PHP it didn’t work out of the box.

In the IIS configuration program (use the start button search in vista on “InetMgr”):
- Install PHP as a ISAPI filter.
- In your selected application pool advances settings, make sure that “Managed Pipeline Mode” is set to “Classic” mode.
In the list of global settings:
- Add a default document “index.php”
- In ISAPI Filters, add a new filter that points to (most likely) “C:\Program Files (x86)\PHP\php5isapi.dll”
- In Handler Mappings, add a PHP entry “*.php” that also points to “C:\Program Files (x86)\PHP\php5isapi.dll”
- In that same screen look over to the right for “View Ordered List…” to make sure that the PHP entry is at the top so it gets priority over the static page handler.

What I also did was have my IIS Site point directly to the default NetBeans project directory. The issue I had there was file permissions. I changed the “Basic Settings…” option to connect as my personal login. Seeing as this is only for development, I don’t see any issues with that. I also changed my default binding to “127.0.0.1,” which should only allow access from the computer itself. Not that it matters as this computer is behind a router

Is object orientated scripting worth the effort?

Sunday, January 27th, 2008

I’m currently creating a movie review website in PHP an SQLite. I’m taking a very object orientated approach.

For example, all database access goes through an object. Adding a review is as simple as calling a function with the proper data.

Here is the function header:

addReview($assocArrayReviewData, $assocArrayReviewBlockData)

Each parameter is an associative array that corresponds to fields in the database. While I don’t want to get into too much detail, the second variable is actually an array of arrays, where each one holds a block of review information (eg: “What the box says”, “funny quotes”, “My thoughts”).

The best thing about is is that once I create the administration interface I can just call that one function with the correct parameters and bam, a new review.

The class also has a built-in search function (that could be used on the internal or external site).

My next class that I created for primarily for the administration area. It’s an html tag class object. You might me thinking, what’s the point of mimicking html tags? Well in my never ending quest to separate html from code, this object can be instantiated instead of writing html dispersed through the script code. Please forgive me on the naming. I’m not quite sure what to call the class yet. I first called a “form” class, then a “control” class, and then once I realized it could be used for anything… the “htmlTag” class. Well anyways, it does what I want it to do regardless of what it is called.

Here is a quick example of code that would call it:

$test = new HtmlTag('test', 'form');
$test->setAttribute('method', 'post');
$test->createSubControl('button1', 'input');
$test->subControl('button1')->setAttribute('type', 'button');
$test->subControl('button1')->setAttribute('value', 'Click Here!');
echo $test->toHtml();

Any idea what it does?

It creates this:


Pretty cool, eh? The whole class is a beefy ~220 lines. haha
Now I can create forms programmatically that can have an unlimited number of parent/children/sub-children to them. So a form can hold a select box, that holds option tags… etc.

Here is a bit of the class file:

class HtmlTag
{
    //strings:
    private $controlType; //stores the type of control (this should correspond to an actual html tag)
    private $innerHtml; //hold any text or whatever inside the control's start and end tags
    
    //associative arrays:
    private $attributes; //hold all of the attributes of the control (eg: onsubmit='' onclick='' style=''...)
    
    private $subControls; //holds sub controls (eg: form has controls inside it, select control has options inside it)

..................

 function &subControl($name)
 {
     return $this->subControls[$name];
 }

}
    

The subControl function is key to accessing children and sub-children of the main object. I wanted to keep the array subControls private, so that function is necessary.

Now that I have that class created I will start designing the administration interface, that now, is just a shell that accesses these two classes.





 

 
Stock Photo Website
Tech Learning Site

Popular Article Tags

Recent Article Comments

Archives